commit 40827b365e3a5f3dac6d1f8e8ffddd589be6cd70 Author: Damian Johnson atagar@torproject.org Date: Sat Dec 8 15:10:08 2012 -0800
Checking event version prereqs before setting any
Checking that our tor version meets all of the event's version prereqs before setting any. This has a few advantages...
* It makes add_event_listener() an all-or-nothing operation (ie, failing one of the checks means that no listeners are attached, rather than a few)
* Avoids repeated acquisitions of _event_listeners_lock (so other lock users can't slip in-between).
* Lets me fix a bug where we were calling SETEVENTS for each event type, rather than a single call when we're done adding the listeners. --- stem/control.py | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/stem/control.py b/stem/control.py index f7463b0..74127c0 100644 --- a/stem/control.py +++ b/stem/control.py @@ -660,14 +660,17 @@ class Controller(BaseController): :raises: :class:`stem.socket.ControllerError` if unable to set the events """
+ # first checking that tor supports these event types for event_type in events: event_version = stem.response.events.EVENT_TYPE_TO_CLASS[event_type]._VERSION_ADDED if not self.get_version().meets_requirements(event_version): raise stem.InvalidRequest(552, "%s event requires Tor version %s or later" % (event_type, event_version)) - - with self._event_listeners_lock: + + with self._event_listeners_lock: + for event_type in events: self._event_listeners.setdefault(event_type, []).append(listener) - self._attach_listeners() + + self._attach_listeners()
def remove_event_listener(self, listener): """
tor-commits@lists.torproject.org