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

[tor-commits] [stem/master] Returning unicode from stem.util.system.call()



commit 7d1e8a4ffc08ca3b5e7fb34d3b025ec3c8755497
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Jan 27 19:08:40 2013 -0800

    Returning unicode from stem.util.system.call()
    
    The call() method is the basic call for shelling out and, like tor's stdout
    earlier, its output was ASCII bytes. This is fine in python 2.x, but causes
    problems for python 3.x. Both are fine with this being unicode output so going
    with that.
    
    ======================================================================
    ERROR: test_get_cwd
    ----------------------------------------------------------------------
    Traceback:
      File "/home/atagar/Desktop/stem/test/data/python3/test/integ/util/system.py", line 334, in test_get_cwd
        self.assertEquals(None, stem.util.system.get_cwd(99999))
      File "/home/atagar/Desktop/stem/test/data/python3/stem/util/system.py", line 528, in get_cwd
        elif results[0].endswith("No such process"):
    TypeError: expected an object with the buffer interface
---
 stem/util/system.py      |    4 ++--
 test/unit/util/system.py |    2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/stem/util/system.py b/stem/util/system.py
index 4f9ba29..f61c3d8 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -209,7 +209,7 @@ def is_running(command):
       command_listing = call(secondary_resolver)
 
     if command_listing:
-      command_listing = map(str.strip, command_listing)
+      command_listing = map(unicode.strip, command_listing)
       return command in command_listing
 
   return None
@@ -678,7 +678,7 @@ def call(command, default = UNDEFINED):
       log.trace(trace_prefix + ", stderr:\n%s" % stderr)
 
     if stdout:
-      return stdout.splitlines()
+      return stdout.decode("utf-8", "replace").splitlines()
     else:
       return []
   except OSError, exc:
diff --git a/test/unit/util/system.py b/test/unit/util/system.py
index 5bdbc86..4a3473c 100644
--- a/test/unit/util/system.py
+++ b/test/unit/util/system.py
@@ -110,7 +110,7 @@ class TestSystem(unittest.TestCase):
     """
 
     # mock response with a linux and bsd resolver
-    running_commands = ["irssi", "moc", "tor", "ps", "  firefox  "]
+    running_commands = [u"irssi", u"moc", u"tor", u"ps", u"  firefox  "]
 
     for ps_cmd in (system.IS_RUNNING_PS_LINUX, system.IS_RUNNING_PS_BSD):
       mocking.mock(system.call, mock_call(ps_cmd, running_commands))



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