本文整理汇总了Python中txtorcon.Circuit类的典型用法代码示例。如果您正苦于以下问题:Python Circuit类的具体用法?Python Circuit怎么用?Python Circuit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Circuit类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_updates
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)
开发者ID:david415,项目名称:txtorcon,代码行数:26,代码来源:test_circuit.py
示例2: test_failed_reason
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'))
开发者ID:hellais,项目名称:txtorcon,代码行数:7,代码来源:test_circuit.py
示例3: test_path_update
def test_path_update(self):
cp = TorControlProtocol()
state = TorState(cp, False)
circuit = Circuit(state)
circuit.update('1 EXTENDED $E11D2B2269CC25E67CA6C9FB5843497539A74FD0=eris PURPOSE=GENERAL'.split())
self.assertEqual(1, len(circuit.path))
self.assertEqual('$E11D2B2269CC25E67CA6C9FB5843497539A74FD0', circuit.path[0].id_hex)
self.assertEqual('eris', circuit.path[0].name)
开发者ID:arlolra,项目名称:txtorcon,代码行数:8,代码来源:test_circuit.py
示例4: test_str
def test_str(self):
tor = FakeTorController()
circuit = Circuit(tor)
circuit.id = 1
str(circuit)
router = Router(tor)
circuit.path.append(router)
str(circuit)
开发者ID:david415,项目名称:txtorcon,代码行数:8,代码来源:test_circuit.py
示例5: test_wrong_update
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()
)
开发者ID:david415,项目名称:txtorcon,代码行数:10,代码来源:test_circuit.py
示例6: test_is_built
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)
开发者ID:david415,项目名称:txtorcon,代码行数:34,代码来源:test_circuit.py
示例7: test_extends_no_path
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, [])
开发者ID:narastabbocchi,项目名称:txtorcon,代码行数:11,代码来源:test_circuit.py
示例8: test_no_age_yet
def test_no_age_yet(self):
"""
make sure age doesn't explode if there's no TIME_CREATED flag.
"""
tor = FakeTorController()
circuit = Circuit(tor)
now = datetime.datetime.now()
circuit.update('1 LAUNCHED PURPOSE=GENERAL'.split())
self.assertTrue(circuit.time_created is None)
diff = circuit.age(now=now)
self.assertEquals(diff, None)
开发者ID:david415,项目名称:txtorcon,代码行数:12,代码来源:test_circuit.py
示例9: test_failed_reason
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')
开发者ID:david415,项目名称:txtorcon,代码行数:12,代码来源:test_circuit.py
示例10: test_age
def test_age(self):
"""
make sure age does something sensible at least once.
"""
tor = FakeTorController()
circuit = Circuit(tor)
now = datetime.datetime.now()
update = '1 LAUNCHED PURPOSE=GENERAL TIME_CREATED=%s' % time.strftime('%Y-%m-%dT%H:%M:%S')
circuit.update(update.split())
diff = circuit.age(now=now)
self.assertEquals(diff, 0)
self.assertTrue(circuit.time_created is not None)
开发者ID:david415,项目名称:txtorcon,代码行数:13,代码来源:test_circuit.py
示例11: test_close_circuit
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
开发者ID:Ryman,项目名称:txtorcon,代码行数:25,代码来源:test_circuit.py
示例12: test_close_circuit
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
开发者ID:david415,项目名称:txtorcon,代码行数:35,代码来源:test_circuit.py
示例13: test_age_default
def test_age_default(self, fake_datetime):
"""
age() w/ defaults works properly
"""
from datetime import datetime
now = datetime.fromtimestamp(60.0)
fake_datetime.return_value = now
fake_datetime.utcnow = Mock(return_value=now)
tor = FakeTorController()
circuit = Circuit(tor)
circuit._time_created = datetime.fromtimestamp(0.0)
self.assertEquals(circuit.age(), 60)
self.assertTrue(circuit.time_created is not None)
开发者ID:david415,项目名称:txtorcon,代码行数:14,代码来源:test_circuit.py
示例14: test_unlisten
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)
开发者ID:hellais,项目名称:txtorcon,代码行数:12,代码来源:test_circuit.py
示例15: test_closed_remaining_streams
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)
开发者ID:david415,项目名称:txtorcon,代码行数:14,代码来源:test_circuit.py
示例16: test_updates
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)
开发者ID:aagbsn,项目名称:txtorcon,代码行数:24,代码来源:test_circuit.py
示例17: test_is_built_errback
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))
开发者ID:david415,项目名称:txtorcon,代码行数:17,代码来源:test_circuit.py
示例18: test_extend_messages
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))
开发者ID:david415,项目名称:txtorcon,代码行数:28,代码来源:test_circuit.py
示例19: test_str
def test_str(self):
tor = FakeTorController()
circuit = Circuit(tor)
circuit.id = 1
foo = str(circuit)
开发者ID:hellais,项目名称:txtorcon,代码行数:5,代码来源:test_circuit.py
示例20: test_str
def test_str(self):
tor = FakeTorController()
circuit = Circuit(tor, self.protocol)
circuit.id = 1
str(circuit)
开发者ID:Ryman,项目名称:txtorcon,代码行数:5,代码来源:test_circuit.py
注:本文中的txtorcon.Circuit类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论