commit 0a583e678ac9b359685e24e3299337d2f8ced99f Author: Damian Johnson atagar@torproject.org Date: Mon May 7 10:07:00 2018 -0700
Remove usage of directory aliases
We provide backward compatablitiy, but we ourselves should reference the new module. --- docs/_static/example/compare_flags.py | 15 ++++++++++----- docs/_static/example/votes_by_bandwidth_authorities.py | 7 ++++--- stem/descriptor/remote.py | 8 ++++---- test/integ/descriptor/remote.py | 9 +++++---- test/unit/descriptor/remote.py | 4 ---- test/unit/tutorial_examples.py | 12 ++++++------ 6 files changed, 29 insertions(+), 26 deletions(-)
diff --git a/docs/_static/example/compare_flags.py b/docs/_static/example/compare_flags.py index df317a89..1efb1d2c 100644 --- a/docs/_static/example/compare_flags.py +++ b/docs/_static/example/compare_flags.py @@ -1,16 +1,21 @@ -from collections import OrderedDict -from stem.descriptor import DocumentHandler, remote +import collections + +import stem.descriptor +import stem.descriptor.remote +import stem.directory
# Query all authority votes asynchronously.
-downloader = remote.DescriptorDownloader(document_handler=DocumentHandler.DOCUMENT) +downloader = stem.descriptor.remote.DescriptorDownloader( + document_handler = stem.descriptor.DocumentHandler.DOCUMENT, +)
# An ordered dictionary ensures queries are finished in the order they were # added.
-queries = OrderedDict() +queries = collections.OrderedDict()
-for name, authority in remote.get_authorities().items(): +for name, authority in stem.directory.Authority.from_cache().items(): if authority.v3ident is None: continue # authority doesn't vote if it lacks a v3ident
diff --git a/docs/_static/example/votes_by_bandwidth_authorities.py b/docs/_static/example/votes_by_bandwidth_authorities.py index f6816b74..9504bd94 100644 --- a/docs/_static/example/votes_by_bandwidth_authorities.py +++ b/docs/_static/example/votes_by_bandwidth_authorities.py @@ -1,11 +1,12 @@ -from stem.descriptor import remote +import stem.descriptor.remote +import stem.directory
# request votes from all the bandwidth authorities
queries = {} -downloader = remote.DescriptorDownloader() +downloader = stem.descriptor.remote.DescriptorDownloader()
-for authority in remote.get_authorities().values(): +for authority in stem.directory.Authority.from_cache().values(): if authority.is_bandwidth_authority: queries[authority.nickname] = downloader.query( '/tor/status-vote/current/authority', diff --git a/stem/descriptor/remote.py b/stem/descriptor/remote.py index bc23063a..a8be9280 100644 --- a/stem/descriptor/remote.py +++ b/stem/descriptor/remote.py @@ -496,7 +496,7 @@ class Query(object): """
if use_authority or not self.endpoints: - picked = random.choice([auth for auth in get_authorities().values() if auth.nickname not in ('tor26', 'Bifroest')]) + picked = random.choice([auth for auth in stem.directory.Authority.from_cache().values() if auth.nickname not in ('tor26', 'Bifroest')]) return stem.DirPort(picked.address, picked.dir_port) else: return random.choice(self.endpoints) @@ -547,7 +547,7 @@ class DescriptorDownloader(object): def __init__(self, use_mirrors = False, **default_args): self._default_args = default_args
- directories = list(get_authorities().values()) + directories = list(stem.directory.Authority.from_cache().values()) self._endpoints = [(directory.address, directory.dir_port) for directory in directories]
if use_mirrors: @@ -569,7 +569,7 @@ class DescriptorDownloader(object): :raises: **Exception** if unable to determine the directory mirrors """
- directories = get_authorities().values() + directories = stem.directory.Authority.from_cache().values() new_endpoints = set([(directory.address, directory.dir_port) for directory in directories])
consensus = list(self.get_consensus(document_handler = stem.descriptor.DocumentHandler.DOCUMENT).run())[0] @@ -735,7 +735,7 @@ class DescriptorDownloader(object): """ Provides the present vote for a given directory authority.
- :param stem.descriptor.remote.DirectoryAuthority authority: authority for which to retrieve a vote for + :param stem.directory.Authority authority: authority for which to retrieve a vote for :param query_args: additional arguments for the :class:`~stem.descriptor.remote.Query` constructor
diff --git a/test/integ/descriptor/remote.py b/test/integ/descriptor/remote.py index 0305d069..c4e4f699 100644 --- a/test/integ/descriptor/remote.py +++ b/test/integ/descriptor/remote.py @@ -11,6 +11,7 @@ import stem.descriptor.networkstatus import stem.descriptor.remote import stem.descriptor.router_status_entry import stem.descriptor.server_descriptor +import stem.directory import test.require
@@ -18,7 +19,7 @@ class TestDescriptorDownloader(unittest.TestCase): @test.require.only_run_once @test.require.online def test_downloading_via_orport(self): - moria1 = stem.descriptor.remote.get_authorities()['moria1'] + moria1 = stem.directory.Authority.from_cache()['moria1']
desc = list(stem.descriptor.remote.their_server_descriptor( endpoints = [stem.ORPort(moria1.address, moria1.or_port)], @@ -31,7 +32,7 @@ class TestDescriptorDownloader(unittest.TestCase): @test.require.only_run_once @test.require.online def test_downloading_via_dirport(self): - moria1 = stem.descriptor.remote.get_authorities()['moria1'] + moria1 = stem.directory.Authority.from_cache()['moria1']
desc = list(stem.descriptor.remote.their_server_descriptor( endpoints = [stem.DirPort(moria1.address, moria1.dir_port)], @@ -73,7 +74,7 @@ class TestDescriptorDownloader(unittest.TestCase): if auth.nickname == 'dannenberg-legacy': continue # skip due to https://trac.torproject.org/projects/tor/ticket/17906
- stem_auth = stem.descriptor.remote.get_authorities().get(auth.nickname) + stem_auth = stem.directory.Authority.from_cache().get(auth.nickname)
if not stem_auth: self.fail("%s isn't a recognized directory authority in stem" % auth.nickname) @@ -99,7 +100,7 @@ class TestDescriptorDownloader(unittest.TestCase):
queries = []
- for nickname, authority in stem.descriptor.remote.get_authorities().items(): + for nickname, authority in stem.directory.Authority.from_cache().items(): queries.append((stem.descriptor.remote.Query( '/tor/server/fp/9695DFC35FFEB861329B9F1AB04C46397020CE31', 'server-descriptor 1.0', diff --git a/test/unit/descriptor/remote.py b/test/unit/descriptor/remote.py index 478a7143..d654f61a 100644 --- a/test/unit/descriptor/remote.py +++ b/test/unit/descriptor/remote.py @@ -369,7 +369,3 @@ class TestDescriptorDownloader(unittest.TestCase): self.assertEqual(1, len(list(query))) self.assertEqual(1, len(list(query))) self.assertEqual(1, len(list(query))) - - def test_using_authorities_in_hash(self): - # ensure our DirectoryAuthority instances can be used in hashes - {stem.descriptor.remote.get_authorities()['moria1']: 'hello'} diff --git a/test/unit/tutorial_examples.py b/test/unit/tutorial_examples.py index d94da5bf..5ca5993e 100644 --- a/test/unit/tutorial_examples.py +++ b/test/unit/tutorial_examples.py @@ -234,8 +234,8 @@ class TestTutorialExamples(unittest.TestCase):
@patch('sys.stdout', new_callable = StringIO) @patch('stem.descriptor.remote.Query') - @patch('stem.descriptor.remote.get_authorities') - def test_compare_flags(self, get_authorities_mock, query_mock, stdout_mock): + @patch('stem.directory.Authority.from_cache') + def test_compare_flags(self, authorities_mock, query_mock, stdout_mock): if stem.prereq._is_python_26(): # example imports OrderedDict from collections which doesn't work under # python 2.6 @@ -243,7 +243,7 @@ class TestTutorialExamples(unittest.TestCase): self.skipTest("(example doesn't support python 2.6)") return
- get_authorities_mock().items.return_value = [('moria1', DIRECTORY_AUTHORITIES['moria1']), ('maatuska', DIRECTORY_AUTHORITIES['maatuska'])] + authorities_mock().items.return_value = [('moria1', DIRECTORY_AUTHORITIES['moria1']), ('maatuska', DIRECTORY_AUTHORITIES['maatuska'])]
fingerprint = [ ('92FCB6748A40E6088E22FBAB943AB2DD743EA818', 'kvy2dIpA5giOIvurlDqy3XQ+qBg='), @@ -281,9 +281,9 @@ class TestTutorialExamples(unittest.TestCase): self.assert_equal_unordered(COMPARE_FLAGS_OUTPUT, stdout_mock.getvalue())
@patch('sys.stdout', new_callable = StringIO) - @patch('stem.descriptor.remote.get_authorities') + @patch('stem.directory.Authority.from_cache') @patch('stem.descriptor.remote.DescriptorDownloader.query') - def test_votes_by_bandwidth_authorities(self, query_mock, get_authorities_mock, stdout_mock): + def test_votes_by_bandwidth_authorities(self, query_mock, authorities_mock, stdout_mock): directory_values = [ DIRECTORY_AUTHORITIES['gabelmoo'], DIRECTORY_AUTHORITIES['moria1'], @@ -291,7 +291,7 @@ class TestTutorialExamples(unittest.TestCase): ]
directory_values[0].address = '131.188.40.189' - get_authorities_mock().values.return_value = directory_values + authorities_mock().values.return_value = directory_values
entry_with_measurement = RouterStatusEntryV3.create({'w': 'Bandwidth=1 Measured=1'}) entry_without_measurement = RouterStatusEntryV3.create()
tor-commits@lists.torproject.org