本文整理匯總了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")])
示例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)
示例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)
示例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")])
示例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)
示例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)
示例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)})
示例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
示例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
示例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")})
示例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)
示例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
示例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)
示例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)
示例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'$")