[tor-commits] [stem/master] Include both method/function for get_server_descriptors

atagar at torproject.org atagar at torproject.org
Sat Aug 17 20:44:27 UTC 2019


commit 916f492b3bf4bba2903eeaa203fb073f85efaa96
Author: Damian Johnson <atagar at torproject.org>
Date:   Mon Aug 5 22:16:27 2019 -0700

    Include both method/function for get_server_descriptors
    
    Like stem.descriptor.remote planning to include both function and method
    counterparts for descriptor fetching.
---
 stem/descriptor/collector.py | 48 ++++++++++++++++++++++++++------------------
 1 file changed, 29 insertions(+), 19 deletions(-)

diff --git a/stem/descriptor/collector.py b/stem/descriptor/collector.py
index 04f45bad..e6e605f0 100644
--- a/stem/descriptor/collector.py
+++ b/stem/descriptor/collector.py
@@ -141,27 +141,13 @@ def get_instance():
 
 def get_server_descriptors(start = None, end = None, cache_to = None, timeout = None, retries = 3):
   """
-  Provides server descriptors for the given time range, sorted oldest to
-  newest.
-
-  :param datetime.datetime start: time range to begin with
-  :param datetime.datetime end: time range to end with
-  :param str cache_to: directory to cache archives into, if an archive is
-    available here it is not downloaded
-  :param int timeout: timeout for downloading each individual archive when the
-    connection becomes idle, no timeout applied if **None**
-  :param int retires: maximum attempts to impose on a per-archive basis
-
-  :returns: **iterator** of
-    :class:`~stem.descriptor.server_descriptor.ServerDescriptor` for the given
-    time range
-
-  :raises: :class:`~stem.DownloadFailed` if the download fails
+  Shorthand for
+  :func:`~stem.descriptor.collector.CollecTor.get_server_descriptors`
+  on our singleton instance.
   """
 
-  for f in get_instance().files('server-descriptor', start, end):
-    for desc in f.read(cache_to, timeout = timeout, retries = retries):
-      yield desc
+  for desc in get_instance().get_server_descriptors(start, end, cache_to, timeout, retries):
+    yield desc
 
 
 class File(object):
@@ -383,6 +369,30 @@ class CollecTor(object):
     self._cached_files = None
     self._cached_index_at = 0
 
+  def get_server_descriptors(self, start = None, end = None, cache_to = None, timeout = None, retries = 3):
+    """
+    Provides server descriptors published during the given time range, sorted
+    oldest to newest.
+
+    :param datetime.datetime start: time range to begin with
+    :param datetime.datetime end: time range to end with
+    :param str cache_to: directory to cache archives into, if an archive is
+      available here it is not downloaded
+    :param int timeout: timeout for downloading each individual archive when
+      the connection becomes idle, no timeout applied if **None**
+    :param int retires: maximum attempts to impose on a per-archive basis
+
+    :returns: **iterator** of
+      :class:`~stem.descriptor.server_descriptor.ServerDescriptor` for the
+      given time range
+
+    :raises: :class:`~stem.DownloadFailed` if the download fails
+    """
+
+    for f in self.files('server-descriptor', start, end):
+      for desc in f.read(cache_to, timeout = timeout, retries = retries):
+        yield desc
+
   def index(self, compression = 'best'):
     """
     Provides the archives available in CollecTor.





More information about the tor-commits mailing list