本文整理汇总了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)
示例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"])
示例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"])
示例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)
示例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)
示例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)
示例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