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


Python str.encode方法代码示例

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


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

示例1: _encode_result

# 需要导入模块: from future.builtins import str [as 别名]
# 或者: from future.builtins.str import encode [as 别名]
def _encode_result(obj, encoding=_implicit_encoding,
                        errors=_implicit_errors):
    return obj.encode(encoding, errors) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:5,代码来源:parse.py

示例2: encode

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

示例3: geturl

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

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

示例4: unquote_to_bytes

# 需要导入模块: from future.builtins import str [as 别名]
# 或者: from future.builtins.str import encode [as 别名]
def unquote_to_bytes(string):
    """unquote_to_bytes('abc%20def') -> b'abc def'."""
    # Note: strings are encoded as UTF-8. This is only an issue if it contains
    # unescaped non-ASCII characters, which URIs should not.
    if not string:
        # Is it a string-like object?
        string.split
        return bytes(b'')
    if isinstance(string, str):
        string = string.encode('utf-8')
    ### For Python-Future:
    # It is already a byte-string object, but force it to be newbytes here on
    # Py2:
    string = bytes(string)
    ###
    bits = string.split(b'%')
    if len(bits) == 1:
        return string
    res = [bits[0]]
    append = res.append
    for item in bits[1:]:
        try:
            append(_hextobyte[item[:2]])
            append(item[2:])
        except KeyError:
            append(b'%')
            append(item)
    return bytes(b'').join(res) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:30,代码来源:parse.py

示例5: to_bytes

# 需要导入模块: from future.builtins import str [as 别名]
# 或者: from future.builtins.str import encode [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

示例6: quote_from_bytes

# 需要导入模块: from future.builtins import str [as 别名]
# 或者: from future.builtins.str import encode [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.str.encode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。