当前位置: 首页>>代码示例>>Python>>正文


Python Circuit.update方法代码示例

本文整理汇总了Python中txtorcon.Circuit.update方法的典型用法代码示例。如果您正苦于以下问题:Python Circuit.update方法的具体用法?Python Circuit.update怎么用?Python Circuit.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在txtorcon.Circuit的用法示例。


在下文中一共展示了Circuit.update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_is_built

# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import update [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)
开发者ID:david415,项目名称:txtorcon,代码行数:36,代码来源:test_circuit.py

示例2: test_updates

# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import update [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)
开发者ID:david415,项目名称:txtorcon,代码行数:28,代码来源:test_circuit.py

示例3: test_close_circuit

# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import update [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
开发者ID:david415,项目名称:txtorcon,代码行数:37,代码来源:test_circuit.py

示例4: test_failed_reason

# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import update [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'))
开发者ID:hellais,项目名称:txtorcon,代码行数:9,代码来源:test_circuit.py

示例5: test_close_circuit

# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import update [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
开发者ID:Ryman,项目名称:txtorcon,代码行数:27,代码来源:test_circuit.py

示例6: test_path_update

# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import update [as 别名]
 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,代码行数:10,代码来源:test_circuit.py

示例7: test_wrong_update

# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import update [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()
     )
开发者ID:david415,项目名称:txtorcon,代码行数:12,代码来源:test_circuit.py

示例8: test_extends_no_path

# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import update [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, [])
开发者ID:narastabbocchi,项目名称:txtorcon,代码行数:13,代码来源:test_circuit.py

示例9: test_failed_reason

# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import update [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')
开发者ID:david415,项目名称:txtorcon,代码行数:14,代码来源:test_circuit.py

示例10: test_no_age_yet

# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import update [as 别名]
    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,代码行数:14,代码来源:test_circuit.py

示例11: test_unlisten

# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import update [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)
开发者ID:hellais,项目名称:txtorcon,代码行数:14,代码来源:test_circuit.py

示例12: test_age

# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import update [as 别名]
    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,代码行数:15,代码来源:test_circuit.py

示例13: test_extend_messages

# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import update [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))
开发者ID:david415,项目名称:txtorcon,代码行数:30,代码来源:test_circuit.py

示例14: test_is_built_errback

# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import update [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))
开发者ID:david415,项目名称:txtorcon,代码行数:19,代码来源:test_circuit.py

示例15: test_updates

# 需要导入模块: from txtorcon import Circuit [as 别名]
# 或者: from txtorcon.Circuit import update [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)
开发者ID:aagbsn,项目名称:txtorcon,代码行数:26,代码来源:test_circuit.py


注:本文中的txtorcon.Circuit.update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。