[tor-commits] [stem/master] Tidying up NetworkStatusDocument._parse() start

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


commit 84fe0b46adc684a663af8536da35648adfd841e2
Author: Damian Johnson <atagar at torproject.org>
Date:   Fri Sep 14 09:35:03 2012 -0700

    Tidying up NetworkStatusDocument._parse() start
    
    Much of the _parse() method's start was unnecessary. Shortening it to improve
    readability.
---
 stem/descriptor/networkstatus.py |   14 +++++---------
 1 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/stem/descriptor/networkstatus.py b/stem/descriptor/networkstatus.py
index 12396d0..2402460 100644
--- a/stem/descriptor/networkstatus.py
+++ b/stem/descriptor/networkstatus.py
@@ -88,6 +88,8 @@ FOOTER_STATUS_DOCUMENT_FIELDS = (
   ("directory-signature", True, True, True),
 )
 
+ALL_FIELDS = [attr[0] for attr in HEADER_STATUS_DOCUMENT_FIELDS + FOOTER_STATUS_DOCUMENT_FIELDS]
+
 DEFAULT_PARAMS = {
   "cbtdisabled": 0,
   "cbtnummodes": 3,
@@ -289,22 +291,16 @@ class NetworkStatusDocument(stem.descriptor.Descriptor):
     header_entries = stem.descriptor._get_descriptor_components(header, validate)[0]
     footer_entries = stem.descriptor._get_descriptor_components(footer, validate)[0]
     
-    all_entries = dict()
-    all_entries.update(header_entries)
-    all_entries.update(footer_entries)
-    
-    known_fields = [attr[0] for attr in HEADER_STATUS_DOCUMENT_FIELDS + FOOTER_STATUS_DOCUMENT_FIELDS]
-    content = header + '\n' + footer
-    
-    for keyword, values in all_entries.items():
+    for keyword, values in header_entries.items() + footer_entries.items():
       value, block_contents = values[0]
       line = "%s %s" % (keyword, value)
       
       # All known fields can only appear once except...
       # * 'directory-signature' in a consensus
       
-      if validate and len(values) > 1 and keyword in known_fields:
+      if validate and len(values) > 1 and keyword in ALL_FIELDS:
         if not (keyword == 'directory-signature' and is_consensus):
+          content = header + '\n' + footer
           raise ValueError("Network status documents can only have a single '%s' line, got %i:\n%s" % (keyword, len(values), content))
       
       if keyword == 'network-status-version':





More information about the tor-commits mailing list