[tor-commits] [stem/master] Invalid event types caused add_event_listener() error

atagar at torproject.org atagar at torproject.org
Tue May 6 01:21:13 UTC 2014


commit 0d357a9d6687afedbe9ad7509ced1797d1129cdf
Author: Damian Johnson <atagar at torproject.org>
Date:   Tue Apr 15 09:45:45 2014 -0700

    Invalid event types caused add_event_listener() error
    
    When presented with invalid or unrecognized event types our
    add_event_listener() is documented as raising a ProtocolError. However, it
    caused a KeyError instead...
    
      >>> SETEVENTS BW,DEBUG
      Traceback (most recent call last):
        File "./prompt", line 8, in <module>
          stem.interpretor.main()
        File "/home/atagar/Desktop/stem/stem/interpretor/__init__.py", line 67, in main
          print interpretor.run_command(user_input)
        File "/home/atagar/Desktop/stem/stem/interpretor/commands.py", line 449, in run_command
          self.controller.add_event_listener(self.register_event, *events)
        File "/home/atagar/Desktop/stem/stem/control.py", line 1920, in add_event_listener
          event_version = stem.response.events.EVENT_TYPE_TO_CLASS[event_type]._VERSION_ADDED
      KeyError: 'BW,DEBUG'
    
    Skipping the version check if we don't have a class for the event type. This
    both fixes invalid events, and also allows us to proper new event types that
    Stem doesn't recognize yet.
    
      >>> SETEVENTS BW,DEBUG
      SETEVENTS rejected BW,DEBUG
---
 stem/control.py |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/stem/control.py b/stem/control.py
index 6630762..3064e81 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -1917,10 +1917,10 @@ class Controller(BaseController):
     with self._event_listeners_lock:
       if self.is_authenticated():
         for event_type in events:
-          event_version = stem.response.events.EVENT_TYPE_TO_CLASS[event_type]._VERSION_ADDED
+          event_type = stem.response.events.EVENT_TYPE_TO_CLASS.get(event_type)
 
-          if self.get_version() < event_version:
-            raise stem.InvalidRequest(552, "%s event requires Tor version %s or later" % (event_type, event_version))
+          if event_type and (self.get_version() < event_type._VERSION_ADDED):
+            raise stem.InvalidRequest(552, "%s event requires Tor version %s or later" % (event_type, event_type._VERSION_ADDED))
 
       for event_type in events:
         self._event_listeners.setdefault(event_type, []).append(listener)





More information about the tor-commits mailing list