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

[tor-commits] [arm/master] Simplifying _getController() helper



commit 03b72fd7946f6246ea41ab9182642ce2ece863ab
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Sep 8 16:44:04 2013 -0700

    Simplifying _getController() helper
    
    I'm still not happy with the _getController() function, but at least now it's a
    tad better...
---
 arm/starter.py |   45 +++++++++++++++++++++------------------------
 1 file changed, 21 insertions(+), 24 deletions(-)

diff --git a/arm/starter.py b/arm/starter.py
index 67fc5a6..5c51812 100644
--- a/arm/starter.py
+++ b/arm/starter.py
@@ -220,34 +220,31 @@ def _getController(controlAddr="127.0.0.1", controlPort=9051, passphrase=None, i
   """
   Custom handler for establishing a stem connection (... needs an overhaul).
   """
-  
-  controller = None
+
+  chroot = arm.util.torTools.getPathPrefix()
+
   try:
-    chroot = arm.util.torTools.getPathPrefix()
     controller = Controller.from_port(controlAddr, controlPort)
-    
+  except stem.SocketError as exc:
+    print exc
+    return None
+
+  try:
+    controller.authenticate(password = passphrase, chroot_path = chroot)
+  except stem.connection.MissingPassword:
     try:
+      passphrase = getpass.getpass("Controller password: ")
       controller.authenticate(password = passphrase, chroot_path = chroot)
-    except stem.connection.MissingPassword:
-      try:
-        passphrase = getpass.getpass("Controller password: ")
-        controller.authenticate(password = passphrase, chroot_path = chroot)
-      except:
-        return None
-    
-    return controller
-  except Exception, exc:
-    if controller: controller.close()
-    
-    if passphrase and str(exc) == "Unable to authenticate: password incorrect":
-      # provide a warning that the provided password didn't work, then try
-      # again prompting for the user to enter it
-      print incorrectPasswordMsg
-      return _getController(controlAddr, controlPort)
-    else:
-      print exc
-    
-    return None
+    except:
+      # Huh? The old version just silently failed when it got an incorrect password?
+      return None
+  except stem.connection.IncorrectPassword:
+    # provide a warning that the provided password didn't work, then try
+    # again prompting for the user to enter it
+    print incorrectPasswordMsg
+    return _getController(controlAddr, controlPort)
+
+  return controller
 
 def _dumpConfig():
   """



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