[tor-commits] [stem/master] Move class methods out of `AsyncController` to reuse them

atagar at torproject.org atagar at torproject.org
Thu Jul 16 01:28:59 UTC 2020


commit ced9564eed196988160d445b94c349c9f530cdbe
Author: Illia Volochii <illia.volochii at gmail.com>
Date:   Thu Apr 23 20:33:07 2020 +0300

    Move class methods out of `AsyncController` to reuse them
---
 stem/control.py | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/stem/control.py b/stem/control.py
index 76849dcf..cc5c9bd7 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -997,14 +997,9 @@ class BaseController(_BaseControllerSocketMixin):
           self._event_notice.clear()
 
 
-class AsyncController(BaseController):
-  """
-  Connection with Tor's control socket. This is built on top of the
-  BaseController and provides a more user friendly API for library users.
-  """
-
-  @staticmethod
-  def from_port(address: str = '127.0.0.1', port: Union[int, str] = 'default') -> 'stem.control.Controller':
+class _ControllerClassMethodMixin:
+  @classmethod
+  def from_port(address: str = '127.0.0.1', port: Union[int, str] = 'default') -> 'stem.control._ControllerClassMethodMixin':
     """
     Constructs a :class:`~stem.socket.ControlPort` based Controller.
 
@@ -1035,10 +1030,10 @@ class AsyncController(BaseController):
     else:
       control_port = stem.socket.ControlPort(address, int(port))
 
-    return AsyncController(control_port)
+    return cls(control_port)
 
-  @staticmethod
-  def from_socket_file(path: str = '/var/run/tor/control') -> 'stem.control.Controller':
+  @classmethod
+  def from_socket_file(cls: Type, path: str = '/var/run/tor/control') -> 'stem.control.Controller':
     """
     Constructs a :class:`~stem.socket.ControlSocketFile` based Controller.
 
@@ -1050,7 +1045,14 @@ class AsyncController(BaseController):
     """
 
     control_socket = stem.socket.ControlSocketFile(path)
-    return AsyncController(control_socket)
+    return cls(control_socket)
+
+
+class AsyncController(BaseController):
+  """
+  Connection with Tor's control socket. This is built on top of the
+  BaseController and provides a more user friendly API for library users.
+  """
 
   def __init__(self, control_socket: stem.socket.ControlSocket, is_authenticated: bool = False) -> None:
     self._is_caching_enabled = True





More information about the tor-commits mailing list