本文整理汇总了Python中protocol.Protocol.dataReceived方法的典型用法代码示例。如果您正苦于以下问题:Python Protocol.dataReceived方法的具体用法?Python Protocol.dataReceived怎么用?Python Protocol.dataReceived使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类protocol.Protocol
的用法示例。
在下文中一共展示了Protocol.dataReceived方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Client
# 需要导入模块: from protocol import Protocol [as 别名]
# 或者: from protocol.Protocol import dataReceived [as 别名]
class Client(Protocol):
def __init__(self):
self.engine = Engine()
self.engine.print_traceback = True
self.proto = FitnesseProtocol(self)
def ack(self):
self.ack_received = True
def connectionMade(self):
self.socketToken = sys.argv[4]
request = "GET /?responder=socketCatcher&ticket=%s HTTP/1.1\r\n\r\n" % self.socketToken
bytes = request.encode("UTF-8")
self.transport.write(bytes)
def dataReceived(self, data):
self.proto.dataReceived(data)
def content(self, data):
self.doc = Document(data)
self.doc.visit_tables(self)
def on_table(self, table):
fixture = self.engine.process(table, throw=False)
self.write_table(table)
def on_comment(self, node):
html = str(node.toxml())
self.transport.write(util.format_10_digit_number(len(html) + 1))
self.transport.write(html)
self.transport.write('\n')
def done(self):
self.transport.loseConnection()
def write_table(self, table):
html = str(table.toxml()) # Fixme : str() workaround for 'Data must not be unicode'
self.transport.write(util.format_10_digit_number(len(html) + 1))
self.transport.write(html)
self.transport.write('\n')
def write_number(self, number):
self.transport.write(util.format_10_digit_number(number))
def report(self):
summary = self.engine.summary
# 0 right, 0 wrong, 0 ignored, 0 exceptions
self.write_number(0)
self.write_number(summary.right)
self.write_number(summary.wrong)
self.write_number(summary.ignored)
self.write_number(summary.exceptions)
summary.reset()
示例2: _perform_request
# 需要导入模块: from protocol import Protocol [as 别名]
# 或者: from protocol.Protocol import dataReceived [as 别名]
def _perform_request(self, _, request, session):
request.setHeader('content-type', 'application/stratum')
request.setHeader('server', settings.USER_AGENT)
request.setHeader('x-session-timeout', session.sessionTimeout)
request.setHeader('access-control-allow-origin', '*') # Allow access from any other domain
# Update client's IP address
session.transport.peer = request.getHost()
# Although it isn't intuitive at all, request.getHeader reads request headers,
# but request.setHeader (few lines above) writes response headers...
if 'application/stratum' not in request.getHeader('content-type'):
session.transport.write("%s\n" % json.dumps({'id': None, 'result': None, 'error': (-1, "Content-type must be 'application/stratum'. See http://stratum.bitcoin.cz for more info.", "")}))
self._finish(None, request, session.transport, session.lock)
return
if not session.protocol:
# Build a "protocol connection"
proto = Protocol()
proto.transport = session.transport
proto.factory = self
proto.connectionMade()
session.protocol = proto
else:
proto = session.protocol
# Update callback URL if presented
callback_url = request.getHeader('x-callback-url')
if callback_url != None:
if callback_url == '':
# Blank value of callback URL switches HTTP Push back to HTTP Poll
session.transport.push_url = None
else:
session.transport.push_url = callback_url
data = request.content.read()
if data:
counter = RequestCounter()
counter.on_finish.addCallback(self._finish, request, session.transport, session.lock)
proto.dataReceived(data, request_counter=counter)
else:
# Ping message (empty request) of HTTP Polling
self._finish(None, request, session.transport, session.lock)
示例3: onMessage
# 需要导入模块: from protocol import Protocol [as 别名]
# 或者: from protocol.Protocol import dataReceived [as 别名]
def onMessage(self, msg, is_binary):
Protocol.dataReceived(self, msg)
示例4: TestProtocol
# 需要导入模块: from protocol import Protocol [as 别名]
# 或者: from protocol.Protocol import dataReceived [as 别名]
class TestProtocol(unittest.TestCase):
def setUp(self):
self.proto = Protocol(self)
self.pages = 0
def ack(self):
self.ack_received = True
def content(self, content):
self.data = content
self.pages += 1
def done(self):
self.done_received = True
def test_ack(self):
self.proto.dataReceived('0000000000')
self.assert_(self.ack_received)
def test_length_and_content_in_seperate_blocks(self):
self.proto.dataReceived('0000000000')
self.proto.dataReceived('0000000004')
self.proto.dataReceived('abcd')
self.proto.dataReceived('0000000000')
self.assertEqual(self.pages, 1)
self.assert_(self.done_received)
def test_if_protocol_reads_correct_length(self):
'''this reproduced a bug'''
self.proto.dataReceived('0000000000')
self.proto.dataReceived('0000000004')
self.proto.dataReceived('ab')
self.proto.dataReceived('cd0000000000')
self.assertEqual(self.pages, 1)
self.assert_(self.done_received)
self.assertEqual(self.data, 'abcd')
def test_length_and_content_in_same_block(self):
self.proto.dataReceived('0000000000')
self.proto.dataReceived('0000000004abcd')
self.proto.dataReceived('0000000000')
self.assertEqual(self.pages, 1)
self.assert_(self.done_received)
def test_suite_of_2_pages(self):
self.proto.dataReceived('0000000000')
self.proto.dataReceived('0000000004')
self.proto.dataReceived('abcd')
self.assertEqual(self.data, 'abcd')
self.proto.dataReceived('0000000004')
self.proto.dataReceived('abcd')
self.assertEqual(self.data, 'abcd')
self.proto.dataReceived('0000000000')
self.assertEqual(self.pages, 2)
self.assert_(self.done_received)