commit 32d39439b3a1cb2a72b2efc9d3010d2c90b174ee Author: Damian Johnson atagar@torproject.org Date: Wed Mar 6 20:12:06 2013 -0800
Making the arrived_at arg of events optional
The kwargs of stem.response.convert() are documented as being optional, however the arrived_at argument for events was mandatory. Caught by meejah. --- stem/response/events.py | 6 +++++- test/unit/response/events.py | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/stem/response/events.py b/stem/response/events.py index 85710c2..af8c8e5 100644 --- a/stem/response/events.py +++ b/stem/response/events.py @@ -5,6 +5,7 @@ import datetime import re import StringIO +import time
import stem import stem.control @@ -41,7 +42,10 @@ class Event(stem.response.ControlMessage): _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): + def _parse_message(self, arrived_at = None): + if arrived_at is None: + arrived_at = int(time.time()) + if not str(self).strip(): raise stem.ProtocolError("Received a blank tor event. Events must at the very least have a type.")
diff --git a/test/unit/response/events.py b/test/unit/response/events.py index 8a685ff..803de0f 100644 --- a/test/unit/response/events.py +++ b/test/unit/response/events.py @@ -307,7 +307,7 @@ PURPOSE=DNS_REQUEST"
def _get_event(content): controller_event = mocking.get_message(content) - stem.response.convert("EVENT", controller_event, arrived_at = 25) + stem.response.convert("EVENT", controller_event) return controller_event
@@ -344,7 +344,7 @@ class TestEvents(unittest.TestCase):
def test_event(self): # synthetic, contrived message construction to reach the blank event check - self.assertRaises(ProtocolError, stem.response.convert, "EVENT", stem.response.ControlMessage([('', '', '')], ''), arrived_at = 25) + self.assertRaises(ProtocolError, stem.response.convert, "EVENT", stem.response.ControlMessage([('', '', '')], ''))
# Event._parse_message() on an unknown event type event = _get_event('650 NONE SOLID "NON SENSE" condition=MEH quoted="1 2 3"')
tor-commits@lists.torproject.org