[tor-commits] [stem/master] Correcting python 3.x regression for descriptor parsing

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


commit 1e23a5d9632926a902bcf1d91ac81cbf9a4eedfd
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Aug 17 15:28:32 2014 -0700

    Correcting python 3.x regression for descriptor parsing
    
    Our recent b2ahex broke python 3.x because we expect fingerprints to be a str
    or unicode, not bytes...
    
    ======================================================================
    ERROR: test_ns_event
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/home/atagar/Desktop/stem/test/data/python3/test/unit/response/events.py", line 796, in test_ns_event
        's': 'Fast HSDir Named Stable V2Dir Valid',
      File "/home/atagar/Desktop/stem/test/data/python3/test/mocking.py", line 479, in get_router_status_entry_v3
        return stem.descriptor.router_status_entry.RouterStatusEntryV3(desc_content, validate = True)
      File "/home/atagar/Desktop/stem/test/data/python3/stem/descriptor/router_status_entry.py", line 344, in __init__
        super(RouterStatusEntryV3, self).__init__(content, validate, document)
      File "/home/atagar/Desktop/stem/test/data/python3/stem/descriptor/router_status_entry.py", line 161, in __init__
        self._parse(entries, validate)
      File "/home/atagar/Desktop/stem/test/data/python3/stem/descriptor/router_status_entry.py", line 351, in _parse
        _parse_r_line(self, value, validate, True)
      File "/home/atagar/Desktop/stem/test/data/python3/stem/descriptor/router_status_entry.py", line 514, in _parse_r_line
        desc.fingerprint = _base64_to_hex(r_comp[1], validate)
      File "/home/atagar/Desktop/stem/test/data/python3/stem/descriptor/router_status_entry.py", line 733, in _base64_to_hex
        raise ValueError("Decoded '%s' to be '%s', which isn't a valid fingerprint" % (identity, fingerprint))
    ValueError: Decoded 'dbBxYcJriTTrcxsuy4PUZcMRwCA===' to be 'b'75B07161C26B8934EB731B2ECB83D465C311C020'', which isn't a valid fingerprint
    
    ----------------------------------------------------------------------
---
 stem/descriptor/router_status_entry.py |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/stem/descriptor/router_status_entry.py b/stem/descriptor/router_status_entry.py
index 27ff203..75ad646 100644
--- a/stem/descriptor/router_status_entry.py
+++ b/stem/descriptor/router_status_entry.py
@@ -24,6 +24,7 @@ import binascii
 import datetime
 
 import stem.exit_policy
+import stem.prereq
 import stem.util.str_tools
 
 from stem.descriptor import (
@@ -725,6 +726,9 @@ def _base64_to_hex(identity, validate, check_if_fingerprint = True):
 
   fingerprint = binascii.b2a_hex(identity_decoded).upper()
 
+  if stem.prereq.is_python_3():
+    fingerprint = stem.util.str_tools._to_unicode(fingerprint)
+
   if check_if_fingerprint:
     if not stem.util.tor_tools.is_valid_fingerprint(fingerprint):
       if not validate:





More information about the tor-commits mailing list