[tor-commits] [stem/master] Optionally having NEWCONSENSUS provide unparsed content

atagar at torproject.org atagar at torproject.org
Sun Oct 29 19:14:36 UTC 2017


commit c2c2b9b4926960f5215b21a3e2a13a40ae6b009a
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Oct 29 12:13:30 2017 -0700

    Optionally having NEWCONSENSUS provide unparsed content
    
    Parsing the whole consensus can be burdensome. Skip doing this upfront so the
    caller can decide if they want a parsed version or not.
---
 docs/change_log.rst     |  1 +
 stem/response/events.py | 28 ++++++++++++++++++++++------
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/docs/change_log.rst b/docs/change_log.rst
index a1fe57f6..4699c2b9 100644
--- a/docs/change_log.rst
+++ b/docs/change_log.rst
@@ -56,6 +56,7 @@ The following are only available within Stem's `git repository
   * Better error message when :func:`~stem.control.Controller.set_conf` fails due to an option being immutable
   * :func:`~stem.control.Controller.is_geoip_unavailable` now determines if database is available right away
   * Added the time attribute to :class:`~stem.response.events.StreamBwEvent` and :class:`~stem.response.events.CircuitBandwidthEvent` (:spec:`00b9daf`)
+  * Added the consensus_content attribute to :class:`~stem.response.events.NewConsensusEvent` and deprecated its 'desc'
   * Deprecated :func:`~stem.control.Controller.is_geoip_unavailable`, this is now available via getinfo instead (:trac:`23237`, :spec:`dc973f8`)
   * Deprecated :class:`~stem.respose.events.AuthDirNewDescEvent` (:trac:`22377`, :spec:`6e887ba`)
   * Caching manual information as sqlite rather than stem.util.conf, making :func:`stem.manual.Manual.from_cache` about ~8x faster
diff --git a/stem/response/events.py b/stem/response/events.py
index fcc92855..256ec30e 100644
--- a/stem/response/events.py
+++ b/stem/response/events.py
@@ -20,6 +20,7 @@ from stem.util import str_type, int_type, connection, log, str_tools, tor_tools
 KW_ARG = re.compile('^(.*) ([A-Za-z0-9_]+)=(\S*)$')
 QUOTED_KW_ARG = re.compile('^(.*) ([A-Za-z0-9_]+)="(.*)"$')
 CELL_TYPE = re.compile('^[a-z0-9_]+$')
+PARSE_NEWCONSENSUS_EVENTS = True
 
 
 class Event(stem.response.ControlMessage):
@@ -234,7 +235,6 @@ class AuthDirNewDescEvent(Event):
   removed in 0.3.2.1-alpha. (:spec:`6e887ba`)
 
   .. deprecated:: 1.6.0
-
      Tor dropped this event as of version 0.3.2.1. (:spec:`6e887ba`)
 
   :var stem.AuthDescriptorAction action: what is being done with the descriptor
@@ -804,6 +804,19 @@ class NewConsensusEvent(Event):
 
   The NEWCONSENSUS event was introduced in tor version 0.2.1.13-alpha.
 
+  .. versionchanged:: 1.6.0
+     Added the consensus_content attribute.
+
+  .. deprecated:: 1.6.0
+     In Stem 2.0 we'll remove the desc attribute, so this event only provides
+     the unparsed consensus. Callers can then parse it if they'd like. To drop
+     parsing before then you can set...
+
+     ::
+
+       stem.response.events.PARSE_NEWCONSENSUS_EVENTS = False
+
+  :var str consensus_content: consensus content
   :var list desc: :class:`~stem.descriptor.router_status_entry.RouterStatusEntryV3` for the changed descriptors
   """
 
@@ -816,11 +829,14 @@ class NewConsensusEvent(Event):
     # TODO: For stem 2.0.0 consider changing 'desc' to 'descriptors' to match
     # our other events.
 
-    self.desc = list(stem.descriptor.router_status_entry._parse_file(
-      io.BytesIO(str_tools._to_bytes(content)),
-      False,
-      entry_class = stem.descriptor.router_status_entry.RouterStatusEntryV3,
-    ))
+    if PARSE_NEWCONSENSUS_EVENTS:
+      self.desc = list(stem.descriptor.router_status_entry._parse_file(
+        io.BytesIO(str_tools._to_bytes(content)),
+        False,
+        entry_class = stem.descriptor.router_status_entry.RouterStatusEntryV3,
+      ))
+    else:
+      self.desc = None
 
 
 class NewDescEvent(Event):



More information about the tor-commits mailing list