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


Python bytes.decode方法代码示例

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


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

示例1: _coerce_args

# 需要导入模块: from future.builtins import bytes [as 别名]
# 或者: from future.builtins.bytes import decode [as 别名]
def _coerce_args(*args):
    # Invokes decode if necessary to create str args
    # and returns the coerced inputs along with
    # an appropriate result coercion function
    #   - noop for str inputs
    #   - encoding function otherwise
    str_input = isinstance(args[0], str)
    for arg in args[1:]:
        # We special-case the empty string to support the
        # "scheme=''" default argument to some functions
        if arg and isinstance(arg, str) != str_input:
            raise TypeError("Cannot mix str and non-str arguments")
    if str_input:
        return args + (_noop,)
    return _decode_args(args) + (_encode_result,)

# Result objects are more helpful than simple tuples 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:19,代码来源:parse.py

示例2: unquote

# 需要导入模块: from future.builtins import bytes [as 别名]
# 或者: from future.builtins.bytes import decode [as 别名]
def unquote(string, encoding='utf-8', errors='replace'):
    """Replace %xx escapes by their single-character equivalent. The optional
    encoding and errors parameters specify how to decode percent-encoded
    sequences into Unicode characters, as accepted by the bytes.decode()
    method.
    By default, percent-encoded sequences are decoded with UTF-8, and invalid
    sequences are replaced by a placeholder character.

    unquote('abc%20def') -> 'abc def'.
    """
    if '%' not in string:
        string.split
        return string
    if encoding is None:
        encoding = 'utf-8'
    if errors is None:
        errors = 'replace'
    bits = _asciire.split(string)
    res = [bits[0]]
    append = res.append
    for i in range(1, len(bits), 2):
        append(unquote_to_bytes(bits[i]).decode(encoding, errors))
        append(bits[i + 1])
    return ''.join(res) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:26,代码来源:parse.py

示例3: _decode_args

# 需要导入模块: from future.builtins import bytes [as 别名]
# 或者: from future.builtins.bytes import decode [as 别名]
def _decode_args(args, encoding=_implicit_encoding,
                       errors=_implicit_errors):
    return tuple(x.decode(encoding, errors) if x else '' for x in args) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:5,代码来源:parse.py

示例4: decode

# 需要导入模块: from future.builtins import bytes [as 别名]
# 或者: from future.builtins.bytes import decode [as 别名]
def decode(self, encoding='ascii', errors='strict'):
        return self._decoded_counterpart(*(x.decode(encoding, errors) for x in self)) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:4,代码来源:parse.py

示例5: geturl

# 需要导入模块: from future.builtins import bytes [as 别名]
# 或者: from future.builtins.bytes import decode [as 别名]
def geturl(self):
        return urlunparse(self)

# Set up the encode/decode result pairs 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:6,代码来源:parse.py

示例6: quote_from_bytes

# 需要导入模块: from future.builtins import bytes [as 别名]
# 或者: from future.builtins.bytes import decode [as 别名]
def quote_from_bytes(bs, safe='/'):
    """Like quote(), but accepts a bytes object rather than a str, and does
    not perform string-to-bytes encoding.  It always returns an ASCII string.
    quote_from_bytes(b'abc def\x3f') -> 'abc%20def%3f'
    """
    if not isinstance(bs, (bytes, bytearray)):
        raise TypeError("quote_from_bytes() expected bytes")
    if not bs:
        return str('')
    ### For Python-Future:
    bs = bytes(bs)
    ### 
    if isinstance(safe, str):
        # Normalize 'safe' by converting to bytes and removing non-ASCII chars
        safe = str(safe).encode('ascii', 'ignore')
    else:
        ### For Python-Future:
        safe = bytes(safe)
        ### 
        safe = bytes([c for c in safe if c < 128])
    if not bs.rstrip(_ALWAYS_SAFE_BYTES + safe):
        return bs.decode()
    try:
        quoter = _safe_quoters[safe]
    except KeyError:
        _safe_quoters[safe] = quoter = Quoter(safe).__getitem__
    return str('').join([quoter(char) for char in bs]) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:29,代码来源:parse.py

示例7: to_bytes

# 需要导入模块: from future.builtins import bytes [as 别名]
# 或者: from future.builtins.bytes import decode [as 别名]
def to_bytes(url):
    """to_bytes(u"URL") --> 'URL'."""
    # Most URL schemes require ASCII. If that changes, the conversion
    # can be relaxed.
    # XXX get rid of to_bytes()
    if isinstance(url, str):
        try:
            url = url.encode("ASCII").decode()
        except UnicodeError:
            raise UnicodeError("URL " + repr(url) +
                               " contains non-ASCII characters")
    return url 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:14,代码来源:parse.py

示例8: quote_from_bytes

# 需要导入模块: from future.builtins import bytes [as 别名]
# 或者: from future.builtins.bytes import decode [as 别名]
def quote_from_bytes(bs, safe='/'):
    """Like quote(), but accepts a bytes object rather than a str, and does
    not perform string-to-bytes encoding.  It always returns an ASCII string.
    quote_from_bytes(b'abc def\x3f') -> 'abc%20def%3f'
    """
    if not isinstance(bs, (bytes, bytearray)):
        raise TypeError("quote_from_bytes() expected bytes")
    if not bs:
        return str('')
    ### For Python-Future:
    bs = bytes(bs)
    ###
    if isinstance(safe, str):
        # Normalize 'safe' by converting to bytes and removing non-ASCII chars
        safe = str(safe).encode('ascii', 'ignore')
    else:
        ### For Python-Future:
        safe = bytes(safe)
        ###
        safe = bytes([c for c in safe if c < 128])
    if not bs.rstrip(_ALWAYS_SAFE_BYTES + safe):
        return bs.decode()
    try:
        quoter = _safe_quoters[safe]
    except KeyError:
        _safe_quoters[safe] = quoter = Quoter(safe).__getitem__
    return str('').join([quoter(char) for char in bs]) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:29,代码来源:parse.py


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