[tor-commits] [stem/master] Use file's seekable() method

atagar at torproject.org atagar at torproject.org
Sun Jan 5 21:39:28 UTC 2020


commit 8406d91ebf979503f84764aacd05d62d93cea470
Author: Damian Johnson <atagar at torproject.org>
Date:   Sat Jan 4 17:21:15 2020 -0800

    Use file's seekable() method
    
    Another small python 3.x simplification.
---
 stem/descriptor/__init__.py | 9 +--------
 stem/descriptor/export.py   | 4 ++--
 2 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py
index b7270ac2..fff08910 100644
--- a/stem/descriptor/__init__.py
+++ b/stem/descriptor/__init__.py
@@ -371,14 +371,7 @@ def parse_file(descriptor_file, descriptor_type = None, validate = False, docume
 
     return
 
-  # Not all files are seekable. If unseekable then advising the user.
-  #
-  # Python 3.x adds an io.seekable() method, but not an option with python 2.x
-  # so using an experimental call to tell() to determine this.
-
-  try:
-    descriptor_file.tell()
-  except IOError:
+  if not descriptor_file.seekable():
     raise IOError(UNSEEKABLE_MSG)
 
   # The tor descriptor specifications do not provide a reliable method for
diff --git a/stem/descriptor/export.py b/stem/descriptor/export.py
index 4b909c97..35835d7c 100644
--- a/stem/descriptor/export.py
+++ b/stem/descriptor/export.py
@@ -40,7 +40,7 @@ def export_csv(descriptors, included_fields = (), excluded_fields = (), header =
   :param list included_fields: attributes to include in the csv
   :param list excluded_fields: attributes to exclude from the csv
   :param bool header: if **True** then the first line will be a comma separated
-    list of the attribute names (**only supported in python 2.7 and higher**)
+    list of the attribute names
 
   :returns: **str** of the CSV for the descriptors, one per line
   :raises: **ValueError** if descriptors contain more than one descriptor type
@@ -62,7 +62,7 @@ def export_csv_file(output_file, descriptors, included_fields = (), excluded_fie
   :param list included_fields: attributes to include in the csv
   :param list excluded_fields: attributes to exclude from the csv
   :param bool header: if **True** then the first line will be a comma separated
-    list of the attribute names (**only supported in python 2.7 and higher**)
+    list of the attribute names
 
   :returns: **str** of the CSV for the descriptors, one per line
   :raises: **ValueError** if descriptors contain more than one descriptor type





More information about the tor-commits mailing list