本文整理汇总了Python中neubot.http.message.Message.prettyprintbody方法的典型用法代码示例。如果您正苦于以下问题:Python Message.prettyprintbody方法的具体用法?Python Message.prettyprintbody怎么用?Python Message.prettyprintbody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neubot.http.message.Message
的用法示例。
在下文中一共展示了Message.prettyprintbody方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ServerStream
# 需要导入模块: from neubot.http.message import Message [as 别名]
# 或者: from neubot.http.message.Message import prettyprintbody [as 别名]
class ServerStream(StreamHTTP):
''' Specializes StreamHTTP to implement the server-side
of an HTTP channel '''
def __init__(self, poller):
''' Initialize '''
StreamHTTP.__init__(self, poller)
self.response_rewriter = None
self.request = None
def got_request_line(self, method, uri, protocol):
''' Invoked when we get a request line '''
self.request = Message(method=method, uri=uri, protocol=protocol)
def got_header(self, key, value):
''' Invoked when we get an header '''
if self.request:
self.request[key] = value
else:
self.close()
def got_end_of_headers(self):
''' Invoked at the end of headers '''
if self.request:
if not self.parent.got_request_headers(self, self.request):
return ERROR, 0
return nextstate(self.request)
else:
return ERROR, 0
def got_piece(self, piece):
''' Invoked when we read a piece of the body '''
if self.request:
self.request.body.write(piece)
else:
self.close()
def got_end_of_body(self):
''' Invoked at the end of the body '''
if self.request:
utils.safe_seek(self.request.body, 0)
self.request.prettyprintbody("<")
self.parent.got_request(self, self.request)
self.request = None
else:
self.close()
def send_response(self, request, response):
''' Send a response to the client '''
if self.response_rewriter:
self.response_rewriter(request, response)
if request['connection'] == 'close' or request.protocol == 'HTTP/1.0':
del response['connection']
response['connection'] = 'close'
self.send_message(response)
if response['connection'] == 'close':
self.close()
address = self.peername[0]
now = time.gmtime()
timestring = "%02d/%s/%04d:%02d:%02d:%02d -0000" % (now.tm_mday,
MONTH[now.tm_mon], now.tm_year, now.tm_hour, now.tm_min, now.tm_sec)
requestline = request.requestline
statuscode = response.code
nbytes = "-"
if response["content-length"]:
nbytes = response["content-length"]
if nbytes == "0":
nbytes = "-"
LOG.log("ACCESS",
"%s - - [%s] \"%s\" %s %s",
(address, timestring, requestline, statuscode, nbytes),
None)