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


Python TorControlProtocol.queue_command方法代码示例

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


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

示例1: FakeTorState

# 需要导入模块: from txtorcon import TorControlProtocol [as 别名]
# 或者: from txtorcon.TorControlProtocol import queue_command [as 别名]
class FakeTorState(object):

    def __init__(self, routers):
        self.routers = routers
        self.protocol = TorControlProtocol()
        self.protocol.connectionMade = lambda: None
        self.protocol.transport = proto_helpers.StringTransport()
        self.protocol.makeConnection(self.protocol.transport)

    def _find_circuit_after_extend(self, x):
        return defer.succeed(None)

    def build_circuit(self, routers=None, using_guards=True):
        cmd = "EXTENDCIRCUIT 0 "
        first = True
        for router in routers:
            if first:
                first = False
            else:
                cmd += ','
            if isinstance(router, basestring) and len(router) == 40 \
               and hashFromHexId(router):
                cmd += router
            else:
                cmd += router.id_hex[1:]
        d = self.protocol.queue_command(cmd)
        print "d %r" % (d,)
        d.addCallback(self._find_circuit_after_extend)
        return d
开发者ID:DonnchaC,项目名称:bwscanner,代码行数:31,代码来源:test_condor.py

示例2: DisconnectionTests

# 需要导入模块: from txtorcon import TorControlProtocol [as 别名]
# 或者: from txtorcon.TorControlProtocol import queue_command [as 别名]
class DisconnectionTests(unittest.TestCase):
    def setUp(self):
        self.protocol = TorControlProtocol()
        self.protocol.connectionMade = lambda: None
        self.transport = proto_helpers.StringTransportWithDisconnection()
        self.protocol.makeConnection(self.transport)
        # why doesn't makeConnection do this?
        self.transport.protocol = self.protocol

    def tearDown(self):
        self.protocol = None

    def test_disconnect_callback(self):
        """
        see that we get our callback on_disconnect if the transport
        goes away
        """
        def it_was_called(*args):
            it_was_called.yes = True
            return None
        it_was_called.yes = False
        self.protocol.on_disconnect.addCallback(it_was_called)
        self.protocol.on_disconnect.addErrback(it_was_called)
        f = failure.Failure(error.ConnectionDone("It's all over"))
        self.protocol.connectionLost(f)
        self.assertTrue(it_was_called.yes)

    def test_when_disconnect(self):
        """
        see that we get our callback for when_disconnected if the
        transport goes away
        """
        def it_was_called(arg):
            it_was_called.yes = True
            return None
        it_was_called.yes = False

        d = self.protocol.when_disconnected()
        d.addCallback(it_was_called)
        f = failure.Failure(error.ConnectionDone("It's all over"))
        self.protocol.connectionLost(f)
        self.assertTrue(it_was_called.yes)

    def test_when_disconnect_error(self):
        """
        see that we get our errback for when_disconnected if the
        transport goes away
        """
        def it_was_called(arg):
            it_was_called.yes = True
            return None
        it_was_called.yes = False

        d = self.protocol.when_disconnected()
        d.addErrback(it_was_called)
        f = failure.Failure(RuntimeError("sadness"))
        self.protocol.connectionLost(f)
        self.assertTrue(it_was_called.yes)

    def test_disconnect_errback(self):
        """
        see that we get our callback on_disconnect if the transport
        goes away
        """
        def it_was_called(*args):
            it_was_called.yes = True
            return None
        it_was_called.yes = False
        self.protocol.on_disconnect.addCallback(it_was_called)
        self.protocol.on_disconnect.addErrback(it_was_called)
        f = failure.Failure(RuntimeError("The thing didn't do the stuff."))
        self.protocol.connectionLost(f)
        self.assertTrue(it_was_called.yes)

    def test_disconnect_outstanding_commands(self):
        """
        outstanding commands should errback on disconnect
        """

        def it_was_called(f):
            str(f)
            it_was_called.count += 1
            return None
        it_was_called.count = 0

        # we want to make sure outstanding commands get errbacks
        d0 = self.protocol.queue_command("some command0")
        d1 = self.protocol.queue_command("some command1")
        d0.addErrback(it_was_called)
        d1.addErrback(it_was_called)
        self.protocol.on_disconnect.addErrback(lambda _: None)

        f = failure.Failure(RuntimeError("The thing didn't do the stuff."))
        self.protocol.connectionLost(f)
        self.assertEqual(it_was_called.count, 2)
开发者ID:meejah,项目名称:txtorcon,代码行数:97,代码来源:test_torcontrolprotocol.py


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