本文整理汇总了Python中http_parser.parser.HttpParser.is_message_begin方法的典型用法代码示例。如果您正苦于以下问题:Python HttpParser.is_message_begin方法的具体用法?Python HttpParser.is_message_begin怎么用?Python HttpParser.is_message_begin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类http_parser.parser.HttpParser
的用法示例。
在下文中一共展示了HttpParser.is_message_begin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: QHttpConnection
# 需要导入模块: from http_parser.parser import HttpParser [as 别名]
# 或者: from http_parser.parser.HttpParser import is_message_begin [as 别名]
class QHttpConnection(QObject):
newRequest = pyqtSignal(QHttpRequest, QHttpResponse)
disconnected = pyqtSignal()
def __init__(self, sock, parent = None):
super(QHttpConnection, self).__init__(parent)
self.m_sock = sock
self.m_body = []
self.m_parser = HttpParser()
self.m_request = QHttpRequest(self)
self.m_request = None
self.m_response = QHttpResponse(self)
self.m_response = None
self.m_sock.readyRead.connect(self._onReadyRead)
self.m_sock.disconnected.connect(self._onDisconnected)
self.m_sock.bytesWritten.connect(self._onBytesWritten)
return
def write(self, data):
self.m_sock.write(data)
return
def _onReadyRead(self):
#qDebug('hehe')
qtdata = self.m_sock.readAll()
pydata = qtdata.data()
np = self.m_parser.execute(pydata, len(pydata))
qDebug(str(np) + '=?' + str(len(pydata)))
#qDebug(qtdata)
#qDebug(qtdata.toHex())
#print(self.m_parser._body)
#print(self.m_parser._body)
#qDebug(str(self.m_parser.is_message_begin()))
#qDebug(str(self.m_parser.is_message_complete()))
#qDebug(str(self.m_parser.is_headers_complete()))
if self.m_parser.is_headers_complete():
if self.m_request != None:
qWarning('alread have a request object')
else:
self.m_request = QHttpRequest(self)
_qogc.add(self.m_request)
# qDebug(str(self.m_request))
# print(self.m_parser.get_headers())
True
### body area
# qDebug(str(self.m_parser.is_message_begin()))
# not use lines,这个可能指的是在客户端时,数据下载完成标识吧。
if self.m_parser.is_message_begin() and self.m_request != None:
qDebug('body coming...')
self.m_request.hasBody()
mth = self.m_parser.get_method()
# qDebug(mth)
if mth == 'GET':
if self.m_parser.is_headers_complete():
self.m_response = QHttpResponse(self)
self.m_response.done.connect(self._onResponseDone)
_qogc.add(self.m_response)
self.newRequest.emit(self.m_request, self.m_response)
pass
elif mth == 'POST':
if self.m_parser.is_partial_body(): self.m_body.append(self.m_parser.recv_body())
if self.m_parser.is_message_complete(): print(b''.join(self.m_body))
elif mth == 'CONNECT':
if self.m_parser.is_headers_complete():
if self.m_response != None:
qWarning('alread have a response object')
else:
self.m_response = QHttpResponse(self)
self.m_response.done.connect(self._onResponseDone)
_qogc.add(self.m_response)
self.newRequest.emit(self.m_request, self.m_response)
else:
qDebug('hdr not complete')
True
else:
qWarning("not impled method:" + mth)
self.m_sock.close()
return
def _onDisconnected(self):
# qDebug('hehe')
self.disconnected.emit()
return
def _onBytesWritten(self, count):
# qDebug('hehe')
return
#.........这里部分代码省略.........