当前位置: 首页>>代码示例>>Python>>正文


Python Message.prettyprintbody方法代码示例

本文整理汇总了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)
开发者ID:claudiuperta,项目名称:neubot,代码行数:82,代码来源:server.py


注:本文中的neubot.http.message.Message.prettyprintbody方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。