[tor-commits] [stem/master] Supporing DESCCHANGED events

atagar at torproject.org atagar at torproject.org
Mon Dec 3 02:35:44 UTC 2012


commit 7f73e1c2c92bd949c29b1430200778d46be4d0cc
Author: Damian Johnson <atagar at torproject.org>
Date:   Wed Nov 21 09:05:40 2012 -0800

    Supporing DESCCHANGED events
    
    Adding support for DESCCHANGED events. These are trivial since... well, they
    don't contain any attributes. I'm also filling in some missing EventType enum
    documentation and changing the API docs for events to automatically pick up new
    event types (there's no point in using autoclass rather than automodule in this
    case).
---
 docs/api/response.rst        |    9 +--------
 stem/control.py              |   31 +++++++++++++++++--------------
 stem/response/events.py      |    9 +++++++++
 test/unit/response/events.py |   22 ++++++++++++++++++++++
 4 files changed, 49 insertions(+), 22 deletions(-)

diff --git a/docs/api/response.rst b/docs/api/response.rst
index a73f172..b2dcda0 100644
--- a/docs/api/response.rst
+++ b/docs/api/response.rst
@@ -15,12 +15,5 @@ Responses
 Events
 ------
 
-.. autoclass:: stem.response.events.Event
-.. autoclass:: stem.response.events.LogEvent
-.. autoclass:: stem.response.events.AddrMapEvent
-.. autoclass:: stem.response.events.BandwidthEvent
-.. autoclass:: stem.response.events.CircuitEvent
-.. autoclass:: stem.response.events.NewDescEvent
-.. autoclass:: stem.response.events.ORConnEvent
-.. autoclass:: stem.response.events.StreamEvent
+.. automodule:: stem.response.events
 
diff --git a/stem/control.py b/stem/control.py
index 3e0a61c..29b77ef 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -69,20 +69,23 @@ providing its own for interacting at a higher level.
   :class:`~stem.control.Controller` can listen for. Enums are mapped to
   :class:`~stem.response.events.Event` subclasses as follows...
   
-  =========== ===========
-  EventType   Event Class
-  =========== ===========
-  **DEBUG**   :class:`stem.response.events.LogEvent`
-  **INFO**    :class:`stem.response.events.LogEvent`
-  **NOTICE**  :class:`stem.response.events.LogEvent`
-  **WARN**    :class:`stem.response.events.LogEvent`
-  **ERR**     :class:`stem.response.events.LogEvent`
-  **BW**      :class:`stem.response.events.BandwidthEvent`
-  **CIRC**    :class:`stem.response.events.CircuitEvent`
-  **NEWDESC** :class:`stem.response.events.NewDescEvent`
-  **ORCONN**  :class:`stem.response.events.ORConnEvent`
-  **STREAM**  :class:`stem.response.events.StreamEvent`
-  =========== ===========
+  ===================== ===========
+  EventType             Event Class
+  ===================== ===========
+  **DEBUG**             :class:`stem.response.events.LogEvent`
+  **INFO**              :class:`stem.response.events.LogEvent`
+  **NOTICE**            :class:`stem.response.events.LogEvent`
+  **WARN**              :class:`stem.response.events.LogEvent`
+  **ERR**               :class:`stem.response.events.LogEvent`
+  **ADDRMAP**           :class:`stem.response.events.AddrMapEvent`
+  **AUTHDIR_NEWDESCS**  :class:`stem.response.events.AuthDirNewDescEvent`
+  **BW**                :class:`stem.response.events.BandwidthEvent`
+  **CIRC**              :class:`stem.response.events.CircuitEvent`
+  **DESCCHANGED**       :class:`stem.response.events.DescChangedEvent`
+  **NEWDESC**           :class:`stem.response.events.NewDescEvent`
+  **ORCONN**            :class:`stem.response.events.ORConnEvent`
+  **STREAM**            :class:`stem.response.events.StreamEvent`
+  ===================== ===========
 """
 
 from __future__ import with_statement
diff --git a/stem/response/events.py b/stem/response/events.py
index 9e13974..f6027aa 100644
--- a/stem/response/events.py
+++ b/stem/response/events.py
@@ -282,6 +282,14 @@ class CircuitEvent(Event):
       log_id = "event.circ.unknown_remote_reason.%s" % self.remote_reason
       log.log_once(log_id, log.INFO, unrecognized_msg % ('remote reason', self.remote_reason))
 
+class DescChangedEvent(Event):
+  """
+  Event that indicates that our descriptor has changed. This was first added in
+  tor version 0.1.2.2.
+  """
+  
+  pass
+
 class LogEvent(Event):
   """
   Tor logging event. These are the most visible kind of event since, by
@@ -473,6 +481,7 @@ EVENT_TYPE_TO_CLASS = {
   "AUTHDIR_NEWDESCS": AuthDirNewDescEvent,
   "BW": BandwidthEvent,
   "CIRC": CircuitEvent,
+  "DESCCHANGED": DescChangedEvent,
   "NEWDESC": NewDescEvent,
   "ORCONN": ORConnEvent,
   "STREAM": StreamEvent,
diff --git a/test/unit/response/events.py b/test/unit/response/events.py
index c5eeb5b..c0d1fca 100644
--- a/test/unit/response/events.py
+++ b/test/unit/response/events.py
@@ -138,6 +138,17 @@ class TestEvents(unittest.TestCase):
     self.assertEqual(None, event.error)
     self.assertEqual(datetime.datetime(2012, 11, 19, 8, 50, 13), event.gmt_expiry)
   
+  def test_authdir_newdesc_event(self):
+    # TODO: We aren't actually parsing the event yet. Until then we can only
+    # check that we properly get a AuthDirNewDescEvent for it.
+    
+    event = _get_event("650 AUTHDIR_NEWDESCS")
+    
+    self.assertTrue(isinstance(event, stem.response.events.AuthDirNewDescEvent))
+    self.assertEqual("AUTHDIR_NEWDESCS", str(event))
+    self.assertEqual([], event.positional_args)
+    self.assertEqual({}, event.keyword_args)
+  
   def test_bw_event(self):
     event = _get_event("650 BW 15 25")
     
@@ -255,6 +266,17 @@ class TestEvents(unittest.TestCase):
     self.assertEqual(None, event.reason)
     self.assertEqual(None, event.remote_reason)
   
+  def test_descchanged_event(self):
+    # all we can check for is that the event is properly parsed as a
+    # DescChangedEvent instance
+    
+    event = _get_event("650 DESCCHANGED")
+    
+    self.assertTrue(isinstance(event, stem.response.events.DescChangedEvent))
+    self.assertEqual("DESCCHANGED", str(event))
+    self.assertEqual([], event.positional_args)
+    self.assertEqual({}, event.keyword_args)
+  
   def test_newdesc_event(self):
     event = _get_event(NEWDESC_SINGLE)
     expected_relays = (("B3FA3110CC6F42443F039220C134CBD2FC4F0493", "Sakura"),)





More information about the tor-commits mailing list