本文整理汇总了Python中txtorcon.TorState._stream_update方法的典型用法代码示例。如果您正苦于以下问题:Python TorState._stream_update方法的具体用法?Python TorState._stream_update怎么用?Python TorState._stream_update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类txtorcon.TorState
的用法示例。
在下文中一共展示了TorState._stream_update方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StateTests
# 需要导入模块: from txtorcon import TorState [as 别名]
# 或者: from txtorcon.TorState import _stream_update [as 别名]
class StateTests(unittest.TestCase):
def setUp(self):
self.protocol = TorControlProtocol()
self.state = TorState(self.protocol)
self.protocol.connectionMade = lambda: None
self.transport = proto_helpers.StringTransport()
self.protocol.makeConnection(self.transport)
def test_close_stream_with_attacher(self):
class MyAttacher(object):
implements(IStreamAttacher)
def __init__(self):
self.streams = []
def attach_stream(self, stream, circuits):
self.streams.append(stream)
return None
attacher = MyAttacher()
self.state.set_attacher(attacher, FakeReactor(self))
self.state._stream_update("76 CLOSED 0 www.example.com:0 REASON=DONE")
def test_stream_update(self):
## we use a circuit ID of 0 so it doesn't try to look anything up but it's
## not really correct to have a SUCCEEDED w/o a valid circuit, I don't think
self.state._stream_update('1610 SUCCEEDED 0 74.125.224.243:80')
self.assertTrue(1610 in self.state.streams)
def test_single_streams(self):
self.state.circuits[496] = FakeCircuit(496)
self.state._stream_status('stream-status=123 SUCCEEDED 496 www.example.com:6667\r\nOK')
self.assertEqual(len(self.state.streams), 1)
def send(self, line):
self.protocol.dataReceived(line.strip() + "\r\n")
def test_bootstrap_callback(self):
'''
FIXME: something is still screwy with this; try throwing an
exception from TorState.bootstrap and we'll just hang...
'''
d = self.state.post_bootstrap
self.protocol._set_valid_events(' '.join(self.state.event_map.keys()))
self.state._bootstrap()
self.send("250+ns/all=")
self.send(".")
self.send("250 OK")
self.send("250+circuit-status=")
self.send(".")
self.send("250 OK")
self.send("250-stream-status=")
self.send("250 OK")
self.send("250-address-mappings/all=")
self.send("250 OK")
for ignored in self.state.event_map.items():
self.send("250 OK")
fakerouter = object()
self.state.routers['$0000000000000000000000000000000000000000'] = fakerouter
self.state.routers['$9999999999999999999999999999999999999999'] = fakerouter
self.send("250+entry-guards=")
self.send("$0000000000000000000000000000000000000000=name up")
self.send("$1111111111111111111111111111111111111111=foo up")
self.send("$9999999999999999999999999999999999999999=eman unusable 2012-01-01 22:00:00")
self.send(".")
self.send("250 OK")
## implicitly created Router object for the $1111...11 lookup
## but 0.0.0.0 will have to country, so Router will ask Tor
## for one via GETINFO ip-to-country
self.send("250-ip-to-country/0.0.0.0=??")
self.send("250 OK")
self.assertEqual(len(self.state.entry_guards), 2)
self.assertTrue('$0000000000000000000000000000000000000000' in self.state.entry_guards)
self.assertEqual(self.state.entry_guards['$0000000000000000000000000000000000000000'], fakerouter)
self.assertTrue('$1111111111111111111111111111111111111111' in self.state.entry_guards)
self.assertEqual(len(self.state.unusable_entry_guards), 1)
self.assertTrue('$9999999999999999999999999999999999999999' in self.state.unusable_entry_guards[0])
return d
def test_bootstrap_existing_addresses(self):
'''
FIXME: something is still screwy with this; try throwing an
exception from TorState.bootstrap and we'll just hang...
'''
d = self.state.post_bootstrap
#.........这里部分代码省略.........