commit 03f32518527070f4584aa52b7ce2ea11028cc2ba Author: Damian Johnson atagar@torproject.org Date: Mon Sep 19 22:12:30 2016 -0700
Stacktrace when queue module is present
When running with the python 2.x if you have the queue module we use io.StringIO rather than StringIO.StringIO. This causes two of our Controller's methods to fail with...
Traceback (most recent call last): File "circuits.py", line 7, in <module> for circ in sorted(controller.get_circuits()): File "/usr/lib/python2.7/site-packages/stem/control.py", line 455, in wrapped return func(self, *args, **kwargs) File "/usr/lib/python2.7/site-packages/stem/control.py", line 3284, in get_circuits circ_message = stem.socket.recv_message(StringIO('650 CIRC ' + circ + '\r\n')) TypeError: initial_value must be unicode or None, not str
Thanks to mancha for catching this! --- docs/change_log.rst | 4 ++-- stem/control.py | 7 +++---- stem/response/__init__.py | 8 ++------ 3 files changed, 7 insertions(+), 12 deletions(-)
diff --git a/docs/change_log.rst b/docs/change_log.rst index 7ae3466..2959f6b 100644 --- a/docs/change_log.rst +++ b/docs/change_log.rst @@ -3,7 +3,7 @@ Change Log
The following is a log of all user-facing changes to Stem, both released and unreleased. For a monthly report on work being done see my `development log -https://www.atagar.com/log.php`_. +http://blog.atagar.com/`_.
* :ref:`versioning` * :ref:`unreleased` @@ -107,7 +107,7 @@ The following are only available within Stem's `git repository
* `Comparison of our descriptor parsing libraries <tutorials/mirror_mirror_on_the_wall.html#are-there-any-other-parsing-libraries>`_ * Example for `custom path selection for circuits <tutorials/to_russia_with_love.html#custom-path-selection>`_ (:trac:`8728`) - * Example for `persisting ephemeral hidden service keys <<tutorials/over_the_river.html#ephemeral-hidden-services>`_ + * Example for `persisting ephemeral hidden service keys <tutorials/over_the_river.html#ephemeral-hidden-services>`_
.. _version_1.4:
diff --git a/stem/control.py b/stem/control.py index dfa5add..af22c8f 100644 --- a/stem/control.py +++ b/stem/control.py @@ -252,11 +252,10 @@ except ImportError: from stem.util.ordereddict import OrderedDict
try: + # Added in 3.x import queue - from io import StringIO except ImportError: import Queue as queue - from StringIO import StringIO
import stem.descriptor.microdescriptor import stem.descriptor.reader @@ -3281,7 +3280,7 @@ class Controller(BaseController): response = self.get_info('circuit-status')
for circ in response.splitlines(): - circ_message = stem.socket.recv_message(StringIO('650 CIRC ' + circ + '\r\n')) + circ_message = stem.socket.recv_message(io.StringIO(stem.util.str_tools._to_unicode('650 CIRC ' + circ + '\r\n'))) stem.response.convert('EVENT', circ_message, arrived_at = 0) circuits.append(circ_message)
@@ -3464,7 +3463,7 @@ class Controller(BaseController): response = self.get_info('stream-status')
for stream in response.splitlines(): - message = stem.socket.recv_message(StringIO('650 STREAM ' + stream + '\r\n')) + message = stem.socket.recv_message(io.StringIO(stem.util.str_tools._to_unicode('650 STREAM ' + stream + '\r\n'))) stem.response.convert('EVENT', message, arrived_at = 0) streams.append(message)
diff --git a/stem/response/__init__.py b/stem/response/__init__.py index b6715fc..3300d41 100644 --- a/stem/response/__init__.py +++ b/stem/response/__init__.py @@ -30,6 +30,7 @@ Parses replies from the control socket. +- pop_mapping - removes and returns the next entry as a KEY=VALUE mapping """
+import io import re import threading
@@ -48,11 +49,6 @@ __all__ = [ 'SingleLineResponse', ]
-try: - from StringIO import StringIO -except ImportError: - from io import StringIO - KEY_ARG = re.compile('^(\S+)=')
# Escape sequences from the 'esc_for_log' function of tor's 'common/util.c'. @@ -157,7 +153,7 @@ class ControlMessage(object): :returns: stem.response.ControlMessage instance """
- msg = stem.socket.recv_message(StringIO(content)) + msg = stem.socket.recv_message(io.StringIO(stem.util.str_tools._to_unicode(content)))
if msg_type is not None: convert(msg_type, msg, **kwargs)