commit 16d6f4a584edb08c71da80baeccdc0f255cd8655 Author: Damian Johnson atagar@torproject.org Date: Sun Jul 2 12:05:31 2017 -0700
Drop use of sys.maxint for descriptor creation
Python 3.x drops sys.maxint...
https://stackoverflow.com/questions/13795758/what-is-sys-maxint-in-python-3
As such descriptor creation broke our python3 compatibility...
====================================================================== ERROR: test_new_consensus_event ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/atagar/Desktop/stem/test/unit/response/events.py", line 1005, in test_new_consensus_event 's': 'Fast Named Running Stable Valid', File "/home/atagar/Desktop/stem/stem/descriptor/__init__.py", line 611, in create return cls(cls.content(attr, exclude, sign), validate = validate) File "/home/atagar/Desktop/stem/stem/descriptor/router_status_entry.py", line 625, in content ('r', '%s p1aag7VwarGxqctS7/fS0y5FU+s oQZFLYe9e4A7bOkWKR7TaNxb0JE %s %s 9001 0' % (_random_nickname(), _random_date(), _random_ipv4_address())), File "/home/atagar/Desktop/stem/stem/descriptor/__init__.py", line 1046, in _random_nickname return ('Unnamed%i' % random.randint(0, sys.maxint))[:20] AttributeError: 'module' object has no attribute 'maxint'
No big whoop. We were just using it for 'gimme a big random number'. Fixing this revealed that we also had an off-by-one error with the string truncation. --- stem/descriptor/__init__.py | 3 +-- test/unit/descriptor/server_descriptor.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py index bf039f8..806e3e3 100644 --- a/stem/descriptor/__init__.py +++ b/stem/descriptor/__init__.py @@ -47,7 +47,6 @@ import os import random import re import string -import sys import tarfile
import stem.prereq @@ -1043,7 +1042,7 @@ def _append_router_signature(content, private_key):
def _random_nickname(): - return ('Unnamed%i' % random.randint(0, sys.maxint))[:20] + return ('Unnamed%i' % random.randint(0, 100000000000000))[:19]
def _random_fingerprint(): diff --git a/test/unit/descriptor/server_descriptor.py b/test/unit/descriptor/server_descriptor.py index 4d36bd8..b31ad68 100644 --- a/test/unit/descriptor/server_descriptor.py +++ b/test/unit/descriptor/server_descriptor.py @@ -290,7 +290,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4= self.assertEqual(None, desc.version) self.assertEqual(None, desc.version_line)
- self.assertEqual([(u'71.35.133.197', 9001, False), (u'12ab:2e19:3bcf::02:9970', 9001, True)], desc.or_addresses) + self.assertEqual([('71.35.133.197', 9001, False), ('12ab:2e19:3bcf::02:9970', 9001, True)], desc.or_addresses) self.assertEqual(None, desc.identifier_type) self.assertEqual(None, desc.identifier) self.assertEqual('4F0069BF91C04581B7C3CA9272E2D3228D4EA571', desc.digest)