本文整理汇总了Python中twisted.protocols.amp.AMP类的典型用法代码示例。如果您正苦于以下问题:Python AMP类的具体用法?Python AMP怎么用?Python AMP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AMP类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, agent):
"""
:param IConvergenceAgent agent: Convergence agent to notify of changes.
"""
locator = _AgentLocator(agent)
AMP.__init__(self, locator=locator)
self.agent = agent
示例2: connected_amp_protocol
def connected_amp_protocol():
"""
:return: ``AMP`` hooked up to transport.
"""
p = AMP()
p.makeConnection(StringTransport())
return p
示例3: test_adds_user
def test_adds_user(self):
"""
When L{UserAdder} is connected to L{IdentityAdmin}, the L{AddUser}
command is called and L{IdentityAdmin} adds the user to its factory's
store.
"""
admin = IdentityAdmin()
admin.factory = self.adminFactory
serverTransport = makeFakeServer(admin)
serverTransport.getQ2QHost = lambda: Q2QAddress('Q2Q Host')
client = AMP()
pump = connect(admin, serverTransport, client, makeFakeClient(client))
d = client.callRemote(AddUser, name='q2q username',
password='q2q password')
pump.flush()
# The username and password are added, along with the domain=q2q
# host, to the IdentityAdmin's factory's store
self.assertEqual([call('Q2Q Host', 'q2q username', 'q2q password')],
self.addUser.calls)
# The server responds with {}
self.assertEqual({}, self.successResultOf(d))
示例4: connectionLost
def connectionLost(self, reason):
for id, producer in self._producers.items():
consumer = self._consumers.get(id)
if consumer is None:
self._finishReceiving(id, reason)
else:
self._finishSending(id, reason)
AMP.connectionLost(self, reason)
示例5: __init__
def __init__(self, *a, **kw):
AMP.__init__(self, *a, **kw)
self._producers = {}
self._consumers = {}
self._buffers = {}
self._pending = {}
self._waitingOnCompletion = {}
self._draining = set()
示例6: connectionLost
def connectionLost(self, reason):
"""
If a login has happened, perform a logout.
"""
AMP.connectionLost(self, reason)
if self.logout is not None:
self.logout()
self.boxReceiver = self.logout = None
示例7: run_amp_command
def run_amp_command(description, command, args, reactor=None):
if reactor is None:
from twisted.internet import reactor
endpoint = endpoints.clientFromString(reactor, description)
amp = AMP()
d = endpoints.connectProtocol(endpoint, amp)
d.addCallback(lambda ign: amp.callRemote(command, **args))
return d
示例8: startReceivingBoxes
def startReceivingBoxes(self, sender):
AMP.startReceivingBoxes(self, sender)
counts = []
for i in range(random.randrange(1, 5)):
d = self.callRemote(Count)
d.addCallback(display, self.identifier)
counts.append(d)
gatherResults(counts).chainDeferred(self.finished)
示例9: __init__
def __init__(self, reactor, agent):
"""
:param IReactorTime reactor: A reactor to use to schedule periodic ping
operations.
:param IConvergenceAgent agent: Convergence agent to notify of changes.
"""
locator = _AgentLocator(agent)
AMP.__init__(self, locator=locator)
self.agent = agent
self._pinger = Pinger(reactor)
示例10: __init__
def __init__(self, reactor, control_amp_service):
"""
:param reactor: See ``ControlServiceLocator.__init__``.
:param ControlAMPService control_amp_service: The service managing AMP
connections to the control service.
"""
locator = ControlServiceLocator(reactor, control_amp_service)
AMP.__init__(self, locator=locator)
self.control_amp_service = control_amp_service
self._pinger = Pinger(reactor)
示例11: __init__
def __init__(self, reactor, agent):
"""
:param IReactorTime reactor: A reactor to use to schedule periodic ping
[email protected]
:param IConvergenceAgent agent: Convergence agent to notify of changes.
"""
locator = _AgentLocator(agent, timeout_for_protocol(reactor, self))
AMP.__init__(self, locator=locator)
self.agent = agent
self._pinger = Pinger(reactor)
示例12: connectionLost
def connectionLost(self, reason):
"""
Inform the associated L{conncache.ConnectionCache} that this
protocol has been disconnected.
"""
self.nexus.conns.connectionLostForKey((endpoint.Q2QEndpoint(
self.nexus.svc,
self.nexus.addr,
self.transport.getQ2QPeer(),
PROTOCOL_NAME), None))
AMP.connectionLost(self, reason)
示例13: test_periodic_noops
def test_periodic_noops(self):
"""
When connected, the protocol sends ``NoOp`` commands at a fixed
interval.
"""
expected_pings = 3
reactor = Clock()
locator = _NoOpCounter()
peer = AMP(locator=locator)
protocol = self.build_protocol(reactor)
pump = connectedServerAndClient(lambda: protocol, lambda: peer)[2]
for i in range(expected_pings):
reactor.advance(PING_INTERVAL.total_seconds())
peer.callRemote(NoOp) # Keep the other side alive past its timeout
pump.flush()
self.assertEqual(locator.noops, expected_pings)
示例14: test_stuff
def test_stuff(self):
svc = FakeQ2QService()
serverAddr = q2q.Q2QAddress("domain", "accounts")
server = AMP()
def respond(box):
self.assertEqual(box['_command'], "add_user")
self.assertEqual(box['name'], "user")
self.assertEqual(box['password'], "password")
return AmpBox()
server.amp_ADD_USER = respond
factory = Factory.forProtocol(lambda: server)
chooser = {"identity-admin": factory}
svc.listenQ2Q(serverAddr, chooser, "Admin")
d = q2qclient.enregister(svc, q2q.Q2QAddress("domain", "user"), "password")
svc.flush()
self.successResultOf(d)
示例15: setUp
def setUp(self):
self.managerTransport = StringTransport()
self.managerAMP = LocalWorkerAMP()
self.managerAMP.makeConnection(self.managerTransport)
self.result = TestResult()
self.workerTransport = StringTransport()
self.worker = AMP()
self.worker.makeConnection(self.workerTransport)
config = trial.Options()
self.testName = "twisted.doesnexist"
config['tests'].append(self.testName)
self.testCase = trial._getSuite(config)._tests.pop()
self.managerAMP.run(self.testCase, self.result)
self.managerTransport.clear()