本文整理汇总了Python中http_parser.parser.HttpParser.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python HttpParser.__init__方法的具体用法?Python HttpParser.__init__怎么用?Python HttpParser.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类http_parser.parser.HttpParser
的用法示例。
在下文中一共展示了HttpParser.__init__方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: HTTPConnection
# 需要导入模块: from http_parser.parser import HttpParser [as 别名]
# 或者: from http_parser.parser.HttpParser import __init__ [as 别名]
class HTTPConnection(object):
def __init__(self, handle, server):
self.server = server
self.request = None
self.parser = HttpParser(kind=0) # request only parser
self._handle = handle
self._handle.start_read(self._on_read)
self._closed = False
self._must_close = False
self._pending_writes = 0
self._remote_address = self._handle.getpeername()
@property
def remote_address(self):
return self._remote_address
def write(self, data):
self._handle.write(data, self._on_write)
self._pending_writes += 1
def finish(self):
"""Close connection once all pending writes are done"""
if self._closed or self._must_close:
return
if self._pending_writes == 0:
self.close()
else:
self._must_close = True
def close(self):
if self._closed:
return
if DEBUG:
logger.debug('Connection from %s closed', self.remote_address)
self._handle.close(self._on_close)
self._closed = True
def _on_read(self, handle, data, error):
if error is not None:
if DEBUG:
if error == pyuv.errno.UV_EOF:
logger.debug('Client closed connection')
else:
logger.debug('Read error: %d %s', error, pyuv.errno.strerror(error))
self.close()
return
if self.request is None:
self.parser.__init__(kind=0)
self.request = HTTPRequest(self)
self.request.process_data(data)
def _on_close(self, handle):
self.server.connections.remove(self)
self._handle = self.server = self.request = self.parser = None
def _on_write(self, handle, error):
if DEBUG and error is not None:
logger.error('Writing response: %d %s', error, pyuv.errno.strerror(error))
self._pending_writes -= 1
if self._pending_writes == 0 and self._must_close:
self.close()