[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Couple fixes for prior controller changes



commit b8f4d3c75f0d4c085dcba02f47f4808c301e235a
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Tue Jun 12 08:49:01 2012 -0700

    Couple fixes for prior controller changes
    
    Two minor bugs...
    - our version parsing was broken for versions without a space in them
    - we were quoting the runner password constant rather than using it, breaking
      the RUN_PASSWORD target
    
    Also some minor whitespace tweaks and moving imports to the start of the file
    (we're only doing method level imports if doing otherwise would break things).
    We might change our import style later to resolve our circular imports, but
    that'll be a project-wide change.
---
 stem/control.py                  |   13 ++++++++-----
 test/integ/control/controller.py |   17 +++++++++--------
 2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/stem/control.py b/stem/control.py
index 9ceb630..f20451b 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -35,8 +35,10 @@ import time
 import Queue
 import threading
 
+import stem.connection
 import stem.response
 import stem.socket
+import stem.version
 import stem.util.log as log
 
 # state changes a control socket can have
@@ -492,9 +494,11 @@ class Controller(BaseController):
       * ValueError if unable to parse the version
     """
     
-    import stem.version
-    raw_str = self.get_info("version")
-    version_str = raw_str[:raw_str.find(' ')]
+    version_str = self.get_info("version")
+    
+    if " " in version_str:
+      version_str = version_str[:version_str.find(' ')]
+    
     return stem.version.Version(version_str)
   
   def authenticate(self, *args, **kwargs):
@@ -506,7 +510,6 @@ class Controller(BaseController):
     :raises: see :func:`stem.connection.authenticate`
     """
     
-    import stem.connection
     stem.connection.authenticate(self, *args, **kwargs)
   
   def protocolinfo(self):
@@ -520,5 +523,5 @@ class Controller(BaseController):
       * :class:`stem.socket.SocketError` if problems arise in establishing or using the socket
     """
     
-    import stem.connection
     return stem.connection.get_protocolinfo(self)
+
diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py
index 4ebce5b..55a86ec 100644
--- a/test/integ/control/controller.py
+++ b/test/integ/control/controller.py
@@ -74,7 +74,7 @@ class TestController(unittest.TestCase):
       
       self.assertEqual({}, controller.get_info([]))
       self.assertEqual({}, controller.get_info([], {}))
-      
+  
   def test_get_version(self):
     """
     Test that the convenient method get_version() works.
@@ -85,7 +85,7 @@ class TestController(unittest.TestCase):
       version = controller.get_version()
       self.assertTrue(isinstance(version, stem.version.Version))
       self.assertEqual(version, runner.get_tor_version())
-      
+  
   def test_authenticate(self):
     """
     Test that the convenient method authenticate() works.
@@ -93,9 +93,9 @@ class TestController(unittest.TestCase):
     
     runner = test.runner.get_runner()
     with runner.get_tor_controller(False) as controller:
-      controller.authenticate("test.runner.CONTROL_PASSWORD")
+      controller.authenticate(test.runner.CONTROL_PASSWORD)
       test.runner.exercise_controller(self, controller)
-      
+  
   def test_protocolinfo(self):
     """
     Test that the convenient method protocolinfo() works.
@@ -104,7 +104,6 @@ class TestController(unittest.TestCase):
     runner = test.runner.get_runner()
     
     with runner.get_tor_controller(False) as controller:
-      
       protocolinfo = controller.protocolinfo()
       self.assertTrue(isinstance(protocolinfo, stem.response.protocolinfo.ProtocolInfoResponse))
       
@@ -115,13 +114,15 @@ class TestController(unittest.TestCase):
       
       if test.runner.Torrc.COOKIE in tor_options:
         auth_methods.append(stem.response.protocolinfo.AuthMethod.COOKIE)
+        
         if tor_version.meets_requirements(stem.version.Requirement.AUTH_SAFECOOKIE):
           auth_methods.append(stem.response.protocolinfo.AuthMethod.SAFECOOKIE)
-          
+      
       if test.runner.Torrc.PASSWORD in tor_options:
         auth_methods.append(stem.response.protocolinfo.AuthMethod.PASSWORD)
-        
+      
       if not auth_methods:
         auth_methods.append(stem.response.protocolinfo.AuthMethod.NONE)
-        
+      
       self.assertEqual(tuple(auth_methods), protocolinfo.auth_methods)
+

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits