[tor-commits] [stem/master] Don't pass unsupplied optional args to wrapped file

atagar at torproject.org atagar at torproject.org
Wed Feb 27 15:49:04 UTC 2013


commit ec3d0c01c9ba4aa30541ceb19e499fbe732453cb
Author: Damian Johnson <atagar at torproject.org>
Date:   Wed Feb 27 07:35:00 2013 -0800

    Don't pass unsupplied optional args to wrapped file
    
    Karsten reports that the descriptor reader is failing for him with...
    
      ParsingFailure: readlines() takes exactly 1 argument (2 given)
    
    This is because to add python 3.x support we had to wrap the parse_file()'s
    file argument with a wrapper. In most cases this wrapper is a passthrough, but
    it converts the read() and readlines() output to unicode.
    
    I based the methods of the wrapper on a StringIO file object, but evidently
    other files (most likely the tarfile) deviate a bit. Addressing the readlines()
    instance and one other that might cause troubles.
---
 stem/descriptor/__init__.py |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py
index 25b180b..a734950 100644
--- a/stem/descriptor/__init__.py
+++ b/stem/descriptor/__init__.py
@@ -331,19 +331,25 @@ class _UnicodeReader(object):
   def readline(self):
     return stem.util.str_tools.to_unicode(self.wrapped_file.readline())
 
-  def readlines(self, sizehint = 0):
+  def readlines(self, sizehint = None):
     # being careful to do in-place conversion so we don't accidently double our
     # memory usage
 
-    results = self.wrapped_file.readlines(sizehint)
+    if sizehint is not None:
+      results = self.wrapped_file.readlines(sizehint)
+    else:
+      results = self.wrapped_file.readlines()
 
     for i in xrange(len(results)):
       results[i] = stem.util.str_tools.to_unicode(results[i])
 
     return results
 
-  def seek(self, pos, mode = 0):
-    return self.wrapped_file.seek(pos, mode)
+  def seek(self, pos, mode = None):
+    if mode is not None:
+      return self.wrapped_file.seek(pos, mode)
+    else:
+      return self.wrapped_file.seek(pos)
 
   def tell(self):
     return self.wrapped_file.tell()



More information about the tor-commits mailing list