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


Python Deferred.chainDeferred方法代码示例

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


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

示例1: mass

# 需要导入模块: from twisted.internet.defer import Deferred [as 别名]
# 或者: from twisted.internet.defer.Deferred import chainDeferred [as 别名]
    def mass(self, flow, out, user, channel, *args):
        """
		\x02mass\x02 <command> [<arguments>]
		Execute the command with the specified arguments mapped on every piped list item
		The arguments string must contain '?' exactly once, which will hold the iterated items
		"""
        d = Deferred()
        command = " ".join(args).replace("=>", "->")
        for item in flow:
            d.chainDeferred(self._handle(user, channel, command.replace("?", item), True))
        d.callback(None)
        return d
开发者ID:kaiyou,项目名称:pyircbot,代码行数:14,代码来源:evaluation.py

示例2: test_backend_components

# 需要导入模块: from twisted.internet.defer import Deferred [as 别名]
# 或者: from twisted.internet.defer.Deferred import chainDeferred [as 别名]
def test_backend_components():
    testDone = getMainDeferred()

    clientDone = Deferred()
    backend = ClientBackend(clientDone)

    # Give it some components.
    graphics_dummy = DummyComponent(backend.graphicsMessage)
    stdio_dummy    = DummyComponent(backend.stdioMessage)
    network_dummy  = DummyComponent(backend.networkMessage)

    # Tell it they're all ready. A fancier test might randomize the order of
    # these and insert some delays, but this is just a simple smoketest.
    backend.stdioReady(stdio_dummy)
    backend.networkReady(network_dummy)
    backend.graphicsInterfaceReady(graphics_dummy)

    def sendMessages():
        network_dummy.sendMessage(YourIdIs(42).serialize())
        graphics_dummy.sendMessage(RequestQuit().serialize())

    def finalChecks(x):
        # Check that the YourIdIs(42) was successfully forwarded to the
        # graphics interface.
        gotId = False
        for msgData in graphics_dummy.messageLog:
            msg = deserializeMessage(msgData)
            if isinstance(msg, YourIdIs):
                assert msg.playerId == 42
                gotId = True
        assert gotId

    clientDone.addCallback(finalChecks)
    clientDone.chainDeferred(testDone)

    # Make sure to chain the main Deferred's errback to that of this
    # deferLater, so that if something goes wrong in sendMessage then it will
    # be reported (rather than silently dropped).
    d = task.deferLater(reactor, 0.05, sendMessages)
    d.addErrback(testDone.errback)

    return testDone
开发者ID:CheeseLord,项目名称:warts,代码行数:44,代码来源:test_components.py

示例3: ChunkedStreamProducer

# 需要导入模块: from twisted.internet.defer import Deferred [as 别名]
# 或者: from twisted.internet.defer.Deferred import chainDeferred [as 别名]
class ChunkedStreamProducer(object):
    interface.implements(IBodyProducer)

    def __init__(self, started, length=UNKNOWN_LENGTH):
        self.length = length
        self.consumer = None
        self.started = Deferred()
        self.finished = Deferred()

    def startProducing(self, consumer):
        print "ChunkedStreamProducer: START PRODUCING"
        self.consumer = consumer
        self.started.callback(None)
        return self.finished

    def _send(self, result, data):
        print "ChunkedStreamProducer: _SEND"
        return self.consumer.write(data)

    def send(self, data):
        print "ChunkedStreamProducer: SEND"
        d = Deferred()
        self.started.chainDeferred(d)
        d.addCallback(self._send, data)
        return d

    def finish(self):
        def _finish(result):
            self.finished.callback(None)
            return None
        d = Deferred()
        self.started.chainDeferred(d)
        d.addCallback(_finish)
        return d

    def pauseProducing(self):
        print "pause"
        pass

    def stopProducing(self):
        print "STOP"
        pass
开发者ID:Wantering,项目名称:softlayer-object-storage-python,代码行数:44,代码来源:twist.py

示例4: request_chunk

# 需要导入模块: from twisted.internet.defer import Deferred [as 别名]
# 或者: from twisted.internet.defer.Deferred import chainDeferred [as 别名]
    def request_chunk(self, x, z):
        """
        Request a ``Chunk`` to be delivered later.

        :returns: Deferred that will be called with the Chunk
        """

        if not async:
            return deferLater(reactor, 0.000001, self.factory.world.load_chunk,
                x, z)

        if (x, z) in self.chunk_cache:
            return succeed(self.chunk_cache[x, z])
        elif (x, z) in self.dirty_chunk_cache:
            return succeed(self.dirty_chunk_cache[x, z])
        elif (x, z) in self._pending_chunks:
            # Rig up another Deferred and wrap it up in a to-go box.
            d = Deferred()
            self._pending_chunks[x, z].chainDeferred(d)
            return d

        chunk = Chunk(x, z)

        first, second, filename = names_for_chunk(x, z)
        f = self.folder.child(first).child(second)
        if not f.exists():
            f.makedirs()
        f = f.child(filename)
        if f.exists() and f.getsize():
            chunk.load_from_tag(read_from_file(f.open("r")))

        if chunk.populated:
            self.chunk_cache[x, z] = chunk
            return succeed(chunk)

        d = deferToAMPProcess(MakeChunk, x=x, z=z, seed=self.seed,
            generators=configuration.getlist("bravo", "generators"))
        self._pending_chunks[x, z] = d

        def pp(kwargs):
            chunk.blocks = fromstring(kwargs["blocks"],
                dtype=uint8).reshape(chunk.blocks.shape)
            chunk.heightmap = fromstring(kwargs["heightmap"],
                dtype=uint8).reshape(chunk.heightmap.shape)
            chunk.metadata = fromstring(kwargs["metadata"],
                dtype=uint8).reshape(chunk.metadata.shape)
            chunk.skylight = fromstring(kwargs["skylight"],
                dtype=uint8).reshape(chunk.skylight.shape)
            chunk.blocklight = fromstring(kwargs["blocklight"],
                dtype=uint8).reshape(chunk.blocklight.shape)

            chunk.populated = True
            chunk.dirty = True

            # Apply the current season to the chunk.
            if self.season:
                self.season.transform(chunk)

            # Since this chunk hasn't been given to any player yet, there's no
            # conceivable way that any meaningful damage has been accumulated;
            # anybody loading any part of this chunk will want the entire thing.
            # Thus, it should start out undamaged.
            chunk.clear_damage()

            self.dirty_chunk_cache[x, z] = chunk
            del self._pending_chunks[x, z]

            return chunk

        # Set up callbacks.
        d.addCallback(pp)
        # Multiple people might be subscribed to this pending callback. We're
        # going to keep it for ourselves and fork off another Deferred for our
        # caller.
        forked = Deferred()
        d.chainDeferred(forked)
        forked.addCallback(lambda none: chunk)
        return forked
开发者ID:ztripez,项目名称:bravo,代码行数:80,代码来源:world.py


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