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


Python Protocol.dataReceived方法代码示例

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


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

示例1: test_protocolToConsumer

# 需要导入模块: from twisted.internet.protocol import Protocol [as 别名]
# 或者: from twisted.internet.protocol.Protocol import dataReceived [as 别名]
 def test_protocolToConsumer(self):
     """
     L{IProtocol} providers can be adapted to L{IConsumer} providers using
     L{ProtocolToConsumerAdapter}.
     """
     result = []
     p = Protocol()
     p.dataReceived = result.append
     consumer = IConsumer(p)
     consumer.write(b"hello")
     self.assertEqual(result, [b"hello"])
     self.assertIsInstance(consumer, ProtocolToConsumerAdapter)
开发者ID:AlexanderHerlan,项目名称:syncpy,代码行数:14,代码来源:test_protocol.py

示例2: test_identityPumpPolicy

# 需要导入模块: from twisted.internet.protocol import Protocol [as 别名]
# 或者: from twisted.internet.protocol.Protocol import dataReceived [as 别名]
    def test_identityPumpPolicy(self):
        """
        L{identityPumpPolicy} is a pump policy which calls the target's
        C{dataReceived} method one for each string in the queue passed to it.
        """
        bytes = []
        client = Protocol()
        client.dataReceived = bytes.append
        queue = loopback._LoopbackQueue()
        queue.put(b"foo")
        queue.put(b"bar")
        queue.put(None)

        loopback.identityPumpPolicy(queue, client)

        self.assertEqual(bytes, [b"foo", b"bar"])
开发者ID:0004c,项目名称:VTK,代码行数:18,代码来源:test_loopback.py

示例3: test_collapsingPumpPolicy

# 需要导入模块: from twisted.internet.protocol import Protocol [as 别名]
# 或者: from twisted.internet.protocol.Protocol import dataReceived [as 别名]
    def test_collapsingPumpPolicy(self):
        """
        L{collapsingPumpPolicy} is a pump policy which calls the target's
        C{dataReceived} only once with all of the strings in the queue passed
        to it joined together.
        """
        bytes = []
        client = Protocol()
        client.dataReceived = bytes.append
        queue = loopback._LoopbackQueue()
        queue.put(b"foo")
        queue.put(b"bar")
        queue.put(None)

        loopback.collapsingPumpPolicy(queue, client)

        self.assertEqual(bytes, [b"foobar"])
开发者ID:0004c,项目名称:VTK,代码行数:19,代码来源:test_loopback.py

示例4: dataReceived

# 需要导入模块: from twisted.internet.protocol import Protocol [as 别名]
# 或者: from twisted.internet.protocol.Protocol import dataReceived [as 别名]
 def dataReceived(self, data):
     Protocol.dataReceived(self, data)
     self.lockBuffer.acquire().addCallback(self.AddDataAndDecode, data)
开发者ID:skycucumber,项目名称:Messaging-Gateway,代码行数:5,代码来源:ProtocolReactor.py

示例5: connectionMade

# 需要导入模块: from twisted.internet.protocol import Protocol [as 别名]
# 或者: from twisted.internet.protocol.Protocol import dataReceived [as 别名]
 def connectionMade(self):
     """Fire up stdin/stdout once we connect."""
     c = Protocol()
     c.dataReceived = self.write
     self.stdio = stdio.StandardIO(c)
开发者ID:rayleyva,项目名称:trigger,代码行数:7,代码来源:twister.py

示例6: dataReceived

# 需要导入模块: from twisted.internet.protocol import Protocol [as 别名]
# 或者: from twisted.internet.protocol.Protocol import dataReceived [as 别名]
 def dataReceived(self, p_data):
     Protocol.dataReceived(self, p_data)
开发者ID:DBrianKimmel,项目名称:PyHouse,代码行数:4,代码来源:onkyo.py

示例7: _receive

# 需要导入模块: from twisted.internet.protocol import Protocol [as 别名]
# 或者: from twisted.internet.protocol.Protocol import dataReceived [as 别名]
def _receive(response, url, headers, follow_redirect, redirect_history):
    d = Deferred()
    headers = dict(response.headers.getAllRawHeaders())
    code = response.code
    length = response.length

    # check for redirects
    if follow_redirect and (code == 302 or code == 301):
        try:
            redirect = headers['Location'][0]
        except KeyError:
            raise CorruptRedirect, 'Received redirect response without Location header'

        parts = list(urlparse(redirect))
        original_parts = list(urlparse(url))

        if parts[0]=='': parts[0] = original_parts[0]
        if parts[1]=='': parts[1] = original_parts[1]

        redirect = urlunparse(parts)

        if code==301:
            _permanent_redirects[url] = redirect

        if redirect_history is None:
            redirect_history = () # comes from post, don't add as history
        else:
            redirect_history = redirect_history + (url,)

        if redirect in redirect_history:
            raise CyclicRedirect, 'Next url has already been in the redirects cycle: ' + redirect

        return get(redirect, headers, True, redirect_history)

    body = ['']
    last_modified = None

    # common closure
    def close(_):
        response = Response(code, body[0], headers, url, redirect_history)
        if last_modified is not None:
            _cache[url] = (last_modified, body[0])
        d.callback(response)

    # check for not modified:
    if code == 304:
        body[0] = _cache[url][1]
        reactor.callLater(0, close, None)
        return d

    # check for caching
    if 'Last-Modified' in headers:
        last_modified = headers['Last-Modified'][0]

    if length == 0:
        reactor.callLater(0, close, None)
        return d

    # retrieve body
    def _receiveChunk(chunk):
        body[0] = body[0] + chunk

    bodyReceiver = Protocol()
    bodyReceiver.dataReceived = _receiveChunk
    bodyReceiver.connectionLost = close

    response.deliverBody(bodyReceiver)

    return d
开发者ID:petrushev,项目名称:txcrawl,代码行数:71,代码来源:txrequests.py


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