commit 8662332c844827b2be4ab7ab1c77027738e5723d Author: David Triendl david@triendl.name Date: Sat Jun 22 09:03:50 2013 +0200
Fix parsing of IPv6 address:port pairs in stream events (fixes #9181) --- docs/change_log.rst | 5 +++-- stem/response/events.py | 2 +- test/unit/response/events.py | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/docs/change_log.rst b/docs/change_log.rst index d7f6a53..635a8de 100644 --- a/docs/change_log.rst +++ b/docs/change_log.rst @@ -47,6 +47,7 @@ The following are only available within stem's `git repository * The :class:`~stem.control.Controller` use of cached content wasn't thread safe (:trac:`8607`) * Added :func:`~stem.control.Controller.get_user` method to the:class:`~stem.control.Controller` * Added :func:`~stem.control.Controller.get_pid` method to the:class:`~stem.control.Controller` + * :class:`~stem.response.events.StreamEvent` didn't recognize IPv6 addresses (:trac:`9181`)
* **Descriptors**
@@ -64,8 +65,8 @@ The following are only available within stem's `git repository * **Website**
* Overhaul of stem's `download page <download.html>`_. This included several - improvements, most notably the addition of PyPI, Ubuntu, Fedora, and - FreeBSD. + improvements, most notably the addition of PyPI, Ubuntu, Fedora, Slackware, + and FreeBSD. * Replaced default sphinx header with a navbar menu. * Added this change log. * Added the `FAQ page <faq.html>`_. diff --git a/stem/response/events.py b/stem/response/events.py index b6badd6..75f2532 100644 --- a/stem/response/events.py +++ b/stem/response/events.py @@ -822,7 +822,7 @@ class StreamEvent(Event): if not ':' in self.target: raise stem.ProtocolError("Target location must be of the form 'address:port': %s" % self)
- address, port = self.target.split(':', 1) + address, port = self.target.rsplit(':', 1)
if not connection.is_valid_port(port, allow_zero = True): raise stem.ProtocolError("Target location's port is invalid: %s" % self) diff --git a/test/unit/response/events.py b/test/unit/response/events.py index 0d56309..9c4de01 100644 --- a/test/unit/response/events.py +++ b/test/unit/response/events.py @@ -317,6 +317,8 @@ STREAM_DNS_REQUEST_BAD_2 = "650 STREAM 1113 NEW 0 www.google.com:0 \ SOURCE_ADDR=127.0.0.1:dns \ PURPOSE=DNS_REQUEST"
+STREAM_NEWRESOLVE_IP6 = "650 STREAM 23 NEWRESOLVE 0 2001:db8::1:0 PURPOSE=DNS_REQUEST" +
def _get_event(content): controller_event = mocking.get_message(content) @@ -1118,6 +1120,25 @@ class TestEvents(unittest.TestCase): # SOURCE_ADDR's port is malformed self.assertRaises(ProtocolError, _get_event, STREAM_DNS_REQUEST_BAD_2)
+ # IPv6 address + event = _get_event(STREAM_NEWRESOLVE_IP6) + + self.assertTrue(isinstance(event, stem.response.events.StreamEvent)) + self.assertEqual(STREAM_NEWRESOLVE_IP6.lstrip("650 "), str(event)) + self.assertEqual("23", event.id) + self.assertEqual(StreamStatus.NEWRESOLVE, event.status) + self.assertEqual(None, event.circ_id) + self.assertEqual("2001:db8::1:0", event.target) + self.assertEqual("2001:db8::1", event.target_address) + self.assertEqual(0, event.target_port) + self.assertEqual(None, event.reason) + self.assertEqual(None, event.remote_reason) + self.assertEqual(None, event.source) + self.assertEqual(None, event.source_addr) + self.assertEqual(None, event.source_address) + self.assertEqual(None, event.source_port) + self.assertEqual(StreamPurpose.DNS_REQUEST, event.purpose) + def test_stream_bw_event(self): event = _get_event("650 STREAM_BW 2 15 25")