[tor-commits] [stem/master] NetworkStatus' meets_consensus_method() comparisons didn't account for None

atagar at torproject.org atagar at torproject.org
Sat Feb 2 18:20:49 UTC 2013


commit de9ac90b6db59f29a42453b829a66dff7b3b1767
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Jan 27 13:17:48 2013 -0800

    NetworkStatus' meets_consensus_method() comparisons didn't account for None
    
    Another spot where comparison with None fails with python 3...
    
    ======================================================================
    ERROR: test_with_directory_authorities
    ----------------------------------------------------------------------
    Traceback:
      File "/home/atagar/Desktop/stem/test/data/python3/test/unit/descriptor/networkstatus/document_v3.py", line 800, in test_with_directory_authorities
        document = NetworkStatusDocumentV3(content)
      File "/home/atagar/Desktop/stem/test/data/python3/stem/descriptor/networkstatus.py", line 509, in __init__
        self._footer = _DocumentFooter(document_file, validate, self._header)
      File "/home/atagar/Desktop/stem/test/data/python3/stem/descriptor/networkstatus.py", line 776, in __init__
        if header.meets_consensus_method(9):
      File "/home/atagar/Desktop/stem/test/data/python3/stem/descriptor/networkstatus.py", line 581, in meets_consensus_method
        return bool(self.consensus_method >= method or [x for x in self.consensus_methods if x >= method])
    TypeError: unorderable types: NoneType() >= int()
---
 stem/descriptor/networkstatus.py |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/stem/descriptor/networkstatus.py b/stem/descriptor/networkstatus.py
index f17d705..b4bc188 100644
--- a/stem/descriptor/networkstatus.py
+++ b/stem/descriptor/networkstatus.py
@@ -578,7 +578,12 @@ class _DocumentHeader(object):
       _check_for_misordered_fields(entries, HEADER_FIELDS)
 
   def meets_consensus_method(self, method):
-    return bool(self.consensus_method >= method or filter(lambda x: x >= method, self.consensus_methods))
+    if self.consensus_method is not None:
+      return self.consensus_method >= method
+    elif self.consensus_methods is not None:
+      return bool(filter(lambda x: x >= method, self.consensus_methods))
+    else:
+      return False  # malformed document
 
   def _parse(self, entries, validate):
     for keyword, values in entries.items():





More information about the tor-commits mailing list