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


Python amp.Command方法代码示例

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


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

示例1: test_callRemote

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import Command [as 别名]
def test_callRemote(self):
        """
        L{CommandDispatcher.callRemote} should emit a properly formatted '_ask'
        box to its boxSender and record an outstanding L{Deferred}.  When a
        corresponding '_answer' packet is received, the L{Deferred} should be
        fired, and the results translated via the given L{Command}'s response
        de-serialization.
        """
        D = self.dispatcher.callRemote(Hello, hello=b'world')
        self.assertEqual(self.sender.sentBoxes,
                          [amp.AmpBox(_command=b"hello",
                                      _ask=b"1",
                                      hello=b"world")])
        answers = []
        D.addCallback(answers.append)
        self.assertEqual(answers, [])
        self.dispatcher.ampBoxReceived(amp.AmpBox({b'hello': b"yay",
                                                   b'print': b"ignored",
                                                   b'_answer': b"1"}))
        self.assertEqual(answers, [dict(hello=b"yay",
                                         Print=u"ignored")]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:test_amp.py

示例2: test_sendTableWithName

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import Command [as 别名]
def test_sendTableWithName(self):
        """
        You can send a reference to a table through a L{SchemaAMP} via
        L{TableSyntaxByName}.
        """
        client = AMP()

        class SampleCommand(Command):
            arguments = [("id", Integer())]

        class Receiver(AMP):

            @SampleCommand.responder
            def gotIt(self, id):
                self.it = id
                return {}

        server = Receiver()
        clientT = StringTransport()
        serverT = StringTransport()
        client.makeConnection(clientT)
        server.makeConnection(serverT)
        client.callRemote(SampleCommand, id=123)
        server.dataReceived(clientT.io.getvalue())
        self.assertEqual(server.it, 123) 
开发者ID:apple,项目名称:ccs-twistedextensions,代码行数:27,代码来源:test_jobs.py

示例3: test_sendTableWithName

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import Command [as 别名]
def test_sendTableWithName(self):
        """
        You can send a reference to a table through a L{SchemaAMP} via
        L{TableSyntaxByName}.
        """
        client = SchemaAMP(schema)

        class SampleCommand(Command):
            arguments = [("table", TableSyntaxByName())]

        class Receiver(SchemaAMP):

            @SampleCommand.responder
            def gotIt(self, table):
                self.it = table
                return {}

        server = Receiver(schema)
        clientT = StringTransport()
        serverT = StringTransport()
        client.makeConnection(clientT)
        server.makeConnection(serverT)
        client.callRemote(SampleCommand, table=schema.DUMMY_WORK_ITEM)
        server.dataReceived(clientT.io.getvalue())
        self.assertEqual(server.it, schema.DUMMY_WORK_ITEM) 
开发者ID:apple,项目名称:ccs-twistedextensions,代码行数:27,代码来源:test_queue.py

示例4: test_callRemote

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import Command [as 别名]
def test_callRemote(self):
        """
        L{CommandDispatcher.callRemote} should emit a properly formatted '_ask'
        box to its boxSender and record an outstanding L{Deferred}.  When a
        corresponding '_answer' packet is received, the L{Deferred} should be
        fired, and the results translated via the given L{Command}'s response
        de-serialization.
        """
        D = self.dispatcher.callRemote(Hello, hello='world')
        self.assertEquals(self.sender.sentBoxes,
                          [amp.AmpBox(_command="hello",
                                      _ask="1",
                                      hello="world")])
        answers = []
        D.addCallback(answers.append)
        self.assertEquals(answers, [])
        self.dispatcher.ampBoxReceived(amp.AmpBox({'hello': "yay",
                                                   'print': "ignored",
                                                   '_answer': "1"}))
        self.assertEquals(answers, [dict(hello="yay",
                                         Print=u"ignored")]) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:23,代码来源:test_amp.py

示例5: test_responderDecorator

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import Command [as 别名]
def test_responderDecorator(self):
        """
        A method on a L{CommandLocator} subclass decorated with a L{Command}
        subclass's L{responder} decorator should be returned from
        locateResponder, wrapped in logic to serialize and deserialize its
        arguments.
        """
        return self._checkSimpleGreeting(TestLocator, 8) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:test_amp.py

示例6: test_responderOverriding

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import Command [as 别名]
def test_responderOverriding(self):
        """
        L{CommandLocator} subclasses can override a responder inherited from
        a base class by using the L{Command.responder} decorator to register
        a new responder method.
        """
        return self._checkSimpleGreeting(OverridingLocator, 9) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:9,代码来源:test_amp.py

示例7: test_parseResponse

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import Command [as 别名]
def test_parseResponse(self):
        """
        There should be a class method of Command which accepts a
        mapping of argument names to serialized forms and returns a
        similar mapping whose values have been parsed via the
        Command's response schema.
        """
        protocol = object()
        result = b'whatever'
        strings = {b'weird': result}
        self.assertEqual(
            ProtocolIncludingCommand.parseResponse(strings, protocol),
            {'weird': (result, protocol)}) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:15,代码来源:test_amp.py

示例8: test_callRemoteCallsParseResponse

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import Command [as 别名]
def test_callRemoteCallsParseResponse(self):
        """
        Making a remote call on a L{amp.Command} subclass which
        overrides the C{parseResponse} method should call that
        C{parseResponse} method to get the response.
        """
        client = NoNetworkProtocol()
        thingy = b"weeoo"
        response = client.callRemote(MagicSchemaCommand, weird=thingy)
        def gotResponse(ign):
            self.assertEqual(client.parseResponseArguments,
                              ({"weird": thingy}, client))
        response.addCallback(gotResponse)
        return response 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:16,代码来源:test_amp.py

示例9: test_responderCallsParseArguments

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import Command [as 别名]
def test_responderCallsParseArguments(self):
        """
        Making a remote call on a L{amp.Command} subclass which
        overrides the C{parseArguments} method should call that
        C{parseArguments} method to get the arguments.
        """
        protocol = NoNetworkProtocol()
        responder = protocol.locateResponder(MagicSchemaCommand.commandName)
        argument = object()
        response = responder(dict(weird=argument))
        response.addCallback(
            lambda ign: self.assertEqual(protocol.parseArgumentsArguments,
                                         ({"weird": argument}, protocol)))
        return response 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:16,代码来源:test_amp.py

示例10: test_makeArguments

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import Command [as 别名]
def test_makeArguments(self):
        """
        There should be a class method of L{amp.Command} which accepts
        a mapping of argument names to objects and returns a similar
        mapping whose values have been serialized via the command's
        argument schema.
        """
        protocol = object()
        argument = object()
        objects = {'weird': argument}
        ident = u"%d:%d" % (id(argument), id(protocol))
        self.assertEqual(
            ProtocolIncludingCommand.makeArguments(objects, protocol),
            {b'weird': ident.encode("ascii")}) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:16,代码来源:test_amp.py

示例11: test_makeArgumentsUsesCommandType

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import Command [as 别名]
def test_makeArgumentsUsesCommandType(self):
        """
        L{amp.Command.makeArguments}'s return type should be the type
        of the result of L{amp.Command.commandType}.
        """
        protocol = object()
        objects = {"weird": b"whatever"}

        result = ProtocolIncludingCommandWithDifferentCommandType.makeArguments(
            objects, protocol)
        self.assertIs(type(result), MyBox) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:13,代码来源:test_amp.py

示例12: test_callRemoteCallsMakeArguments

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import Command [as 别名]
def test_callRemoteCallsMakeArguments(self):
        """
        Making a remote call on a L{amp.Command} subclass which
        overrides the C{makeArguments} method should call that
        C{makeArguments} method to get the response.
        """
        client = NoNetworkProtocol()
        argument = object()
        response = client.callRemote(MagicSchemaCommand, weird=argument)
        def gotResponse(ign):
            self.assertEqual(client.makeArgumentsArguments,
                             ({"weird": argument}, client))
        response.addCallback(gotResponse)
        return response 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:16,代码来源:test_amp.py

示例13: test_extraArgumentsDisallowed

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import Command [as 别名]
def test_extraArgumentsDisallowed(self):
        """
        L{Command.makeArguments} raises L{amp.InvalidSignature} if the objects
        dictionary passed to it includes a key which does not correspond to the
        Python identifier for a defined argument.
        """
        self.assertRaises(
            amp.InvalidSignature,
            Hello.makeArguments,
            dict(hello="hello", bogusArgument=object()), None) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:test_amp.py

示例14: test_commandNameDefaultsToClassNameAsByteString

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import Command [as 别名]
def test_commandNameDefaultsToClassNameAsByteString(self):
        """
        A L{Command} subclass without a defined C{commandName} that's
        not a byte string.
        """
        class NewCommand(amp.Command):
            """
            A new command.
            """

        self.assertEqual(b"NewCommand", NewCommand.commandName) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:13,代码来源:test_amp.py

示例15: test_commandNameMustBeAByteString

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import Command [as 别名]
def test_commandNameMustBeAByteString(self):
        """
        A L{Command} subclass cannot be defined with a C{commandName} that's
        not a byte string.
        """
        error = self.assertRaises(
            TypeError, type, "NewCommand", (amp.Command, ),
            {"commandName": u"FOO"})
        self.assertRegex(
            str(error), "^Command names must be byte strings, got: u?'FOO'$") 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:test_amp.py


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