commit ff2bd2948e70f5691a4d3e173687d7eca8c050c2
Author: Damian Johnson <atagar(a)torproject.org>
Date: Sat Dec 28 16:24:24 2019 -0800
Revise CollecTor example
The example we provided did not deduplicate relays, causing us to cite relays
repeatedly for each descriptor they published.
---
docs/_static/example/collector_reading.py | 9 ++++++++-
test/unit/tutorial.py | 2 +-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/docs/_static/example/collector_reading.py b/docs/_static/example/collector_reading.py
index 06cc913a..64af83dc 100644
--- a/docs/_static/example/collector_reading.py
+++ b/docs/_static/example/collector_reading.py
@@ -5,6 +5,13 @@ yesterday = datetime.datetime.utcnow() - datetime.timedelta(days = 1)
# provide yesterday's exits
+exits = {}
+
for desc in stem.descriptor.collector.get_server_descriptors(start = yesterday):
if desc.exit_policy.is_exiting_allowed():
- print(' %s (%s)' % (desc.nickname, desc.fingerprint))
+ exits[desc.fingerprint] = desc
+
+print('%i relays published an exiting policy today...\n' % len(exits))
+
+for fingerprint, desc in exits.items():
+ print(' %s (%s)' % (desc.nickname, fingerprint))
diff --git a/test/unit/tutorial.py b/test/unit/tutorial.py
index 9d70a5cf..e866f3ca 100644
--- a/test/unit/tutorial.py
+++ b/test/unit/tutorial.py
@@ -173,7 +173,7 @@ class TestTutorial(unittest.TestCase):
}, exit_policy = ExitPolicy('accept *:*'), validate = False)])
exec_documentation_example('collector_reading.py')
- self.assertEqual(' caerSidi (2C3C46625698B6D67DF32BC1918AD3EE1F9906B1)\n', stdout_mock.getvalue())
+ self.assertEqual('1 relays published an exiting policy today...\n\n caerSidi (2C3C46625698B6D67DF32BC1918AD3EE1F9906B1)\n', stdout_mock.getvalue())
@patch('sys.stdout', new_callable = StringIO)
@patch('stem.descriptor.remote.DescriptorDownloader')