commit 86524bf589014f2f6d7a4a9704cc0801663654b2 Author: Sean Robinson seankrobinson@gmail.com Date: Fri Dec 7 04:03:19 2012 -0700
Begin version requirements for events
Check that the tor process is of a minimum version able to generate the events requested. Checking versions here improves on the 'Unrecognized event "XXX"' response from the tor process.
The SETEVENT control message was added to tor version 0.0.9-pre5 (commit 347d3f9d629df74b). But control protocol V1 changed the message syntax in tor version 0.1.1.1-alpha (commit 9b4aa8d2abbce713) and V0 is not supported. Therefor, version 0.1.1.1-alpha is the baseline for any and all events in Stem.
Signed-off-by: Sean Robinson seankrobinson@gmail.com --- stem/control.py | 8 ++++++-- stem/response/events.py | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/stem/control.py b/stem/control.py index a53b9b1..f7463b0 100644 --- a/stem/control.py +++ b/stem/control.py @@ -660,8 +660,12 @@ class Controller(BaseController): :raises: :class:`stem.socket.ControllerError` if unable to set the events """
- with self._event_listeners_lock: - for event_type in events: + 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: self._event_listeners.setdefault(event_type, []).append(listener) self._attach_listeners()
diff --git a/stem/response/events.py b/stem/response/events.py index 7526c88..e6ef1a0 100644 --- a/stem/response/events.py +++ b/stem/response/events.py @@ -6,6 +6,7 @@ import stem import stem.control import stem.response import stem.descriptor.router_status_entry +import stem.version
from stem.util import connection, log, str_tools, tor_tools
@@ -32,6 +33,7 @@ class Event(stem.response.ControlMessage): _KEYWORD_ARGS = {} # map of 'keyword => attribute' for recognized attributes _QUOTED = () # positional arguments that are quoted _SKIP_PARSING = False # skip parsing contents into our positional_args and keyword_args + _VERSION_ADDED = stem.version.Version('0.1.1.1-alpha') # minimum version with control-spec V1 event support
def _parse_message(self, arrived_at): if not str(self).strip():
tor-commits@lists.torproject.org