commit 9a0a5437e0ff38ae90cc0a2386c098fc36027e74 Author: Damian Johnson atagar@torproject.org Date: Sat Feb 8 13:45:03 2020 -0800
Drop support for legacy tuple endpoints --- stem/descriptor/remote.py | 17 +++++------------ test/unit/descriptor/remote.py | 12 ++++++------ 2 files changed, 11 insertions(+), 18 deletions(-)
diff --git a/stem/descriptor/remote.py b/stem/descriptor/remote.py index e059a504..d650c226 100644 --- a/stem/descriptor/remote.py +++ b/stem/descriptor/remote.py @@ -347,11 +347,6 @@ class Query(object): renamed to http.client.HTTPMessage.
.. versionchanged:: 1.7.0 - Endpoints are now expected to be :class:`~stem.DirPort` or - :class:`~stem.ORPort` instances. Usage of tuples for this - argument is deprecated and will be removed in the future. - - .. versionchanged:: 1.7.0 Avoid downloading from tor26. This directory authority throttles its DirPort to such an extent that requests either time out or take on the order of minutes. @@ -459,12 +454,10 @@ class Query(object):
if endpoints: for endpoint in endpoints: - if isinstance(endpoint, tuple) and len(endpoint) == 2: - self.endpoints.append(stem.DirPort(endpoint[0], endpoint[1])) # TODO: remove this in stem 2.0 - elif isinstance(endpoint, (stem.ORPort, stem.DirPort)): + if isinstance(endpoint, (stem.ORPort, stem.DirPort)): self.endpoints.append(endpoint) else: - raise ValueError("Endpoints must be an stem.ORPort, stem.DirPort, or two value tuple. '%s' is a %s." % (endpoint, type(endpoint).__name__)) + raise ValueError("Endpoints must be an stem.ORPort or stem.DirPort. '%s' is a %s." % (endpoint, type(endpoint).__name__))
self.resource = resource self.compression = new_compression @@ -669,13 +662,13 @@ class DescriptorDownloader(object): """
directories = [auth for auth in stem.directory.Authority.from_cache().values() if auth.nickname not in DIR_PORT_BLACKLIST] - new_endpoints = set([(directory.address, directory.dir_port) for directory in directories]) + new_endpoints = set([stem.DirPort(directory.address, directory.dir_port) for directory in directories])
consensus = list(self.get_consensus(document_handler = stem.descriptor.DocumentHandler.DOCUMENT).run())[0]
for desc in consensus.routers.values(): if stem.Flag.V2DIR in desc.flags and desc.dir_port: - new_endpoints.add((desc.address, desc.dir_port)) + new_endpoints.add(stem.DirPort(desc.address, desc.dir_port))
# we need our endpoints to be a list rather than set for random.choice()
@@ -858,7 +851,7 @@ class DescriptorDownloader(object): resource = '/tor/status-vote/current/authority'
if 'endpoint' not in query_args: - query_args['endpoints'] = [(authority.address, authority.dir_port)] + query_args['endpoints'] = [stem.DirPort(authority.address, authority.dir_port)]
return self.query(resource, **query_args)
diff --git a/test/unit/descriptor/remote.py b/test/unit/descriptor/remote.py index 7cdeab46..01e0c58e 100644 --- a/test/unit/descriptor/remote.py +++ b/test/unit/descriptor/remote.py @@ -301,7 +301,7 @@ class TestDescriptorDownloader(unittest.TestCase): query = stem.descriptor.remote.Query( TEST_RESOURCE, 'server-descriptor 1.0', - endpoints = [('128.31.0.39', 9131)], + endpoints = [stem.DirPort('128.31.0.39', 9131)], compression = Compression.PLAINTEXT, validate = True, ) @@ -326,7 +326,7 @@ class TestDescriptorDownloader(unittest.TestCase): query = stem.descriptor.remote.Query( TEST_RESOURCE, 'server-descriptor 1.0', - endpoints = [('128.31.0.39', 9131)], + endpoints = [stem.DirPort('128.31.0.39', 9131)], compression = Compression.PLAINTEXT, validate = True, ) @@ -353,7 +353,7 @@ class TestDescriptorDownloader(unittest.TestCase): query = stem.descriptor.remote.Query( TEST_RESOURCE, 'server-descriptor 1.0', - endpoints = [('128.31.0.39', 9131)], + endpoints = [stem.DirPort('128.31.0.39', 9131)], fall_back_to_authority = False, timeout = 0.1, validate = True, @@ -369,12 +369,12 @@ class TestDescriptorDownloader(unittest.TestCase): invalid_endpoints = { 'hello': "'h' is a str.", ('hello',): "'hello' is a str.", + (('hello',),): "'('hello',)' is a tuple.", (15,): "'15' is a int.", - (('12.34.56.78', 15, 'third arg'),): "'('12.34.56.78', 15, 'third arg')' is a tuple.", }
for endpoints, error_suffix in invalid_endpoints.items(): - expected_error = 'Endpoints must be an stem.ORPort, stem.DirPort, or two value tuple. ' + error_suffix + expected_error = 'Endpoints must be an stem.ORPort or stem.DirPort. ' + error_suffix self.assertRaisesWith(ValueError, expected_error, stem.descriptor.remote.Query, TEST_RESOURCE, 'server-descriptor 1.0', endpoints = endpoints)
@patch('urllib.request.urlopen', _dirport_mock(TEST_DESCRIPTOR)) @@ -382,7 +382,7 @@ class TestDescriptorDownloader(unittest.TestCase): query = stem.descriptor.remote.Query( TEST_RESOURCE, 'server-descriptor 1.0', - endpoints = [('128.31.0.39', 9131)], + endpoints = [stem.DirPort('128.31.0.39', 9131)], compression = Compression.PLAINTEXT, validate = True, )
tor-commits@lists.torproject.org