[tor-commits] [stem/master] Renaming controller and socket keyword arguments

atagar at torproject.org atagar at torproject.org
Wed Feb 27 15:49:04 UTC 2013


commit 3872befa5c62a91eb83d0d1376741b51a91acdb6
Author: Damian Johnson <atagar at torproject.org>
Date:   Sat Feb 23 16:07:19 2013 -0800

    Renaming controller and socket keyword arguments
    
    Less is more. I'm not sure why I called these keyword arguments 'control_addr',
    'control_port', and 'socket_path' but these will be highly used constructors.
    We should aim to have them be as user friendly a possible, and that means less
    verbose.
---
 stem/connection.py                      |   16 ++++++++--------
 stem/control.py                         |   24 ++++++++++++------------
 stem/socket.py                          |   14 +++++++-------
 test/integ/connection/authentication.py |    2 +-
 test/integ/connection/connect.py        |    4 ++--
 test/integ/control/controller.py        |    2 +-
 test/integ/process.py                   |    4 ++--
 test/integ/response/protocolinfo.py     |    2 +-
 test/prompt.py                          |    2 +-
 test/runner.py                          |    2 +-
 10 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/stem/connection.py b/stem/connection.py
index 688a8a1..952c17f 100644
--- a/stem/connection.py
+++ b/stem/connection.py
@@ -22,7 +22,7 @@ fine-grained control over the authentication process. For instance...
   import stem.socket
 
   try:
-    control_socket = stem.socket.ControlPort(control_port = 9051)
+    control_socket = stem.socket.ControlPort(port = 9051)
   except stem.SocketError, exc:
     print "Unable to connect to port 9051 (%s)" % exc
     sys.exit(1)
@@ -125,15 +125,15 @@ CLIENT_HASH_CONSTANT = "Tor safe cookie authentication controller-to-server hash
 SERVER_HASH_CONSTANT = "Tor safe cookie authentication server-to-controller hash"
 
 
-def connect_port(control_addr = "127.0.0.1", control_port = 9051, password = None, chroot_path = None, controller = stem.control.Controller):
+def connect_port(address = "127.0.0.1", port = 9051, password = None, chroot_path = None, controller = stem.control.Controller):
   """
   Convenience function for quickly getting a control connection. This is very
   handy for debugging or CLI setup, handling setup and prompting for a password
   if necessary (and none is provided). If any issues arise this prints a
   description of the problem and returns **None**.
 
-  :param str control_addr: ip address of the controller
-  :param int control_port: port number of the controller
+  :param str address: ip address of the controller
+  :param int port: port number of the controller
   :param str password: passphrase to authenticate to the socket
   :param str chroot_path: path prefix if in a chroot environment
   :param Class controller: :class:`~stem.control.BaseController` subclass to be
@@ -143,7 +143,7 @@ def connect_port(control_addr = "127.0.0.1", control_port = 9051, password = Non
   """
 
   try:
-    control_port = stem.socket.ControlPort(control_addr, control_port)
+    control_port = stem.socket.ControlPort(address, port)
   except stem.SocketError, exc:
     print exc
     return None
@@ -151,12 +151,12 @@ def connect_port(control_addr = "127.0.0.1", control_port = 9051, password = Non
   return _connect(control_port, password, chroot_path, controller)
 
 
-def connect_socket_file(socket_path = "/var/run/tor/control", password = None, chroot_path = None, controller = stem.control.Controller):
+def connect_socket_file(path = "/var/run/tor/control", password = None, chroot_path = None, controller = stem.control.Controller):
   """
   Convenience function for quickly getting a control connection. For more
   information see the :func:`~stem.connection.connect_port` function.
 
-  :param str socket_path: path where the control socket is located
+  :param str path: path where the control socket is located
   :param str password: passphrase to authenticate to the socket
   :param str chroot_path: path prefix if in a chroot environment
   :param Class controller: :class:`~stem.control.BaseController` subclass to be
@@ -166,7 +166,7 @@ def connect_socket_file(socket_path = "/var/run/tor/control", password = None, c
   """
 
   try:
-    control_socket = stem.socket.ControlSocketFile(socket_path)
+    control_socket = stem.socket.ControlSocketFile(path)
   except stem.SocketError, exc:
     print exc
     return None
diff --git a/stem/control.py b/stem/control.py
index 347dec0..6b9a7ca 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -618,38 +618,38 @@ class Controller(BaseController):
   BaseController and provides a more user friendly API for library users.
   """
 
-  def from_port(control_addr = "127.0.0.1", control_port = 9051):
+  def from_port(address = "127.0.0.1", port = 9051):
     """
     Constructs a :class:`~stem.socket.ControlPort` based Controller.
 
-    :param str control_addr: ip address of the controller
-    :param int control_port: port number of the controller
+    :param str address: ip address of the controller
+    :param int port: port number of the controller
 
     :returns: :class:`~stem.control.Controller` attached to the given port
 
     :raises: :class:`stem.SocketError` if we're unable to establish a connection
     """
 
-    if not stem.util.connection.is_valid_ip_address(control_addr):
-      raise ValueError("Invalid IP address: %s" % control_addr)
-    elif not stem.util.connection.is_valid_port(control_port):
-      raise ValueError("Invalid port: %s" % control_port)
+    if not stem.util.connection.is_valid_ip_address(address):
+      raise ValueError("Invalid IP address: %s" % address)
+    elif not stem.util.connection.is_valid_port(port):
+      raise ValueError("Invalid port: %s" % port)
 
-    control_port = stem.socket.ControlPort(control_addr, control_port)
+    control_port = stem.socket.ControlPort(address, port)
     return Controller(control_port)
 
-  def from_socket_file(socket_path = "/var/run/tor/control"):
+  def from_socket_file(path = "/var/run/tor/control"):
     """
     Constructs a :class:`~stem.socket.ControlSocketFile` based Controller.
 
-    :param str socket_path: path where the control socket is located
+    :param str path: path where the control socket is located
 
     :returns: :class:`~stem.control.Controller` attached to the given socket file
 
     :raises: :class:`stem.SocketError` if we're unable to establish a connection
     """
 
-    control_socket = stem.socket.ControlSocketFile(socket_path)
+    control_socket = stem.socket.ControlSocketFile(path)
     return Controller(control_socket)
 
   from_port = staticmethod(from_port)
@@ -1417,7 +1417,7 @@ class Controller(BaseController):
       def print_bw(event):
         print "sent: %i, received: %i" % (event.written, event.read)
 
-      with Controller.from_port(control_port = 9051) as controller:
+      with Controller.from_port(port = 9051) as controller:
         controller.authenticate()
         controller.add_event_listener(print_bw, EventType.BW)
         time.sleep(5)
diff --git a/stem/socket.py b/stem/socket.py
index 039a2cd..3b9498c 100644
--- a/stem/socket.py
+++ b/stem/socket.py
@@ -296,12 +296,12 @@ class ControlPort(ControlSocket):
   option.
   """
 
-  def __init__(self, control_addr = "127.0.0.1", control_port = 9051, connect = True):
+  def __init__(self, address = "127.0.0.1", port = 9051, connect = True):
     """
     ControlPort constructor.
 
-    :param str control_addr: ip address of the controller
-    :param int control_port: port number of the controller
+    :param str address: ip address of the controller
+    :param int port: port number of the controller
     :param bool connect: connects to the socket if True, leaves it unconnected otherwise
 
     :raises: :class:`stem.SocketError` if connect is **True** and we're
@@ -309,8 +309,8 @@ class ControlPort(ControlSocket):
     """
 
     super(ControlPort, self).__init__()
-    self._control_addr = control_addr
-    self._control_port = control_port
+    self._control_addr = address
+    self._control_port = port
 
     if connect:
       self.connect()
@@ -351,7 +351,7 @@ class ControlSocketFile(ControlSocket):
   option.
   """
 
-  def __init__(self, socket_path = "/var/run/tor/control", connect = True):
+  def __init__(self, path = "/var/run/tor/control", connect = True):
     """
     ControlSocketFile constructor.
 
@@ -363,7 +363,7 @@ class ControlSocketFile(ControlSocket):
     """
 
     super(ControlSocketFile, self).__init__()
-    self._socket_path = socket_path
+    self._socket_path = path
 
     if connect:
       self.connect()
diff --git a/test/integ/connection/authentication.py b/test/integ/connection/authentication.py
index d8c0a8a..36b8af6 100644
--- a/test/integ/connection/authentication.py
+++ b/test/integ/connection/authentication.py
@@ -145,7 +145,7 @@ class TestAuthenticate(unittest.TestCase):
     tor_options = runner.get_options()
 
     try:
-      control_socket = stem.socket.ControlPort(control_port = test.runner.CONTROL_PORT)
+      control_socket = stem.socket.ControlPort(port = test.runner.CONTROL_PORT)
     except stem.SocketError:
       # assert that we didn't have a socket to connect to
       self.assertFalse(test.runner.Torrc.PORT in tor_options)
diff --git a/test/integ/connection/connect.py b/test/integ/connection/connect.py
index 9ffc215..994b777 100644
--- a/test/integ/connection/connect.py
+++ b/test/integ/connection/connect.py
@@ -30,7 +30,7 @@ class TestConnect(unittest.TestCase):
     runner = test.runner.get_runner()
 
     control_socket = stem.connection.connect_port(
-      control_port = test.runner.CONTROL_PORT,
+      port = test.runner.CONTROL_PORT,
       password = test.runner.CONTROL_PASSWORD,
       chroot_path = runner.get_chroot(),
       controller = None)
@@ -52,7 +52,7 @@ class TestConnect(unittest.TestCase):
     runner = test.runner.get_runner()
 
     control_socket = stem.connection.connect_socket_file(
-      socket_path = test.runner.CONTROL_SOCKET_PATH,
+      path = test.runner.CONTROL_SOCKET_PATH,
       password = test.runner.CONTROL_PASSWORD,
       chroot_path = runner.get_chroot(),
       controller = None)
diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py
index 3cabcd9..6d55b80 100644
--- a/test/integ/control/controller.py
+++ b/test/integ/control/controller.py
@@ -39,7 +39,7 @@ class TestController(unittest.TestCase):
       return
 
     if test.runner.Torrc.PORT in test.runner.get_runner().get_options():
-      with stem.control.Controller.from_port(control_port = test.runner.CONTROL_PORT) as controller:
+      with stem.control.Controller.from_port(port = test.runner.CONTROL_PORT) as controller:
         self.assertTrue(isinstance(controller, stem.control.Controller))
     else:
       self.assertRaises(stem.SocketError, stem.control.Controller.from_port, "127.0.0.1", test.runner.CONTROL_PORT)
diff --git a/test/integ/process.py b/test/integ/process.py
index a5af4c6..a65a24b 100644
--- a/test/integ/process.py
+++ b/test/integ/process.py
@@ -65,7 +65,7 @@ class TestProcess(unittest.TestCase):
 
     control_socket = None
     try:
-      control_socket = stem.socket.ControlPort(control_port = 2778)
+      control_socket = stem.socket.ControlPort(port = 2778)
       stem.connection.authenticate(control_socket, chroot_path = runner.get_chroot())
 
       # exercises the socket
@@ -173,7 +173,7 @@ class TestProcess(unittest.TestCase):
 
     # We're the controlling process. Just need to connect then disconnect.
 
-    controller = stem.control.Controller.from_port(control_port = 2778)
+    controller = stem.control.Controller.from_port(port = 2778)
     controller.authenticate()
     controller.close()
 
diff --git a/test/integ/response/protocolinfo.py b/test/integ/response/protocolinfo.py
index 6f3e79a..fa9e265 100644
--- a/test/integ/response/protocolinfo.py
+++ b/test/integ/response/protocolinfo.py
@@ -72,7 +72,7 @@ class TestProtocolInfo(unittest.TestCase):
         "lsof -a -p ")
 
       mocking.mock(stem.util.system.call, filter_system_call(cwd_by_port_lookup_prefixes))
-      control_socket = stem.socket.ControlPort(control_port = test.runner.CONTROL_PORT)
+      control_socket = stem.socket.ControlPort(port = test.runner.CONTROL_PORT)
     else:
       cwd_by_socket_lookup_prefixes = (
         stem.util.system.GET_PID_BY_FILE_LSOF % "",
diff --git a/test/prompt.py b/test/prompt.py
index c28c914..7b6fa61 100644
--- a/test/prompt.py
+++ b/test/prompt.py
@@ -97,6 +97,6 @@ def controller():
   if not is_running():
     start()
 
-  controller = stem.control.Controller.from_port(control_port = CONTROL_PORT)
+  controller = stem.control.Controller.from_port(port = CONTROL_PORT)
   controller.authenticate()
   return controller
diff --git a/test/runner.py b/test/runner.py
index e5faf1b..f94e4da 100644
--- a/test/runner.py
+++ b/test/runner.py
@@ -528,7 +528,7 @@ class Runner(object):
     """
 
     if Torrc.PORT in self._custom_opts:
-      control_socket = stem.socket.ControlPort(control_port = CONTROL_PORT)
+      control_socket = stem.socket.ControlPort(port = CONTROL_PORT)
     elif Torrc.SOCKET in self._custom_opts:
       control_socket = stem.socket.ControlSocketFile(CONTROL_SOCKET_PATH)
     else:





More information about the tor-commits mailing list