[tor-commits] [stem/master] Fixing python3 issue related to unicode exit policies

atagar at torproject.org atagar at torproject.org
Mon Oct 14 00:42:15 UTC 2013


commit d09bd8b365819f4ea0d0a7d6b782b1021dba91c1
Author: Damian Johnson <atagar at torproject.org>
Date:   Sat Oct 12 16:37:02 2013 -0700

    Fixing python3 issue related to unicode exit policies
    
    Our recent exit policy caching caused a regression under python3...
    
    Traceback (most recent call last):
      File "./test/data/python3/run_tests.py", line 25, in <module>
        import test.runner
      File "/home/atagar/Desktop/stem/test/data/python3/test/runner.py", line 51, in <module>
        import stem.connection
      File "/home/atagar/Desktop/stem/test/data/python3/stem/connection.py", line 109, in <module>
        import stem.control
      File "/home/atagar/Desktop/stem/test/data/python3/stem/control.py", line 145, in <module>
        import stem.descriptor.microdescriptor
      File "/home/atagar/Desktop/stem/test/data/python3/stem/descriptor/__init__.py", line 546, in <module>
        import stem.descriptor.server_descriptor
      File "/home/atagar/Desktop/stem/test/data/python3/stem/descriptor/server_descriptor.py", line 91, in <module>
        REJECT_ALL_POLICY = stem.exit_policy.ExitPolicy("reject *:*")
      File "/home/atagar/Desktop/stem/test/data/python3/stem/exit_policy.py", line 164, in __init__
        self._input_rules = zlib.compress(','.join(rules))
    TypeError: 'str' does not support the buffer interface
---
 stem/exit_policy.py |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/stem/exit_policy.py b/stem/exit_policy.py
index cc91124..ee13308 100644
--- a/stem/exit_policy.py
+++ b/stem/exit_policy.py
@@ -61,6 +61,7 @@ import zlib
 import stem.prereq
 import stem.util.connection
 import stem.util.enum
+import stem.util.str_tools
 
 try:
   # added in python 3.2
@@ -161,7 +162,8 @@ class ExitPolicy(object):
         is_all_str = False
 
     if rules and is_all_str:
-      self._input_rules = zlib.compress(','.join(rules))
+      byte_rules = [stem.util.str_tools._to_bytes(r) for r in rules]
+      self._input_rules = zlib.compress(b','.join(byte_rules))
     else:
       self._input_rules = rules
 





More information about the tor-commits mailing list