[tor-commits] [stem/master] Stub for AUTHDIR_NEWDESCS events
atagar at torproject.org
atagar at torproject.org
Mon Dec 3 02:35:44 UTC 2012
commit 84ec250529b81cb86899897784602e6c41fb8d98
Author: Damian Johnson <atagar at torproject.org>
Date: Tue Nov 20 09:37:54 2012 -0800
Stub for AUTHDIR_NEWDESCS events
Implementing the parts that I can for AUTHDIR_NEWDESCS events. The spec doesn't
provide enough detail for us to parse them (https://trac.torproject.org/7533)
and I need an example of an event before I can test them
(https://trac.torproject.org/7534).
---
stem/__init__.py | 22 ++++++++++++++++++++++
stem/response/events.py | 35 +++++++++++++++++++++++++++++++++--
2 files changed, 55 insertions(+), 2 deletions(-)
diff --git a/stem/__init__.py b/stem/__init__.py
index f0fca41..c2c001a 100644
--- a/stem/__init__.py
+++ b/stem/__init__.py
@@ -230,6 +230,22 @@ Library for working with the tor process.
**IOERROR** unknown
**RESOURCELIMIT** unknown
=================== ===========
+
+.. data:: AuthDescriptorAction (enum)
+
+ Actions that directory authorities might take with relay descriptors. Tor may
+ provide reasons not in this enum.
+
+ Enum descriptions are pending...
+ https://trac.torproject.org/7533
+
+ ===================== ===========
+ AuthDescriptorAction Description
+ ===================== ===========
+ **ACCEPTED** unknown
+ **DROPPED** unknown
+ **REJECTED** unknown
+ ===================== ===========
"""
__version__ = '0.0.1'
@@ -443,3 +459,9 @@ ORClosureReason = stem.util.enum.UppercaseEnum(
"RESOURCELIMIT",
)
+AuthDescriptorAction = stem.util.enum.UppercaseEnum(
+ "ACCEPTED",
+ "DROPPED",
+ "REJECTED",
+)
+
diff --git a/stem/response/events.py b/stem/response/events.py
index 941e796..9e13974 100644
--- a/stem/response/events.py
+++ b/stem/response/events.py
@@ -32,6 +32,7 @@ class Event(stem.response.ControlMessage):
_POSITIONAL_ARGS = ()
_KEYWORD_ARGS = {}
_QUOTED = ()
+ _SKIP_PARSING = False
def _parse_message(self, arrived_at):
if not str(self).strip():
@@ -48,6 +49,21 @@ class Event(stem.response.ControlMessage):
self.positional_args = []
self.keyword_args = {}
+ if not self._SKIP_PARSING:
+ self._parse_standard_attr()
+
+ self._parse()
+
+ def _parse_standard_attr(self):
+ """
+ Most events are of the form...
+ 650 *( positional_args ) *( key "=" value )
+
+ This parses this standard format, populating our **positional_args** and
+ **keyword_args** attributes and creating attributes if it's in our event's
+ **_POSITIONAL_ARGS** and **_KEYWORD_ARGS**.
+ """
+
# Whoever decided to allow for quoted attributes in events should be
# punished. Preferably under some of those maritime laws that allow for
# flogging. Event parsing was nice until we threw this crap in...
@@ -112,8 +128,6 @@ class Event(stem.response.ControlMessage):
for controller_attr_name, attr_name in self._KEYWORD_ARGS.items():
setattr(self, attr_name, self.keyword_args.get(controller_attr_name))
-
- self._parse()
# method overwritten by our subclasses for special handling that they do
def _parse(self):
@@ -154,6 +168,20 @@ class AddrMapEvent(Event):
if self.gmt_expiry != None:
self.gmt_expiry = datetime.datetime.strptime(self.gmt_expiry, "%Y-%m-%d %H:%M:%S")
+class AuthDirNewDescEvent(Event):
+ """
+ Event specific to directory authorities, indicating that we just received new
+ descriptors.
+
+ **Unimplemented, waiting on 'https://trac.torproject.org/7534'.**
+
+ :var stem.AuthDescriptorAction action: what is being done with the descriptor
+ :var str message: unknown
+ :var stem.descriptor.Descriptor descriptor: unknown
+ """
+
+ _SKIP_PARSING = True
+
class BandwidthEvent(Event):
"""
Event emitted every second with the bytes sent and received by tor.
@@ -263,6 +291,8 @@ class LogEvent(Event):
:var str message: logged message
"""
+ _SKIP_PARSING = True
+
def _parse(self):
self.runlevel = self.type
@@ -440,6 +470,7 @@ EVENT_TYPE_TO_CLASS = {
"WARN": LogEvent,
"ERR": LogEvent,
"ADDRMAP": AddrMapEvent,
+ "AUTHDIR_NEWDESCS": AuthDirNewDescEvent,
"BW": BandwidthEvent,
"CIRC": CircuitEvent,
"NEWDESC": NewDescEvent,
More information about the tor-commits
mailing list