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


Python string.decode方法代码示例

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


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

示例1: find_noun_phrases

# 需要导入模块: import string [as 别名]
# 或者: from string import decode [as 别名]
def find_noun_phrases(string):
    noun_counts = {}
    try:
        blob = TextBlob(string.decode('utf-8'))
    except:
        print "Error occured"
        return None 
    if blob.detect_language() != "en":
        print "Tweets are not in English"
        sys.exit(1)
    else:   
        for noun in blob.noun_phrases:
            if noun in stopwords.words('english') or noun in extra_stopwords or noun == '' or len(noun) < 3:
                pass
            else:   
                noun_counts[noun.lower()] = blob.words.count(noun)
    sorted_noun_counts = sorted(noun_counts.items(), key=operator.itemgetter(1),reverse=True)
    return sorted_noun_counts[0:15] 
开发者ID:utkusen,项目名称:rhodiola,代码行数:20,代码来源:rhodiola.py

示例2: encode

# 需要导入模块: import string [as 别名]
# 或者: from string import decode [as 别名]
def encode(string):
        return unicodedata.normalize('NFKD', string.decode('utf-8')).encode('ascii', 'ignore') 
开发者ID:kodi-czsk,项目名称:plugin.video.sosac.ph,代码行数:4,代码来源:sutils.py

示例3: parse_unicode_str

# 需要导入模块: import string [as 别名]
# 或者: from string import decode [as 别名]
def parse_unicode_str(string):
    try:
        return string.decode('utf8')
    except (UnicodeEncodeError, UnicodeDecodeError):
        return string 
开发者ID:PokemonGoF,项目名称:PokemonGo-Bot,代码行数:7,代码来源:pokecli.py

示例4: string_to_key

# 需要导入模块: import string [as 别名]
# 或者: from string import decode [as 别名]
def string_to_key(cls, string, salt, params):
        utf16string = string.decode('UTF-8').encode('UTF-16LE')
        return Key(cls.enctype, MD4.new(utf16string).digest()) 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:5,代码来源:crypto.py

示例5: string_to_key

# 需要导入模块: import string [as 别名]
# 或者: from string import decode [as 别名]
def string_to_key(cls, string, salt, params):
		utf16string = string.decode('UTF-8').encode('UTF-16LE')
		return Key(cls.enctype, hashlib.new('md4', utf16string).digest()) 
开发者ID:skelsec,项目名称:minikerberos,代码行数:5,代码来源:encryption.py

示例6: parse_unicode_str

# 需要导入模块: import string [as 别名]
# 或者: from string import decode [as 别名]
def parse_unicode_str(string):
    try:
        return string.decode('utf8')
    except UnicodeEncodeError:
        return string 
开发者ID:PokemonGoF,项目名称:PokemonGo-Bot-Backup,代码行数:7,代码来源:pokecli.py

示例7: byte_xor

# 需要导入模块: import string [as 别名]
# 或者: from string import decode [as 别名]
def byte_xor(stream: bytes, key: int) -> str:
        return bytes(byte ^ key for byte in stream).decode(errors="ignore") 
开发者ID:NeKitDS,项目名称:gd.py,代码行数:4,代码来源:coders.py

示例8: decode_save

# 需要导入模块: import string [as 别名]
# 或者: from string import decode [as 别名]
def decode_save(cls, save: Union[bytes, str], needs_xor: bool = True) -> str:
        if isinstance(save, str):
            save = save.encode()

        if needs_xor:
            save = cls.byte_xor(save, 11)

        save += "=" * (4 - len(save) % 4)

        return inflate(urlsafe_b64decode(save.encode())).decode(errors="ignore") 
开发者ID:NeKitDS,项目名称:gd.py,代码行数:12,代码来源:coders.py

示例9: decode_mac_save

# 需要导入模块: import string [as 别名]
# 或者: from string import decode [as 别名]
def decode_mac_save(cls, save: Union[bytes, str], *args, **kwargs) -> str:
        if isinstance(save, str):
            save = save.encode()

        data = cls.cipher.decrypt(save)

        last = data[-1]
        if last < 16:
            data = data[:-last]

        return data.decode(errors="ignore") 
开发者ID:NeKitDS,项目名称:gd.py,代码行数:13,代码来源:coders.py

示例10: encode_save

# 需要导入模块: import string [as 别名]
# 或者: from string import decode [as 别名]
def encode_save(cls, save: Union[bytes, str], needs_xor: bool = True) -> str:
        if isinstance(save, str):
            save = save.encode()

        final = urlsafe_b64encode(deflate(save))

        if needs_xor:
            final = cls.byte_xor(final, 11)
        else:
            final = final.decode()

        return final 
开发者ID:NeKitDS,项目名称:gd.py,代码行数:14,代码来源:coders.py

示例11: do_base64

# 需要导入模块: import string [as 别名]
# 或者: from string import decode [as 别名]
def do_base64(
        cls, data: str, encode: bool = True, errors: str = "strict", safe: bool = True
    ) -> str:
        try:
            if encode:
                return urlsafe_b64encode(data.encode(errors=errors)).decode(errors=errors)
            else:
                padded = data + ("=" * (4 - len(data) % 4))
                return urlsafe_b64decode(padded.encode(errors=errors)).decode(errors=errors)

        except Exception:
            if safe:
                return data
            raise 
开发者ID:NeKitDS,项目名称:gd.py,代码行数:16,代码来源:coders.py

示例12: unzip

# 需要导入模块: import string [as 别名]
# 或者: from string import decode [as 别名]
def unzip(cls, string: Union[bytes, str]) -> Union[bytes, str]:
        """Decompresses a level string.

        Used to unzip level data.

        Parameters
        ----------
        string: Union[:class:`bytes`, :class:`str`]
            String to unzip, encoded in Base64.

        Returns
        -------
        Union[:class:`bytes`, :class:`str`]
            Unzipped level data, as a stream.
        """
        if isinstance(string, str):
            string = string.encode()

        unzipped = inflate(urlsafe_b64decode(string))

        try:
            final = unzipped.decode()
        except UnicodeDecodeError:
            final = unzipped

        return final 
开发者ID:NeKitDS,项目名称:gd.py,代码行数:28,代码来源:coders.py

示例13: zip

# 需要导入模块: import string [as 别名]
# 或者: from string import decode [as 别名]
def zip(cls, string: Union[bytes, str], append_semicolon: bool = True) -> str:
        if isinstance(string, bytes):
            string = string.decode(errors="ignore")

        if append_semicolon and not string.endswith(";"):
            string += ";"

        return cls.encode_save(string, needs_xor=False) 
开发者ID:NeKitDS,项目名称:gd.py,代码行数:10,代码来源:coders.py

示例14: mapUTF8toXML

# 需要导入模块: import string [as 别名]
# 或者: from string import decode [as 别名]
def mapUTF8toXML(string):
	uString = string.decode('utf8')
	string = ""
	for uChar in uString:
		i = ord(uChar)
		if (i < 0x80) and (i > 0x1F):
			string = string + chr(i)
		else:
			string = string + "&#x" + hex(i)[2:] + ";"
	return string 
开发者ID:gltn,项目名称:stdm,代码行数:12,代码来源:M_E_T_A_.py

示例15: _floatconstants

# 需要导入模块: import string [as 别名]
# 或者: from string import decode [as 别名]
def _floatconstants():
    _BYTES = '7FF80000000000007FF0000000000000'.decode('hex')
    if sys.byteorder != 'big':
        _BYTES = _BYTES[:8][::-1] + _BYTES[8:][::-1]
    nan, inf = struct.unpack('dd', _BYTES)
    return nan, inf, -inf 
开发者ID:soarpenguin,项目名称:python-scripts,代码行数:8,代码来源:lib.py


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