当前位置: 首页>>代码示例>>Python>>正文


Python Stream.listen方法代码示例

本文整理汇总了Python中txtorcon.Stream.listen方法的典型用法代码示例。如果您正苦于以下问题:Python Stream.listen方法的具体用法?Python Stream.listen怎么用?Python Stream.listen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在txtorcon.Stream的用法示例。


在下文中一共展示了Stream.listen方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_ipv6

# 需要导入模块: from txtorcon import Stream [as 别名]
# 或者: from txtorcon.Stream import listen [as 别名]
    def test_ipv6(self):
        listener = Listener([('new', {'target_host': '::1',
                                      'target_port': 80})])

        stream = Stream(self)
        stream.listen(listener)
        stream.update("1234 NEW 0 ::1:80 SOURCE_ADDR=127.0.0.1:57349 PURPOSE=USER".split())
开发者ID:felipedau,项目名称:txtorcon,代码行数:9,代码来源:test_stream.py

示例2: test_stream_changed_with_detach

# 需要导入模块: from txtorcon import Stream [as 别名]
# 或者: from txtorcon.Stream import listen [as 别名]
    def test_stream_changed_with_detach(self):
        "Change a stream-id mid-stream, but with a DETACHED message"
        self.circuits[123] = FakeCircuit(123)
        self.circuits[456] = FakeCircuit(456)

        listener = Listener(
            [
                ('new', {'target_host': 'www.yahoo.com', 'target_port': 80}),
                ('attach', {}),
                ('detach', {'kwargs': dict(reason='END', remote_reason='MISC')}),
                ('attach', {})
            ]
        )

        stream = Stream(self)
        stream.listen(listener)
        stream.update("999 NEW 0 www.yahoo.com:80 SOURCE_ADDR=127.0.0.1:55877 PURPOSE=USER".split())
        stream.update("999 SENTCONNECT 123 1.2.3.4:80".split())
        self.assertEqual(len(self.circuits[123].streams), 1)
        self.assertEqual(self.circuits[123].streams[0], stream)

        stream.update("999 DETACHED 123 1.2.3.4:80 REASON=END REMOTE_REASON=MISC".split())
        self.assertEqual(len(self.circuits[123].streams), 0)

        stream.update("999 SENTCONNECT 456 1.2.3.4:80 SOURCE=EXIT".split())
        self.assertEqual(len(self.circuits[456].streams), 1)
        self.assertEqual(self.circuits[456].streams[0], stream)
开发者ID:felipedau,项目名称:txtorcon,代码行数:29,代码来源:test_stream.py

示例3: test_ipv6_source

# 需要导入模块: from txtorcon import Stream [as 别名]
# 或者: from txtorcon.Stream import listen [as 别名]
    def test_ipv6_source(self):
        listener = Listener(
            [
                ('new', {'source_addr': maybe_ip_addr('::1'),
                         'source_port': 12345})
            ]
        )

        stream = Stream(self)
        stream.listen(listener)
        stream.update("1234 NEW 0 127.0.0.1:80 SOURCE_ADDR=::1:12345 PURPOSE=USER".split())
开发者ID:felipedau,项目名称:txtorcon,代码行数:13,代码来源:test_stream.py

示例4: test_listen_unlisten

# 需要导入模块: from txtorcon import Stream [as 别名]
# 或者: from txtorcon.Stream import listen [as 别名]
    def test_listen_unlisten(self):
        self.circuits[186] = FakeCircuit(186)

        listener = Listener([])

        stream = Stream(self)
        stream.listen(listener)
        stream.listen(listener)
        self.assertEqual(len(stream.listeners), 1)
        stream.unlisten(listener)
        self.assertEqual(len(stream.listeners), 0)
开发者ID:felipedau,项目名称:txtorcon,代码行数:13,代码来源:test_stream.py

示例5: test_listener_fail

# 需要导入模块: from txtorcon import Stream [as 别名]
# 或者: from txtorcon.Stream import listen [as 别名]
 def test_listener_fail(self):
     listener = Listener(
         [
             ('new', {'target_host': 'www.yahoo.com', 'target_port': 80}),
             ('attach', {'target_addr': maybe_ip_addr('1.2.3.4')}),
             ('failed', {'kwargs': dict(REASON='TIMEOUT', REMOTE_REASON='DESTROYED')})
         ]
     )
     stream = Stream(self)
     stream.listen(listener)
     stream.update("316 NEW 0 www.yahoo.com:80 SOURCE_ADDR=127.0.0.1:55877 PURPOSE=USER".split())
     self.circuits[186] = FakeCircuit(186)
     stream.update("316 REMAP 186 1.2.3.4:80 SOURCE=EXIT".split())
     stream.update("316 FAILED 0 1.2.3.4:80 REASON=TIMEOUT REMOTE_REASON=DESTROYED".split())
开发者ID:felipedau,项目名称:txtorcon,代码行数:16,代码来源:test_stream.py

示例6: test_listener_attach_no_remap

# 需要导入模块: from txtorcon import Stream [as 别名]
# 或者: from txtorcon.Stream import listen [as 别名]
    def test_listener_attach_no_remap(self):
        "Attachment is via SENTCONNECT on .onion addresses (for example)"
        self.circuits[186] = FakeCircuit(186)

        listener = Listener([('new', {'target_host': 'www.yahoo.com',
                                      'target_port': 80}),
                             ('attach', {})])

        stream = Stream(self)
        stream.listen(listener)
        stream.update("316 NEW 0 www.yahoo.com:80 SOURCE_ADDR=127.0.0.1:55877 PURPOSE=USER".split())
        stream.update("316 SENTCONNECT 186 1.2.3.4:80 SOURCE=EXIT".split())

        self.assertEqual(self.circuits[186].streams[0], stream)
开发者ID:felipedau,项目名称:txtorcon,代码行数:16,代码来源:test_stream.py

示例7: test_listener_attach

# 需要导入模块: from txtorcon import Stream [as 别名]
# 或者: from txtorcon.Stream import listen [as 别名]
    def test_listener_attach(self):
        self.circuits[186] = FakeCircuit(186)

        listener = Listener(
            [
                ('new', {'target_host': 'www.yahoo.com', 'target_port': 80}),
                ('attach', {'target_addr': maybe_ip_addr('1.2.3.4')})
            ]
        )

        stream = Stream(self)
        stream.listen(listener)
        stream.update("316 NEW 0 www.yahoo.com:80 SOURCE_ADDR=127.0.0.1:55877 PURPOSE=USER".split())
        stream.update("316 REMAP 186 1.2.3.4:80 SOURCE=EXIT".split())

        self.assertEqual(self.circuits[186].streams[0], stream)
开发者ID:felipedau,项目名称:txtorcon,代码行数:18,代码来源:test_stream.py

示例8: test_listener_close

# 需要导入模块: from txtorcon import Stream [as 别名]
# 或者: from txtorcon.Stream import listen [as 别名]
    def test_listener_close(self):
        self.circuits[186] = FakeCircuit(186)

        listener = Listener(
            [
                ('new', {'target_host': 'www.yahoo.com', 'target_port': 80}),
                ('attach', {'target_addr': maybe_ip_addr('1.2.3.4')}),
                ('closed', {'kwargs': dict(REASON='END', REMOTE_REASON='DONE')})
            ]
        )
        stream = Stream(self)
        stream.listen(listener)
        stream.update("316 NEW 0 www.yahoo.com:80 SOURCE_ADDR=127.0.0.1:55877 PURPOSE=USER".split())
        stream.update("316 REMAP 186 1.2.3.4:80 SOURCE=EXIT".split())
        stream.update("316 CLOSED 186 1.2.3.4:80 REASON=END REMOTE_REASON=DONE".split())

        self.assertEqual(len(self.circuits[186].streams), 0)
开发者ID:felipedau,项目名称:txtorcon,代码行数:19,代码来源:test_stream.py

示例9: test_listener_exception

# 需要导入模块: from txtorcon import Stream [as 别名]
# 或者: from txtorcon.Stream import listen [as 别名]
    def test_listener_exception(self):
        """A listener throws an exception during notify"""

        exc = Exception("the bad stuff happened")

        class Bad(StreamListenerMixin):
            def stream_new(*args, **kw):
                raise exc
        listener = Bad()

        stream = Stream(self)
        stream.listen(listener)
        stream.update("1 NEW 0 94.23.164.42.$43ED8310EB968746970896E8835C2F1991E50B69.exit:9001 SOURCE_ADDR=(Tor_internal):0 PURPOSE=DIR_FETCH".split())

        errors = self.flushLoggedErrors()
        self.assertEqual(1, len(errors))
        self.assertEqual(errors[0].value, exc)
开发者ID:felipedau,项目名称:txtorcon,代码行数:19,代码来源:test_stream.py

示例10: test_stream_changed

# 需要导入模块: from txtorcon import Stream [as 别名]
# 或者: from txtorcon.Stream import listen [as 别名]
    def test_stream_changed(self):
        "Change a stream-id mid-stream."
        self.circuits[186] = FakeCircuit(186)

        listener = Listener([('new', {'target_host': 'www.yahoo.com',
                                      'target_port': 80}),
                             ('attach', {}),
                             ('succeeded', {})])

        stream = Stream(self)
        stream.listen(listener)
        stream.update("316 NEW 0 www.yahoo.com:80 SOURCE_ADDR=127.0.0.1:55877 PURPOSE=USER".split())
        stream.update("316 SENTCONNECT 186 1.2.3.4:80 SOURCE=EXIT".split())
        self.assertEqual(self.circuits[186].streams[0], stream)

        # magically change circuit ID without a DETACHED, should fail
        stream.update("316 SUCCEEDED 999 1.2.3.4:80 SOURCE=EXIT".split())
        errs = self.flushLoggedErrors()
        self.assertEqual(len(errs), 1)
        # kind of fragile to look at strings, but...
        self.assertTrue('186 to 999' in str(errs[0]))
开发者ID:felipedau,项目名称:txtorcon,代码行数:23,代码来源:test_stream.py

示例11: test_listener_new

# 需要导入模块: from txtorcon import Stream [as 别名]
# 或者: from txtorcon.Stream import listen [as 别名]
    def test_listener_new(self):
        listener = Listener([('new', {'target_port': 9001})])

        stream = Stream(self)
        stream.listen(listener)
        stream.update("1 NEW 0 94.23.164.42.$43ED8310EB968746970896E8835C2F1991E50B69.exit:9001 SOURCE_ADDR=(Tor_internal):0 PURPOSE=DIR_FETCH".split())
开发者ID:felipedau,项目名称:txtorcon,代码行数:8,代码来源:test_stream.py


注:本文中的txtorcon.Stream.listen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。