本文整理汇总了Python中txtorcon.TorControlProtocol.signal方法的典型用法代码示例。如果您正苦于以下问题:Python TorControlProtocol.signal方法的具体用法?Python TorControlProtocol.signal怎么用?Python TorControlProtocol.signal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类txtorcon.TorControlProtocol
的用法示例。
在下文中一共展示了TorControlProtocol.signal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ProtocolTests
# 需要导入模块: from txtorcon import TorControlProtocol [as 别名]
# 或者: from txtorcon.TorControlProtocol import signal [as 别名]
#.........这里部分代码省略.........
server_nonce = bytes(bytearray([0] * 32))
server_hash = bytes(bytearray([0] * 32))
# pretend we already did PROTOCOLINFO and read the cookie
# file
self.protocol._cookie_data = cookiedata
self.protocol.client_nonce = server_nonce # all 0's anyway
try:
self.protocol._safecookie_authchallenge(
'250 AUTHCHALLENGE SERVERHASH={} SERVERNONCE={}'.format(
b2a_hex(server_hash).decode('ascii'),
b2a_hex(server_nonce).decode('ascii'),
)
)
self.assertTrue(False)
except RuntimeError as e:
self.assertTrue('hash not expected' in str(e))
def confirm_version_events(self, arg):
self.assertEqual(self.protocol.version, 'foo')
events = 'GUARD STREAM CIRC NS NEWCONSENSUS ORCONN NEWDESC ADDRMAP STATUS_GENERAL'.split()
self.assertEqual(len(self.protocol.valid_events), len(events))
self.assertTrue(all(x in self.protocol.valid_events for x in events))
def test_bootstrap_callback(self):
d = self.protocol.post_bootstrap
d.addCallback(CallbackChecker(self.protocol))
d.addCallback(self.confirm_version_events)
events = b'GUARD STREAM CIRC NS NEWCONSENSUS ORCONN NEWDESC ADDRMAP STATUS_GENERAL'
self.protocol._bootstrap()
# answer all the requests generated by boostrapping etc.
self.send(b"250-signal/names=")
self.send(b"250 OK")
self.send(b"250-version=foo")
self.send(b"250 OK")
self.send(b"250-events/names=" + events)
self.send(b"250 OK")
self.send(b"250 OK") # for USEFEATURE
return d
def test_bootstrap_tor_does_not_support_signal_names(self):
self.protocol._bootstrap()
self.send(b'552 Unrecognized key "signal/names"')
valid_signals = ["RELOAD", "DUMP", "DEBUG", "NEWNYM", "CLEARDNSCACHE"]
self.assertEqual(self.protocol.valid_signals, valid_signals)
def test_async(self):
"""
test the example from control-spec.txt to see that we
handle interleaved async notifications properly.
"""
self.protocol._set_valid_events('CIRC')
self.protocol.add_event_listener('CIRC', lambda _: None)
self.send(b"250 OK")
d = self.protocol.get_conf("SOCKSPORT ORPORT")
self.send(b"650 CIRC 1000 EXTENDED moria1,moria2")
self.send(b"250-SOCKSPORT=9050")
self.send(b"250 ORPORT=0")
return d