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


Python escape._unicode方法代码示例

本文整理汇总了Python中tornado.escape._unicode方法的典型用法代码示例。如果您正苦于以下问题:Python escape._unicode方法的具体用法?Python escape._unicode怎么用?Python escape._unicode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tornado.escape的用法示例。


在下文中一共展示了escape._unicode方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: decode_argument

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import _unicode [as 别名]
def decode_argument(self, value, name=None):
        """从请求中解码一个参数.

        这个参数已经被解码现在是一个字节字符串(byte string). 默认情况下,
        这个方法会把参数解码成utf-8并且返回一个unicode字符串, 但是它可以
        被子类复写.

        这个方法既可以在 `get_argument()` 中被用作过滤器, 也可以用来从url
        中提取值并传递给 `get()`/`post()`/等.

        如果知道的话参数的name会被提供, 但也可能为None
        (e.g. 在url正则表达式中未命名的组).
        """
        try:
            return _unicode(value)
        except UnicodeDecodeError:
            raise HTTPError(400, "Invalid unicode in %s: %r" %
                            (name or "url", value[:40])) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:20,代码来源:web.py

示例2: decode_argument

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import _unicode [as 别名]
def decode_argument(self, value: bytes, name: str = None) -> str:
        """Decodes an argument from the request.

        The argument has been percent-decoded and is now a byte string.
        By default, this method decodes the argument as utf-8 and returns
        a unicode string, but this may be overridden in subclasses.

        This method is used as a filter for both `get_argument()` and for
        values extracted from the url and passed to `get()`/`post()`/etc.

        The name of the argument is provided if known, but may be None
        (e.g. for unnamed groups in the url regex).
        """
        try:
            return _unicode(value)
        except UnicodeDecodeError:
            raise HTTPError(
                400, "Invalid unicode in %s: %r" % (name or "url", value[:40])
            ) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:21,代码来源:web.py

示例3: transform_first_chunk

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import _unicode [as 别名]
def transform_first_chunk(self, status_code, headers, chunk, finishing):
        if 'Vary' in headers:
            headers['Vary'] += b', Accept-Encoding'
        else:
            headers['Vary'] = b'Accept-Encoding'
        if self._gzipping:
            ctype = _unicode(headers.get("Content-Type", "")).split(";")[0]
            self._gzipping = (ctype in self.CONTENT_TYPES) and \
                (not finishing or len(chunk) >= self.MIN_LENGTH) and \
                (finishing or "Content-Length" not in headers) and \
                ("Content-Encoding" not in headers)
        if self._gzipping:
            headers["Content-Encoding"] = "gzip"
            self._gzip_value = BytesIO()
            self._gzip_file = gzip.GzipFile(mode="w", fileobj=self._gzip_value)
            chunk = self.transform_chunk(chunk, finishing)
            if "Content-Length" in headers:
                headers["Content-Length"] = str(len(chunk))
        return status_code, headers, chunk 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:21,代码来源:web.py

示例4: decode_argument

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import _unicode [as 别名]
def decode_argument(self, value, name=None):
        """Decodes an argument from the request.

        The argument has been percent-decoded and is now a byte string.
        By default, this method decodes the argument as utf-8 and returns
        a unicode string, but this may be overridden in subclasses.

        This method is used as a filter for both `get_argument()` and for
        values extracted from the url and passed to `get()`/`post()`/etc.

        The name of the argument is provided if known, but may be None
        (e.g. for unnamed groups in the url regex).
        """
        try:
            return _unicode(value)
        except UnicodeDecodeError:
            raise HTTPError(400, "Invalid unicode in %s: %r" %
                            (name or "url", value[:40])) 
开发者ID:tp4a,项目名称:teleport,代码行数:20,代码来源:web.py

示例5: transform_first_chunk

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import _unicode [as 别名]
def transform_first_chunk(self, status_code, headers, chunk, finishing):
        if 'Vary' in headers:
            headers['Vary'] += b', Accept-Encoding'
        else:
            headers['Vary'] = b'Accept-Encoding'
        if self._gzipping:
            ctype = _unicode(headers.get("Content-Type", "")).split(";")[0]
            self._gzipping = self._compressible_type(ctype) and \
                (not finishing or len(chunk) >= self.MIN_LENGTH) and \
                ("Content-Encoding" not in headers)
        if self._gzipping:
            headers["Content-Encoding"] = "gzip"
            self._gzip_value = BytesIO()
            self._gzip_file = gzip.GzipFile(mode="w", fileobj=self._gzip_value,
                                            compresslevel=self.GZIP_LEVEL)
            chunk = self.transform_chunk(chunk, finishing)
            if "Content-Length" in headers:
                # The original content length is no longer correct.
                # If this is the last (and only) chunk, we can set the new
                # content-length; otherwise we remove it and fall back to
                # chunked encoding.
                if finishing:
                    headers["Content-Length"] = str(len(chunk))
                else:
                    del headers["Content-Length"]
        return status_code, headers, chunk 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:28,代码来源:web.py

示例6: _safe_unicode

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import _unicode [as 别名]
def _safe_unicode(s):
    try:
        return _unicode(s)
    except UnicodeDecodeError:
        return repr(s) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:7,代码来源:log.py

示例7: _parse_string

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import _unicode [as 别名]
def _parse_string(self, value):
        return _unicode(value) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:4,代码来源:options.py

示例8: transform_first_chunk

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import _unicode [as 别名]
def transform_first_chunk(
        self,
        status_code: int,
        headers: httputil.HTTPHeaders,
        chunk: bytes,
        finishing: bool,
    ) -> Tuple[int, httputil.HTTPHeaders, bytes]:
        # TODO: can/should this type be inherited from the superclass?
        if "Vary" in headers:
            headers["Vary"] += ", Accept-Encoding"
        else:
            headers["Vary"] = "Accept-Encoding"
        if self._gzipping:
            ctype = _unicode(headers.get("Content-Type", "")).split(";")[0]
            self._gzipping = (
                self._compressible_type(ctype)
                and (not finishing or len(chunk) >= self.MIN_LENGTH)
                and ("Content-Encoding" not in headers)
            )
        if self._gzipping:
            headers["Content-Encoding"] = "gzip"
            self._gzip_value = BytesIO()
            self._gzip_file = gzip.GzipFile(
                mode="w", fileobj=self._gzip_value, compresslevel=self.GZIP_LEVEL
            )
            chunk = self.transform_chunk(chunk, finishing)
            if "Content-Length" in headers:
                # The original content length is no longer correct.
                # If this is the last (and only) chunk, we can set the new
                # content-length; otherwise we remove it and fall back to
                # chunked encoding.
                if finishing:
                    headers["Content-Length"] = str(len(chunk))
                else:
                    del headers["Content-Length"]
        return status_code, headers, chunk 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:38,代码来源:web.py

示例9: _safe_unicode

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import _unicode [as 别名]
def _safe_unicode(s: Any) -> str:
    try:
        return _unicode(s)
    except UnicodeDecodeError:
        return repr(s) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:7,代码来源:log.py

示例10: _parse_string

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import _unicode [as 别名]
def _parse_string(self, value: str) -> str:
        return _unicode(value) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:4,代码来源:options.py

示例11: decode_argument

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import _unicode [as 别名]
def decode_argument(self, value, name=None):
        """Decodes an argument from the request.

        The argument has been percent-decoded and is now a byte string.
        By default, this method decodes the argument as utf-8 and returns
        a unicode string, but this may be overridden in subclasses.

        This method is used as a filter for both `get_argument()` and for
        values extracted from the url and passed to `get()`/`post()`/etc.

        The name of the argument is provided if known, but may be None
        (e.g. for unnamed groups in the url regex).
        """
        return _unicode(value) 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:16,代码来源:web.py

示例12: transform_first_chunk

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import _unicode [as 别名]
def transform_first_chunk(self, status_code, headers, chunk, finishing):
        # type: (int, httputil.HTTPHeaders, bytes, bool) -> typing.Tuple[int, httputil.HTTPHeaders, bytes] # noqa: E501
        # TODO: can/should this type be inherited from the superclass?
        if 'Vary' in headers:
            headers['Vary'] += ', Accept-Encoding'
        else:
            headers['Vary'] = 'Accept-Encoding'
        if self._gzipping:
            ctype = _unicode(headers.get("Content-Type", "")).split(";")[0]
            self._gzipping = self._compressible_type(ctype) and \
                (not finishing or len(chunk) >= self.MIN_LENGTH) and \
                ("Content-Encoding" not in headers)
        if self._gzipping:
            headers["Content-Encoding"] = "gzip"
            self._gzip_value = BytesIO()
            self._gzip_file = gzip.GzipFile(mode="w", fileobj=self._gzip_value,
                                            compresslevel=self.GZIP_LEVEL)
            chunk = self.transform_chunk(chunk, finishing)
            if "Content-Length" in headers:
                # The original content length is no longer correct.
                # If this is the last (and only) chunk, we can set the new
                # content-length; otherwise we remove it and fall back to
                # chunked encoding.
                if finishing:
                    headers["Content-Length"] = str(len(chunk))
                else:
                    del headers["Content-Length"]
        return status_code, headers, chunk 
开发者ID:tp4a,项目名称:teleport,代码行数:30,代码来源:web.py

示例13: post

# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import _unicode [as 别名]
def post(self):
        self.finish({"header": self.request.headers["X-Header-Encoding-Test"],
                     "argument": self.get_argument("argument"),
                     "filename": self.request.files["files"][0].filename,
                     "filebody": _unicode(self.request.files["files"][0]["body"]),
                     })


# This test is also called from wsgi_test 
开发者ID:tp4a,项目名称:teleport,代码行数:11,代码来源:httpserver_test.py


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