本文整理汇总了Python中txtorcon.Circuit.listen方法的典型用法代码示例。如果您正苦于以下问题:Python Circuit.listen方法的具体用法?Python Circuit.listen怎么用?Python Circuit.listen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类txtorcon.Circuit
的用法示例。
在下文中一共展示了Circuit.listen方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_is_built
# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import listen [as 别名]
def test_is_built(self):
tor = FakeTorController()
a = FakeRouter('$E11D2B2269CC25E67CA6C9FB5843497539A74FD0', 'a')
b = FakeRouter('$50DD343021E509EB3A5A7FD0D8A4F8364AFBDCB5', 'b')
c = FakeRouter('$253DFF1838A2B7782BE7735F74E50090D46CA1BC', 'c')
tor.routers['$E11D2B2269CC25E67CA6C9FB5843497539A74FD0'] = a
tor.routers['$50DD343021E509EB3A5A7FD0D8A4F8364AFBDCB5'] = b
tor.routers['$253DFF1838A2B7782BE7735F74E50090D46CA1BC'] = c
circuit = Circuit(tor)
circuit.listen(tor)
circuit.update('123 EXTENDED $E11D2B2269CC25E67CA6C9FB5843497539A74FD0=eris,$50DD343021E509EB3A5A7FD0D8A4F8364AFBDCB5=venus,$253DFF1838A2B7782BE7735F74E50090D46CA1BC=chomsky PURPOSE=GENERAL'.split())
built0 = circuit.is_built
built1 = circuit.when_built()
self.assertTrue(built0 is not built1)
self.assertFalse(built0.called)
self.assertFalse(built1.called)
circuit.update('123 BUILT $E11D2B2269CC25E67CA6C9FB5843497539A74FD0=eris,$50DD343021E509EB3A5A7FD0D8A4F8364AFBDCB5=venus,$253DFF1838A2B7782BE7735F74E50090D46CA1BC=chomsky PURPOSE=GENERAL'.split())
# create callback when we're alread in BUILT; should be
# callback'd already
built2 = circuit.when_built()
self.assertTrue(built2 is not built1)
self.assertTrue(built2 is not built0)
self.assertTrue(built0.called)
self.assertTrue(built1.called)
self.assertTrue(built2.called)
self.assertTrue(built0.result == circuit)
self.assertTrue(built1.result == circuit)
self.assertTrue(built2.result == circuit)
示例2: test_updates
# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import listen [as 别名]
def test_updates(self):
tor = FakeTorController()
circuit = Circuit(tor)
circuit.listen(tor)
tor.routers['$E11D2B2269CC25E67CA6C9FB5843497539A74FD0'] = FakeRouter(
'$E11D2B2269CC25E67CA6C9FB5843497539A74FD0', 'a'
)
tor.routers['$50DD343021E509EB3A5A7FD0D8A4F8364AFBDCB5'] = FakeRouter(
'$50DD343021E509EB3A5A7FD0D8A4F8364AFBDCB5', 'b'
)
tor.routers['$253DFF1838A2B7782BE7735F74E50090D46CA1BC'] = FakeRouter(
'$253DFF1838A2B7782BE7735F74E50090D46CA1BC', 'c'
)
for ex in examples[:-1]:
circuit.update(ex.split()[1:])
self.assertEqual(circuit.state, ex.split()[2])
self.assertEqual(circuit.purpose, 'GENERAL')
if '$' in ex:
self.assertEqual(
len(circuit.path),
len(ex.split()[3].split(','))
)
for (r, p) in zip(ex.split()[3].split(','), circuit.path):
d = r.split('=')[0]
self.assertEqual(d, p.id_hash)
示例3: test_close_circuit
# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import listen [as 别名]
def test_close_circuit(self):
tor = FakeTorController()
a = FakeRouter('$E11D2B2269CC25E67CA6C9FB5843497539A74FD0', 'a')
b = FakeRouter('$50DD343021E509EB3A5A7FD0D8A4F8364AFBDCB5', 'b')
c = FakeRouter('$253DFF1838A2B7782BE7735F74E50090D46CA1BC', 'c')
tor.routers['$E11D2B2269CC25E67CA6C9FB5843497539A74FD0'] = a
tor.routers['$50DD343021E509EB3A5A7FD0D8A4F8364AFBDCB5'] = b
tor.routers['$253DFF1838A2B7782BE7735F74E50090D46CA1BC'] = c
circuit = Circuit(tor)
circuit.listen(tor)
circuit.update('123 EXTENDED $E11D2B2269CC25E67CA6C9FB5843497539A74FD0=eris,$50DD343021E509EB3A5A7FD0D8A4F8364AFBDCB5=venus,$253DFF1838A2B7782BE7735F74E50090D46CA1BC=chomsky PURPOSE=GENERAL'.split())
self.assertEqual(3, len(circuit.path))
d = circuit.close()
# we already pretended that Tor answered "OK" to the
# CLOSECIRCUIT call (see close_circuit() in FakeTorController
# above) however the circuit isn't "really" closed yet...
self.assertTrue(not d.called)
# not unit-test-y? shouldn't probably delve into internals I
# suppose...
self.assertTrue(circuit._closing_deferred is not None)
# simulate that Tor has really closed the circuit for us
# this should cause our Deferred to callback
circuit.update('123 CLOSED $E11D2B2269CC25E67CA6C9FB5843497539A74FD0=eris,$50DD343021E509EB3A5A7FD0D8A4F8364AFBDCB5=venus,$253DFF1838A2B7782BE7735F74E50090D46CA1BC=chomsky PURPOSE=GENERAL REASON=FINISHED'.split())
# confirm that our circuit callback has been triggered already
self.assertRaises(
defer.AlreadyCalledError,
d.callback,
"should have been called already"
)
return d
示例4: test_extend_messages
# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import listen [as 别名]
def test_extend_messages(self):
tor = FakeTorController()
a = FakeRouter('$E11D2B2269CC25E67CA6C9FB5843497539A74FD0', 'a')
b = FakeRouter('$50DD343021E509EB3A5A7FD0D8A4F8364AFBDCB5', 'b')
c = FakeRouter('$253DFF1838A2B7782BE7735F74E50090D46CA1BC', 'c')
tor.routers['$E11D2B2269CC25E67CA6C9FB5843497539A74FD0'] = a
tor.routers['$50DD343021E509EB3A5A7FD0D8A4F8364AFBDCB5'] = b
tor.routers['$253DFF1838A2B7782BE7735F74E50090D46CA1BC'] = c
circuit = Circuit(tor)
circuit.listen(tor)
circuit.update('365 LAUNCHED PURPOSE=GENERAL'.split())
self.assertEqual(tor.extend, [])
circuit.update('365 EXTENDED $E11D2B2269CC25E67CA6C9FB5843497539A74FD0=eris PURPOSE=GENERAL'.split())
self.assertEqual(len(tor.extend), 1)
self.assertEqual(tor.extend[0], (circuit, a))
circuit.update('365 EXTENDED $E11D2B2269CC25E67CA6C9FB5843497539A74FD0=eris,$50DD343021E509EB3A5A7FD0D8A4F8364AFBDCB5=venus PURPOSE=GENERAL'.split())
self.assertEqual(len(tor.extend), 2)
self.assertEqual(tor.extend[0], (circuit, a))
self.assertEqual(tor.extend[1], (circuit, b))
circuit.update('365 EXTENDED $E11D2B2269CC25E67CA6C9FB5843497539A74FD0=eris,$50DD343021E509EB3A5A7FD0D8A4F8364AFBDCB5=venus,$253DFF1838A2B7782BE7735F74E50090D46CA1BC=chomsky PURPOSE=GENERAL'.split())
self.assertEqual(len(tor.extend), 3)
self.assertEqual(tor.extend[0], (circuit, a))
self.assertEqual(tor.extend[1], (circuit, b))
self.assertEqual(tor.extend[2], (circuit, c))
示例5: test_failed_reason
# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import listen [as 别名]
def test_failed_reason(self):
tor = FakeTorController()
circuit = Circuit(tor)
circuit.listen(tor)
circuit.update('1 FAILED $E11D2B2269CC25E67CA6C9FB5843497539A74FD0=eris PURPOSE=GENERAL REASON=TIMEOUT'.split())
self.assertEqual(len(tor.failed), 1)
self.assertEqual(tor.failed[0], (circuit, 'TIMEOUT'))
示例6: test_close_circuit
# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import listen [as 别名]
def test_close_circuit(self):
tor = FakeTorController()
a = FakeRouter('$E11D2B2269CC25E67CA6C9FB5843497539A74FD0', 'a')
b = FakeRouter('$50DD343021E509EB3A5A7FD0D8A4F8364AFBDCB5', 'b')
c = FakeRouter('$253DFF1838A2B7782BE7735F74E50090D46CA1BC', 'c')
tor.routers['$E11D2B2269CC25E67CA6C9FB5843497539A74FD0'] = a
tor.routers['$50DD343021E509EB3A5A7FD0D8A4F8364AFBDCB5'] = b
tor.routers['$253DFF1838A2B7782BE7735F74E50090D46CA1BC'] = c
circuit = Circuit(tor, self.protocol)
circuit.listen(tor)
circuit.update('123 EXTENDED $E11D2B2269CC25E67CA6C9FB5843497539A74FD0=eris,$50DD343021E509EB3A5A7FD0D8A4F8364AFBDCB5=venus,$253DFF1838A2B7782BE7735F74E50090D46CA1BC=chomsky PURPOSE=GENERAL'.split())
self.assertEqual(3, len(circuit.path))
d = circuit.close()
self.assertTrue(self.protocol.deferred is not None)
# simulate the success of the CIRCUITCLOSED call"
self.protocol.deferred.callback("it went swimmingly")
# simulate that Tor has really closed the circuit for us (via failing it, in this case)
circuit.update('123 CLOSED $E11D2B2269CC25E67CA6C9FB5843497539A74FD0=eris,$50DD343021E509EB3A5A7FD0D8A4F8364AFBDCB5=venus,$253DFF1838A2B7782BE7735F74E50090D46CA1BC=chomsky PURPOSE=GENERAL REASON=FINISHED'.split())
# confirm that our circuit callback has been triggered already
self.assertRaises(defer.AlreadyCalledError, d.callback, "should have been called already")
return d
示例7: test_wrong_update
# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import listen [as 别名]
def test_wrong_update(self):
tor = FakeTorController()
circuit = Circuit(tor)
circuit.listen(tor)
circuit.update('1 LAUNCHED PURPOSE=GENERAL'.split())
self.assertRaises(
Exception,
circuit.update,
'2 LAUNCHED PURPOSE=GENERAL'.split()
)
示例8: test_extends_no_path
# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import listen [as 别名]
def test_extends_no_path(self):
'''
without connectivity, it seems you get EXTENDS messages with no path update.
'''
tor = FakeTorController()
circuit = Circuit(tor)
circuit.listen(tor)
circuit.update('753 EXTENDED BUILD_FLAGS=IS_INTERNAL,NEED_CAPACITY,NEED_UPTIME PURPOSE=MEASURE_TIMEOUT TIME_CREATED=2012-07-30T18:23:18.956704'.split())
self.assertEqual(tor.extend, [])
self.assertEqual(circuit.path, [])
示例9: test_failed_reason
# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import listen [as 别名]
def test_failed_reason(self):
tor = FakeTorController()
circuit = Circuit(tor)
circuit.listen(tor)
circuit.update('1 FAILED $E11D2B2269CC25E67CA6C9FB5843497539A74FD0=eris PURPOSE=GENERAL REASON=TIMEOUT'.split())
self.assertEqual(len(tor.failed), 1)
circ, kw = tor.failed[0]
self.assertEqual(circ, circuit)
self.assertTrue('PURPOSE' in kw)
self.assertTrue('REASON' in kw)
self.assertEqual(kw['PURPOSE'], 'GENERAL')
self.assertEqual(kw['REASON'], 'TIMEOUT')
示例10: test_unlisten
# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import listen [as 别名]
def test_unlisten(self):
tor = FakeTorController()
tor.routers['$E11D2B2269CC25E67CA6C9FB5843497539A74FD0'] = FakeRouter('$E11D2B2269CC25E67CA6C9FB5843497539A74FD0','a')
circuit = Circuit(tor)
circuit.listen(tor)
circuit.update('1 LAUNCHED PURPOSE=GENERAL'.split())
circuit.unlisten(tor)
circuit.update('1 EXTENDED $E11D2B2269CC25E67CA6C9FB5843497539A74FD0=eris PURPOSE=GENERAL'.split())
self.assertEqual(len(tor.circuits), 1)
self.assertTrue(tor.circuits.has_key(1))
self.assertEqual(len(tor.extend), 0)
示例11: test_closed_remaining_streams
# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import listen [as 别名]
def test_closed_remaining_streams(self):
tor = FakeTorController()
circuit = Circuit(tor)
circuit.listen(tor)
circuit.update('1 LAUNCHED PURPOSE=GENERAL'.split())
stream = Stream(tor)
stream.update("1 NEW 0 94.23.164.42.$43ED8310EB968746970896E8835C2F1991E50B69.exit:9001 SOURCE_ADDR=(Tor_internal):0 PURPOSE=DIR_FETCH".split())
circuit.streams.append(stream)
self.assertEqual(len(circuit.streams), 1)
circuit.update('1 CLOSED $E11D2B2269CC25E67CA6C9FB5843497539A74FD0=eris,$50DD343021E509EB3A5A7FD0D8A4F8364AFBDCB5=venus,$253DFF1838A2B7782BE7735F74E50090D46CA1BC=chomsky PURPOSE=GENERAL REASON=FINISHED'.split())
circuit.update('1 FAILED $E11D2B2269CC25E67CA6C9FB5843497539A74FD0=eris,$50DD343021E509EB3A5A7FD0D8A4F8364AFBDCB5=venus,$253DFF1838A2B7782BE7735F74E50090D46CA1BC=chomsky PURPOSE=GENERAL REASON=TIMEOUT'.split())
errs = self.flushLoggedErrors()
self.assertEqual(len(errs), 2)
示例12: test_is_built_errback
# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import listen [as 别名]
def test_is_built_errback(self):
tor = FakeTorController()
a = FakeRouter('$E11D2B2269CC25E67CA6C9FB5843497539A74FD0', 'a')
tor.routers['$E11D2B2269CC25E67CA6C9FB5843497539A74FD0'] = a
state = TorState(tor)
circuit = Circuit(tor)
circuit.listen(tor)
circuit.update('123 EXTENDED $E11D2B2269CC25E67CA6C9FB5843497539A74FD0=eris PURPOSE=GENERAL'.split())
state.circuit_new(circuit)
d = circuit.when_built()
state.circuit_closed(circuit)
self.assertTrue(d.called)
self.assertTrue(isinstance(d.result, Failure))
示例13: test_updates
# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import listen [as 别名]
def test_updates(self):
tor = FakeTorController()
circuit = Circuit(tor)
circuit.listen(tor)
tor.routers["$E11D2B2269CC25E67CA6C9FB5843497539A74FD0"] = FakeRouter(
"$E11D2B2269CC25E67CA6C9FB5843497539A74FD0", "a"
)
tor.routers["$50DD343021E509EB3A5A7FD0D8A4F8364AFBDCB5"] = FakeRouter(
"$50DD343021E509EB3A5A7FD0D8A4F8364AFBDCB5", "b"
)
tor.routers["$253DFF1838A2B7782BE7735F74E50090D46CA1BC"] = FakeRouter(
"$253DFF1838A2B7782BE7735F74E50090D46CA1BC", "c"
)
for ex in examples[:-1]:
circuit.update(ex.split()[1:])
self.assertEqual(circuit.state, ex.split()[2])
self.assertEqual(circuit.purpose, "GENERAL")
if "$" in ex:
self.assertEqual(len(circuit.path), len(ex.split()[3].split(",")))
for (r, p) in zip(ex.split()[3].split(","), circuit.path):
d = r.split("=")[0]
self.assertEqual(d, p.hash)