python类util()的实例源码

tornado.py 文件源码 项目:SuperOcto 作者: mcecchi 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _handle_method(self, *args, **kwargs):
        """
        Takes care of defining the new request body if necessary and forwarding
        the current request and changed body to the ``fallback``.
        """

        # determine which body to supply
        body = b""
        if self.is_multipart():
            # make sure we really processed all data in the buffer
            while len(self._buffer):
                self._process_multipart_data(self._buffer)

            # use rewritten body
            body = self._new_body

        elif self.request.method in UploadStorageFallbackHandler.BODY_METHODS:
            # directly use data from buffer
            body = self._buffer

        # rewrite content length
        self.request.headers["Content-Length"] = len(body)

        try:
            # call the configured fallback with request and body to use
            self._fallback(self.request, body)
            self._headers_written = True
        finally:
            # make sure the temporary files are removed again
            for f in self._files:
                octoprint.util.silent_remove(f)

    # make all http methods trigger _handle_method
tornado.py 文件源码 项目:SuperOcto 作者: mcecchi 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _extended_header_value(value):
    if not value:
        return value

    if value.lower().startswith("iso-8859-1'") or value.lower().startswith("utf-8'"):
        # RFC 5987 section 3.2
        from urllib import unquote
        encoding, _, value = value.split("'", 2)
        return unquote(octoprint.util.to_str(value, encoding="iso-8859-1")).decode(encoding)

    else:
        # no encoding provided, strip potentially present quotes and call it a day
        return octoprint.util.to_unicode(_strip_value_quotes(value), encoding="utf-8")


问题


面经


文章

微信
公众号

扫码关注公众号