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


Python amp.AMP属性代码示例

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


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

示例1: connectionMade

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import AMP [as 别名]
def connectionMade(self):
        """
        When connection is made, create the AMP protocol instance.
        """
        self._ampProtocol.makeConnection(LocalWorkerTransport(self.transport))
        if not os.path.exists(self._logDirectory):
            os.makedirs(self._logDirectory)
        self._outLog = open(os.path.join(self._logDirectory, 'out.log'), 'w')
        self._errLog = open(os.path.join(self._logDirectory, 'err.log'), 'w')
        testLog = open(os.path.join(self._logDirectory, self._logFile), 'w')
        self._ampProtocol.setTestStream(testLog)
        logDirectory = self._logDirectory
        if isinstance(logDirectory, unicode):
            logDirectory = logDirectory.encode("utf-8")
        d = self._ampProtocol.callRemote(workercommands.Start,
                                         directory=logDirectory)
        # Ignore the potential errors, the test suite will fail properly and it
        # would just print garbage.
        d.addErrback(lambda x: None) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:worker.py

示例2: setUp

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import AMP [as 别名]
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 = b"twisted.doesnexist"
        config['tests'].append(self.testName)
        self.testCase = trial._getSuite(config)._tests.pop()

        self.managerAMP.run(self.testCase, self.result)
        self.managerTransport.clear() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_worker.py

示例3: test_processEnded

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import AMP [as 别名]
def test_processEnded(self):
        """
        L{LocalWorker.processEnded} calls C{connectionLost} on itself and on
        the L{AMP} protocol.
        """

        class FakeStream(object):
            callNumber = 0

            def close(self):
                self.callNumber += 1


        transport = FakeTransport()
        protocol = FakeAMProtocol()
        localWorker = LocalWorker(protocol, '.', 'test.log')
        localWorker.makeConnection(transport)
        localWorker._outLog = FakeStream()
        localWorker.processEnded(Failure(CONNECTION_DONE))
        self.assertEqual(localWorker._outLog.callNumber, 1)
        self.assertIdentical(None, protocol.transport)
        return self.assertFailure(localWorker.endDeferred, ConnectionDone) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:24,代码来源:test_worker.py

示例4: test_lookupFunctionDeprecatedOverride

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import AMP [as 别名]
def test_lookupFunctionDeprecatedOverride(self):
        """
        Subclasses which override locateResponder under its old name,
        lookupFunction, should have the override invoked instead.  (This tests
        an AMP subclass, because in the version of the code that could invoke
        this deprecated code path, there was no L{CommandLocator}.)
        """
        locator = OverrideLocatorAMP()
        customResponderObject = self.assertWarns(
            PendingDeprecationWarning,
            "Override locateResponder, not lookupFunction.",
            __file__, lambda : locator.locateResponder(b"custom"))
        self.assertEqual(locator.customResponder, customResponderObject)
        # Make sure upcalling works too
        normalResponderObject = self.assertWarns(
            PendingDeprecationWarning,
            "Override locateResponder, not lookupFunction.",
            __file__, lambda : locator.locateResponder(b"simple"))
        result = normalResponderObject(amp.Box(greeting=b"ni hao", cookie=b"5"))
        def done(values):
            self.assertEqual(values, amp.AmpBox(cookieplus=b'8'))
        return result.addCallback(done) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:24,代码来源:test_amp.py

示例5: test_protocolSwitchFail

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import AMP [as 别名]
def test_protocolSwitchFail(self, switcher=SimpleSymmetricCommandProtocol):
        """
        Verify that if we try to switch protocols and it fails, the connection
        stays up and we can go back to speaking AMP.
        """
        self.testSucceeded = False

        serverDeferred = defer.Deferred()
        serverProto = switcher(serverDeferred)
        clientDeferred = defer.Deferred()
        clientProto = switcher(clientDeferred)
        c, s, p = connectedServerAndClient(ServerClass=lambda: serverProto,
                                           ClientClass=lambda: clientProto)
        L = []
        c.switchToTestProtocol(fail=True).addErrback(L.append)
        p.flush()
        L.pop().trap(UnknownProtocol)
        self.assertFalse(self.testSucceeded)
        # It's a known error, so let's send a "hello" on the same connection;
        # it should work.
        c.sendHello(b'world').addCallback(L.append)
        p.flush()
        self.assertEqual(L.pop()['hello'], b'world') 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:25,代码来源:test_amp.py

示例6: test_toStringProto

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import AMP [as 别名]
def test_toStringProto(self):
        """
        To send a file descriptor, L{Descriptor.toStringProto} uses the
        L{IUNIXTransport.sendFileDescriptor} implementation of the transport of
        the protocol passed to it to copy the file descriptor.  Each subsequent
        descriptor sent over a particular AMP connection is assigned the next
        integer value, starting from 0.  The base ten string representation of
        this value is the byte encoding of the argument.

        This is a whitebox test which involves direct L{_DescriptorExchanger}
        state inspection and mutation.
        """
        argument = amp.Descriptor()
        self.assertEqual(b"0", argument.toStringProto(2, self.protocol))
        self.assertEqual(
            ("fileDescriptorReceived", 2 + self.fuzz), self.transport._queue.pop(0))
        self.assertEqual(b"1", argument.toStringProto(4, self.protocol))
        self.assertEqual(
            ("fileDescriptorReceived", 4 + self.fuzz), self.transport._queue.pop(0))
        self.assertEqual(b"2", argument.toStringProto(6, self.protocol))
        self.assertEqual(
            ("fileDescriptorReceived", 6 + self.fuzz), self.transport._queue.pop(0))
        self.assertEqual({}, self.protocol._descriptors) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:25,代码来源:test_amp.py

示例7: test_send_era_on_connect

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import AMP [as 别名]
def test_send_era_on_connect(self):
        """
        Upon connecting a ``SetNodeEraCommand`` is sent with the current
        node's era and UUID.
        """
        client = AgentAMP(self.reactor, self.service)
        # The object that processes incoming AMP commands:
        server_locator = UpdateNodeEraLocator()
        server = AMP(locator=server_locator)
        pump = connectedServerAndClient(lambda: client, lambda: server)[2]
        pump.flush()
        self.assertEqual(
            # Actual result of handling AMP commands, if any:
            dict(era=server_locator.era, uuid=server_locator.uuid),
            # Expected result:
            dict(era=unicode(self.service.era),
                 uuid=unicode(self.deployer.node_uuid))) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:19,代码来源:test_loop.py

示例8: test_sendTableWithName

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import AMP [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

示例9: failsafeResponder

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import AMP [as 别名]
def failsafeResponder(command):
    """
    Wrap an AMP command responder in some fail-safe logic, to make it so that
    unknown errors won't drop the connection, as AMP's default behavior would.
    """
    def wrap(inner):
        @inlineCallbacks
        def innerinner(*a, **k):
            try:
                val = yield inner(*a, **k)
            except:
                f = Failure()
                if f.type in command.errors:
                    returnValue(f)
                else:
                    log.failure("shared database connection pool error", failure=f)
                    raise FailsafeException()
            else:
                returnValue(val)
        return command.responder(innerinner)
    return wrap 
开发者ID:apple,项目名称:ccs-twistedextensions,代码行数:23,代码来源:adbapi2.py

示例10: connectionMade

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import AMP [as 别名]
def connectionMade(self):
        """
        When connection is made, create the AMP protocol instance.
        """
        self._ampProtocol.makeConnection(LocalWorkerTransport(self.transport))
        if not os.path.exists(self._logDirectory):
            os.makedirs(self._logDirectory)
        self._outLog = open(os.path.join(self._logDirectory, 'out.log'), 'wb')
        self._errLog = open(os.path.join(self._logDirectory, 'err.log'), 'wb')
        self._testLog = open(
            os.path.join(self._logDirectory, self._logFile), 'w')
        self._ampProtocol.setTestStream(self._testLog)
        logDirectory = self._logDirectory
        d = self._ampProtocol.callRemote(workercommands.Start,
                                         directory=logDirectory)
        # Ignore the potential errors, the test suite will fail properly and it
        # would just print garbage.
        d.addErrback(lambda x: None) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:20,代码来源:worker.py

示例11: setUp

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import AMP [as 别名]
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() 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:18,代码来源:test_worker.py

示例12: test_processEnded

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import AMP [as 别名]
def test_processEnded(self):
        """
        L{LocalWorker.processEnded} calls C{connectionLost} on itself and on
        the L{AMP} protocol.
        """

        transport = FakeTransport()
        protocol = FakeAMProtocol()
        localWorker = LocalWorker(protocol, '.', 'test.log')
        localWorker.makeConnection(transport)
        localWorker.processEnded(Failure(CONNECTION_DONE))
        self.assertTrue(localWorker._outLog.closed)
        self.assertTrue(localWorker._errLog.closed)
        self.assertTrue(localWorker._testLog.closed)
        self.assertIdentical(None, protocol.transport)
        return self.assertFailure(localWorker.endDeferred, ConnectionDone) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:18,代码来源:test_worker.py

示例13: __init__

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import AMP [as 别名]
def __init__(self, directory):
        """
        """
        amp.AMP.__init__(self)
        self._directory = directory

        # How to large we let an AMP response get before breaking it up
        self._maxSize = 55000

        # The cache of results we have not fully responded with.  A dictionary
        # whose keys are "continuation tokens" and whose values are tuples of
        # (timestamp, list-of-records).  When a response does not fit within
        # AMP size limits, the remaining records are stored in this dictionary
        # keyed by an opaque token we generate to return to the client so that
        # it can ask for the remaining results later.
        self._continuations = {} 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:18,代码来源:server.py

示例14: recordToDict

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import AMP [as 别名]
def recordToDict(self, record):
        """
        Turn a record in a dictionary of fields which can be reconstituted
        within the client
        """
        fields = {}
        if record is not None:
            for field, value in record.fields.iteritems():

                # FIXME: need to sort out dealing with enormous groups; we
                # can ignore these when sending AMP responses because the
                # client will always fetch members via a members( ) AMP
                # command.
                if field.name in (u"memberDNs", u"memberUIDs"):
                    continue

                valueType = record.service.fieldName.valueType(field)
                if valueType in (unicode, bool):
                    fields[field.name] = value
                elif valueType is uuid.UUID:
                    fields[field.name] = str(value)
                elif issubclass(valueType, (Names, NamedConstant)):
                    fields[field.name] = value.name if value else None
        return fields 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:26,代码来源:server.py

示例15: _sendCommand

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import AMP [as 别名]
def _sendCommand(self, command, **kwds):
        """
        Execute a remote AMP command, first making the connection to the peer.
        Any kwds are passed on to the AMP command.

        @param command: the AMP command to call
        @type command: L{twisted.protocols.amp.Command}
        """
        ampProto = (yield self._getConnection())
        try:
            results = (yield ampProto.callRemote(command, **kwds))
        except Exception, e:
            log.error("Failed AMP command", error=e)
            #  FIXME: is there a way to hook into ConnectionLost?
            self._connection = None
            raise 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:18,代码来源:client.py


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