本文整理汇总了Python中txtorcon.TorControlProtocol.lineReceived方法的典型用法代码示例。如果您正苦于以下问题:Python TorControlProtocol.lineReceived方法的具体用法?Python TorControlProtocol.lineReceived怎么用?Python TorControlProtocol.lineReceived使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类txtorcon.TorControlProtocol
的用法示例。
在下文中一共展示了TorControlProtocol.lineReceived方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ProtocolTests
# 需要导入模块: from txtorcon import TorControlProtocol [as 别名]
# 或者: from txtorcon.TorControlProtocol import lineReceived [as 别名]
#.........这里部分代码省略.........
# second one still gets called.
listener0 = EventListener()
listener0.do_error = True
listener1 = EventListener()
self.protocol.add_event_listener('STREAM', listener0)
self.protocol.add_event_listener('STREAM', listener1)
d = self.protocol.defer
self.send(b"250 OK")
self._wait(d)
self.send(b"650 STREAM 1234 NEW 4321 1.2.3.4:555 REASON=MISC")
self.send(b"650 STREAM 2345 NEW 4321 2.3.4.5:666 REASON=MISC")
self.assertEqual(listener0.stream_events, 2)
self.assertEqual(listener1.stream_events, 2)
# should have logged the two errors
logged = self.flushLoggedErrors()
self.assertEqual(2, len(logged))
self.assertTrue("the bad thing happened" in str(logged[0]))
self.assertTrue("the bad thing happened" in str(logged[1]))
def test_remove_eventlistener(self):
self.protocol._set_valid_events('STREAM')
class EventListener(object):
stream_events = 0
def __call__(self, data):
self.stream_events += 1
listener = EventListener()
self.protocol.add_event_listener('STREAM', listener)
self.assertEqual(self.transport.value(), b'SETEVENTS STREAM\r\n')
self.protocol.lineReceived(b"250 OK")
self.transport.clear()
self.protocol.remove_event_listener('STREAM', listener)
self.assertEqual(self.transport.value(), b'SETEVENTS \r\n')
def test_remove_eventlistener_multiple(self):
self.protocol._set_valid_events('STREAM')
class EventListener(object):
stream_events = 0
def __call__(self, data):
self.stream_events += 1
listener0 = EventListener()
listener1 = EventListener()
self.protocol.add_event_listener('STREAM', listener0)
self.assertEqual(self.transport.value(), b'SETEVENTS STREAM\r\n')
self.protocol.lineReceived(b"250 OK")
self.transport.clear()
# add another one, shouldn't issue a tor command
self.protocol.add_event_listener('STREAM', listener1)
self.assertEqual(self.transport.value(), b'')
# remove one, should still not issue a tor command
self.protocol.remove_event_listener('STREAM', listener0)
self.assertEqual(self.transport.value(), b'')
# remove the other one, NOW should issue a command
self.protocol.remove_event_listener('STREAM', listener1)
self.assertEqual(self.transport.value(), b'SETEVENTS \r\n')
# try removing invalid event