[tor-commits] [stem/master] Remove extra checks for circuit id and stream id validity

atagar at torproject.org atagar at torproject.org
Sat Dec 15 20:25:42 UTC 2012


commit e30f2df26221004fc2c535e5ef5e0b2c8518e3b2
Author: Sean Robinson <seankrobinson at gmail.com>
Date:   Fri Dec 14 17:12:27 2012 -0700

    Remove extra checks for circuit id and stream id validity
    
    CircuitID and StreamID may not be None, so raise ProtocolError if either
    ID is None.  Inside is_valid_circuit_id() and is_valid_stream_id(),
    isinstance(entry, str) already returns False if None is checked.  Add None
    as invalid IDs in tests.
    
    NOTE: Do not try this with is_valid_fingerprint() and is_valid_nickname(),
    as the fingerprint or nickname may be None in certain cases.
    
    Signed-off-by: Sean Robinson <seankrobinson at gmail.com>
---
 stem/response/events.py     |    6 +++---
 test/unit/util/tor_tools.py |    2 ++
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/stem/response/events.py b/stem/response/events.py
index 8c9cc2b..4e0aef8 100644
--- a/stem/response/events.py
+++ b/stem/response/events.py
@@ -326,7 +326,7 @@ class CircuitEvent(Event):
       except ValueError, exc:
         raise stem.ProtocolError("Unable to parse create date (%s): %s" % (exc, self))
     
-    if self.id is not None and not tor_tools.is_valid_circuit_id(self.id):
+    if not tor_tools.is_valid_circuit_id(self.id):
       raise stem.ProtocolError("Circuit IDs must be one to sixteen alphanumeric characters, got '%s': %s" % (self.id, self))
     
     self._log_if_unrecognized('status', stem.CircStatus)
@@ -381,7 +381,7 @@ class CircMinorEvent(Event):
       except ValueError, exc:
         raise stem.ProtocolError("Unable to parse create date (%s): %s" % (exc, self))
     
-    if self.id is not None and not tor_tools.is_valid_circuit_id(self.id):
+    if not tor_tools.is_valid_circuit_id(self.id):
       raise stem.ProtocolError("Circuit IDs must be one to sixteen alphanumeric characters, got '%s': %s" % (self.id, self))
     
     self._log_if_unrecognized('event', stem.CircEvent)
@@ -811,7 +811,7 @@ class StreamBwEvent(Event):
   _VERSION_ADDED = stem.version.Version('0.1.2.8-beta')
   
   def _parse(self):
-    if self.id is not None and not tor_tools.is_valid_stream_id(self.id):
+    if not tor_tools.is_valid_stream_id(self.id):
       raise stem.ProtocolError("Stream IDs must be one to sixteen alphanumeric characters, got '%s': %s" % (self.id, self))
     elif not self.written:
       raise stem.ProtocolError("STREAM_BW event is missing its written value")
diff --git a/test/unit/util/tor_tools.py b/test/unit/util/tor_tools.py
index 32581e9..0c0e6e2 100644
--- a/test/unit/util/tor_tools.py
+++ b/test/unit/util/tor_tools.py
@@ -43,6 +43,7 @@ class TestTorTools(unittest.TestCase):
     )
     
     invalid_nicknames = (
+      None,
       "",
       "toolongggggggggggggg",
       "bad_character",
@@ -66,6 +67,7 @@ class TestTorTools(unittest.TestCase):
     )
     
     invalid_circuit_ids = (
+      None,
       "",
       0,
       2,



More information about the tor-commits mailing list