[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Checking that to_bytes has unicode before converting
commit f4ee5ab36ee512f7cb904bb371f593f7e2f1f8a6
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Wed Jan 30 09:39:45 2013 -0800
Checking that to_bytes has unicode before converting
Adding a check to the to_bytes() helper so we don't attempt to convert ASCII
bytes to ASCII bytes (which doesn't work so well).
======================================================================
ERROR: test_old_descriptor
----------------------------------------------------------------------
Traceback:
File "/home/atagar/Desktop/stem/test/data/python3/test/integ/descriptor/server_descriptor.py", line 120, in test_old_descriptor
desc = stem.descriptor.server_descriptor.RelayDescriptor(descriptor_contents)
File "/home/atagar/Desktop/stem/test/data/python3/stem/descriptor/server_descriptor.py", line 642, in __init__
self._validate_content()
File "/home/atagar/Desktop/stem/test/data/python3/stem/descriptor/server_descriptor.py", line 687, in _validate_content
key_der_as_hash = hashlib.sha1(stem.util.str_tools.to_bytes(key_as_bytes)).hexdigest()
File "/home/atagar/Desktop/stem/test/data/python3/stem/util/str_tools.py", line 73, in to_bytes
return _to_bytes(msg)
File "/home/atagar/Desktop/stem/test/data/python3/stem/util/str_tools.py", line 54, in _to_bytes
return codecs.latin_1_encode(msg)[0]
TypeError: Can't convert 'bytes' object to str implicitly
---
stem/util/str_tools.py | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/stem/util/str_tools.py b/stem/util/str_tools.py
index 022874e..2956419 100644
--- a/stem/util/str_tools.py
+++ b/stem/util/str_tools.py
@@ -51,7 +51,10 @@ if stem.prereq.is_python_3():
import codecs
def _to_bytes(msg):
- return codecs.latin_1_encode(msg)[0]
+ if isinstance(msg, str):
+ return codecs.latin_1_encode(msg)[0]
+ else:
+ return msg
else:
def _to_bytes(msg):
return msg
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits