[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Alphabetizing event types



commit dff8a0edf35a6e52f2d0e1d52fee71f891146c23
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Nov 18 13:03:46 2012 -0800

    Alphabetizing event types
    
    I had been following an order similar to the control spec but on reflection
    that doesn't make sense. Ordering these alphabetically would be better.
---
 stem/control.py         |    1 +
 stem/response/events.py |   76 +++++++++++++++++++++++-----------------------
 2 files changed, 39 insertions(+), 38 deletions(-)

diff --git a/stem/control.py b/stem/control.py
index 0ddc63c..d7dec9a 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -79,6 +79,7 @@ providing its own for interacting at a higher level.
   **ERR**     :class:`stem.response.events.LogEvent`
   **BW**      :class:`stem.response.events.BandwidthEvent`
   **CIRC**    :class:`stem.response.events.CircuitEvent`
+  **STREAM**  :class:`stem.response.events.StreamEvent`
   =========== ===========
 """
 
diff --git a/stem/response/events.py b/stem/response/events.py
index e24b797..0e7a71e 100644
--- a/stem/response/events.py
+++ b/stem/response/events.py
@@ -78,6 +78,27 @@ class Event(stem.response.ControlMessage):
   def _parse(self):
     pass
 
+class BandwidthEvent(Event):
+  """
+  Event emitted every second with the bytes sent and received by tor.
+  
+  :var long read: bytes received by tor that second
+  :var long written: bytes sent by tor that second
+  """
+  
+  _POSITIONAL_ARGS = ("read", "written")
+  
+  def _parse(self):
+    if not self.read:
+      raise stem.ProtocolError("BW event is missing its read value")
+    elif not self.written:
+      raise stem.ProtocolError("BW event is missing its written value")
+    elif not self.read.isdigit() or not self.written.isdigit():
+      raise stem.ProtocolError("A BW event's bytes sent and received should be a positive numeric value, received: %s" % self)
+    
+    self.read = long(self.read)
+    self.written = long(self.written)
+
 class CircuitEvent(Event):
   """
   Event that indicates that a circuit has changed.
@@ -157,6 +178,23 @@ 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 LogEvent(Event):
+  """
+  Tor logging event. These are the most visible kind of event since, by
+  default, tor logs at the NOTICE runlevel to stdout.
+  
+  :var str runlevel: runlevel of the logged message
+  :var str message: logged message
+  """
+  
+  def _parse(self):
+    self.runlevel = self.type
+    
+    # message is our content, minus the runlevel and ending "OK" if a
+    # multi-line message
+    
+    self.message = str(self)[len(self.runlevel) + 1:].rstrip("\nOK")
+
 class StreamEvent(Event):
   """
   Event that indicates that a stream has changed.
@@ -237,44 +275,6 @@ class StreamEvent(Event):
       log_id = "event.stream.purpose.%s" % self.purpose
       log.log_once(log_id, log.INFO, unrecognized_msg % ('purpose', self.purpose))
 
-class BandwidthEvent(Event):
-  """
-  Event emitted every second with the bytes sent and received by tor.
-  
-  :var long read: bytes received by tor that second
-  :var long written: bytes sent by tor that second
-  """
-  
-  _POSITIONAL_ARGS = ("read", "written")
-  
-  def _parse(self):
-    if not self.read:
-      raise stem.ProtocolError("BW event is missing its read value")
-    elif not self.written:
-      raise stem.ProtocolError("BW event is missing its written value")
-    elif not self.read.isdigit() or not self.written.isdigit():
-      raise stem.ProtocolError("A BW event's bytes sent and received should be a positive numeric value, received: %s" % self)
-    
-    self.read = long(self.read)
-    self.written = long(self.written)
-
-class LogEvent(Event):
-  """
-  Tor logging event. These are the most visible kind of event since, by
-  default, tor logs at the NOTICE runlevel to stdout.
-  
-  :var str runlevel: runlevel of the logged message
-  :var str message: logged message
-  """
-  
-  def _parse(self):
-    self.runlevel = self.type
-    
-    # message is our content, minus the runlevel and ending "OK" if a
-    # multi-line message
-    
-    self.message = str(self)[len(self.runlevel) + 1:].rstrip("\nOK")
-
 EVENT_TYPE_TO_CLASS = {
   "CIRC": CircuitEvent,
   "STREAM": StreamEvent,



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits