[tor-commits] [stem/master] Correcting doctest failure for python3

atagar at torproject.org atagar at torproject.org
Sun Aug 17 22:38:43 UTC 2014


commit 4645eb41e604d84dc54e22faa1438c008ee9336e
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Aug 17 12:59:38 2014 -0700

    Correcting doctest failure for python3
    
    Our 2to3 python conversion understandably doesn't convert examples on our
    comments. As a result doctest choked when processing a python 2.x print
    statement...
    
    **********************************************************************
    File "/home/atagar/Desktop/stem/test/data/python3/stem/version.py", line 12, in version.py
    Failed example:
        print my_version
    Exception raised:
        Traceback (most recent call last):
          File "/usr/lib/python3.2/doctest.py", line 1288, in __run
            compileflags, 1), test.globs)
          File "<doctest version.py[2]>", line 1
            print my_version
                           ^
        SyntaxError: invalid syntax
    **********************************************************************
    1 items had failures:
       1 of   4 in version.py
    ***Test Failed*** 1 failures.
    **********************************************************************
---
 stem/control.py     |   14 +++++++-------
 stem/exit_policy.py |    6 +++---
 stem/version.py     |    2 +-
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/stem/control.py b/stem/control.py
index 4b70240..e2f133d 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -30,7 +30,7 @@ Controller you can then authenticate yourself using its
     try:
       controller = Controller.from_port()
     except stem.SocketError as exc:
-      print "Unable to connect to tor on port 9051: %s" % exc
+      print("Unable to connect to tor on port 9051: %s" % exc)
       sys.exit(1)
 
     try:
@@ -41,13 +41,13 @@ Controller you can then authenticate yourself using its
       try:
         controller.authenticate(password = pw)
       except stem.connection.PasswordAuthFailed:
-        print "Unable to authenticate, password is incorrect"
+        print("Unable to authenticate, password is incorrect")
         sys.exit(1)
     except stem.connection.AuthenticationFailure as exc:
-      print "Unable to authenticate: %s" % exc
+      print("Unable to authenticate: %s" % exc)
       sys.exit(1)
 
-    print "Tor is running version %s" % controller.get_version()
+    print("Tor is running version %s" % controller.get_version())
     controller.close()
 
 If you're fine with allowing your script to raise exceptions then this can be more nicely done as...
@@ -60,7 +60,7 @@ If you're fine with allowing your script to raise exceptions then this can be mo
     with Controller.from_port() as controller:
       controller.authenticate()
 
-      print "Tor is running version %s" % controller.get_version()
+      print("Tor is running version %s" % controller.get_version())
 
 **Module Overview:**
 
@@ -1903,7 +1903,7 @@ class Controller(BaseController):
       from stem.control import Controller, EventType
 
       def print_bw(event):
-        print 'sent: %i, received: %i' % (event.written, event.read)
+        print('sent: %i, received: %i' % (event.written, event.read))
 
       with Controller.from_port(port = 9051) as controller:
         controller.authenticate()
@@ -2256,7 +2256,7 @@ class Controller(BaseController):
       19
       >>> controller.extend_circuit('0')
       20
-      >>> print controller.get_info('circuit-status')
+      >>> print(controller.get_info('circuit-status'))
       20 EXTENDED $718BCEA286B531757ACAFF93AE04910EA73DE617=KsmoinOK,$649F2D0ACF418F7CFC6539AB2257EB2D5297BAFA=Eskimo BUILD_FLAGS=NEED_CAPACITY PURPOSE=GENERAL TIME_CREATED=2012-12-06T13:51:11.433755
       19 BUILT $718BCEA286B531757ACAFF93AE04910EA73DE617=KsmoinOK,$30BAB8EE7606CBD12F3CC269AE976E0153E7A58D=Pascal1,$2765D8A8C4BBA3F89585A9FFE0E8575615880BEB=Anthracite PURPOSE=GENERAL TIME_CREATED=2012-12-06T13:50:56.969938
 
diff --git a/stem/exit_policy.py b/stem/exit_policy.py
index e779562..4f622d7 100644
--- a/stem/exit_policy.py
+++ b/stem/exit_policy.py
@@ -9,15 +9,15 @@ exiting to a destination is permissible or not. For instance...
 
   >>> from stem.exit_policy import ExitPolicy, MicroExitPolicy
   >>> policy = ExitPolicy('accept *:80', 'accept *:443', 'reject *:*')
-  >>> print policy
+  >>> print(policy)
   accept *:80, accept *:443, reject *:*
-  >>> print policy.summary()
+  >>> print(policy.summary())
   accept 80, 443
   >>> policy.can_exit_to('75.119.206.243', 80)
   True
 
   >>> policy = MicroExitPolicy('accept 80,443')
-  >>> print policy
+  >>> print(policy)
   accept 80,443
   >>> policy.can_exit_to('75.119.206.243', 80)
   True
diff --git a/stem/version.py b/stem/version.py
index b5b1151..be971fb 100644
--- a/stem/version.py
+++ b/stem/version.py
@@ -9,7 +9,7 @@ easily parsed and compared, for instance...
 
   >>> from stem.version import get_system_tor_version, Requirement
   >>> my_version = get_system_tor_version()
-  >>> print my_version
+  >>> print(my_version)
   0.2.1.30
   >>> my_version >= Requirement.TORRC_CONTROL_SOCKET
   True





More information about the tor-commits mailing list