[tor-commits] [stem/master] Fix DescriptorParser.remaining

atagar at torproject.org atagar at torproject.org
Sat Oct 13 18:35:44 UTC 2012


commit cc0c897908bb0d1bd97672675badb1286d71bfbc
Author: Ravi Chandra Padmala <neenaoffline at gmail.com>
Date:   Tue Aug 7 11:58:33 2012 +0530

    Fix DescriptorParser.remaining
---
 stem/descriptor/__init__.py                 |    1 +
 stem/descriptor/networkstatus_descriptor.py |   17 +++++++++--------
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py
index 0c883c2..5afe214 100644
--- a/stem/descriptor/__init__.py
+++ b/stem/descriptor/__init__.py
@@ -418,6 +418,7 @@ class DescriptorParser:
     if self.line:
       lines, self.lines = self.lines, []
       lines.insert(0, self.line)
+      self.line = None
       return lines
     else:
       return []
diff --git a/stem/descriptor/networkstatus_descriptor.py b/stem/descriptor/networkstatus_descriptor.py
index 036c47e..5c7d58e 100644
--- a/stem/descriptor/networkstatus_descriptor.py
+++ b/stem/descriptor/networkstatus_descriptor.py
@@ -259,10 +259,11 @@ class DirectoryAuthority(stem.descriptor.Descriptor):
     self.contact = parser.read_keyword_line("contact")
     if vote:
       self.legacy_dir_key = parser.read_keyword_line("legacy-dir-key", True)
-      self.key_certificate = KeyCertificate(parser.remaining(), validate)
+      self.key_certificate = KeyCertificate("\n".join(parser.remaining()), validate)
     else:
       self.vote_digest = parser.read_keyword_line("vote-digest", True)
-    if parser.remaining() and validate:
+    rmng = parser.remaining()
+    if rmng and validate:
       raise ValueError("Unrecognized trailing data in directory authority information")
 
 class KeyCertificate(stem.descriptor.Descriptor):
@@ -349,9 +350,9 @@ class KeyCertificate(stem.descriptor.Descriptor):
         # ignore unrecognized lines if we aren't validating
         self._unrecognized_lines.append(parser.read_line())
     
-    if parser.remaining():
-      if validate: raise ValueError("Unrecognized trailing data in key certificate")
-      else: self._unrecognized_lines.append(parser.read_line())
+    self._unrecognized_lines = parser.remaining()
+    if self._unrecognized_lines and validate:
+      raise ValueError("Unrecognized trailing data in key certificate")
   
   def get_unrecognized_lines(self):
     """
@@ -395,9 +396,9 @@ class DirectorySignature(stem.descriptor.Descriptor):
       self.method, self.identity, self.key_digest = signature_line
     
     self.signature = parser.read_block("SIGNATURE")
-    if parser.remaining():
-      if validate: raise ValueError("Unrecognized trailing data in directory signature")
-      else: self._unrecognized_lines.append(parser.read_line())
+    self._unrecognized_lines = parser.remaining()
+    if self._unrecognized_lines and validate:
+      raise ValueError("Unrecognized trailing data in directory signature")
 
 class RouterDescriptor(stem.descriptor.Descriptor):
   """





More information about the tor-commits mailing list