[tor-commits] [stem/master] Correcting StatusEvent's docs and adding an 'arguments' attribute
atagar at torproject.org
atagar at torproject.org
Sun Aug 24 01:35:39 UTC 2014
commit 6d48a779c406643b8bdd2ceb4ad33299e092cbee
Author: Damian Johnson <atagar at torproject.org>
Date: Sat Aug 23 18:31:45 2014 -0700
Correcting StatusEvent's docs and adding an 'arguments' attribute
Our StatusEvent class misdocumented its 'action' argument as being called
'message'. Also, it wasn't clear that it commonly had keyword arguments
available. Technically they were available since the parent class supplied
these in its keyword_args attribute, but adding an alias for that to the
StatusEvent to make it clear that they're usually provided.
Issues caught by sysrqb on...
https://trac.torproject.org/12925
---
stem/response/events.py | 10 +++++++++-
test/unit/response/events.py | 2 +-
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/stem/response/events.py b/stem/response/events.py
index 0065d68..b640d2d 100644
--- a/stem/response/events.py
+++ b/stem/response/events.py
@@ -848,7 +848,8 @@ class StatusEvent(Event):
:var stem.StatusType status_type: category of the status event
:var stem.Runlevel runlevel: runlevel of the logged message
- :var str message: logged message
+ :var str action: activity that caused this message
+ :var dict arguments: attributes about the event
"""
_POSITIONAL_ARGS = ('runlevel', 'action')
@@ -864,6 +865,13 @@ class StatusEvent(Event):
else:
raise ValueError("BUG: Unrecognized status type (%s), likely an EVENT_TYPE_TO_CLASS addition without revising how 'status_type' is assigned." % self.type)
+ # Just an alias for our parent class' keyword_args since that already
+ # parses these for us. Unlike our other event types Tor commonly supplies
+ # arbitrary key/value pairs for these, so making an alias here to better
+ # draw attention that the StatusEvent will likely have them.
+
+ self.arguments = self.keyword_args
+
self._log_if_unrecognized('runlevel', stem.Runlevel)
diff --git a/test/unit/response/events.py b/test/unit/response/events.py
index dac2609..a44d536 100644
--- a/test/unit/response/events.py
+++ b/test/unit/response/events.py
@@ -900,7 +900,7 @@ class TestEvents(unittest.TestCase):
'SUMMARY': 'Loading relay descriptors',
}
- self.assertEqual(expected_attr, event.keyword_args)
+ self.assertEqual(expected_attr, event.arguments)
def test_status_event_bootstrap_stuck(self):
event = _get_event(STATUS_CLIENT_BOOTSTRAP_STUCK)
More information about the tor-commits
mailing list