Python string.decode() Examples

The following are 18 code examples for showing how to use string.decode(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module string , or try the search function .

Example 1
Project: rhodiola   Author: utkusen   File: rhodiola.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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] 
Example 2
Project: plugin.video.sosac.ph   Author: kodi-czsk   File: sutils.py    License: GNU General Public License v2.0 5 votes vote down vote up
def encode(string):
        return unicodedata.normalize('NFKD', string.decode('utf-8')).encode('ascii', 'ignore') 
Example 3
Project: PokemonGo-Bot   Author: PokemonGoF   File: pokecli.py    License: MIT License 5 votes vote down vote up
def parse_unicode_str(string):
    try:
        return string.decode('utf8')
    except (UnicodeEncodeError, UnicodeDecodeError):
        return string 
Example 4
Project: CVE-2017-7494   Author: joxeankoret   File: crypto.py    License: GNU General Public License v3.0 5 votes vote down vote up
def string_to_key(cls, string, salt, params):
        utf16string = string.decode('UTF-8').encode('UTF-16LE')
        return Key(cls.enctype, MD4.new(utf16string).digest()) 
Example 5
Project: minikerberos   Author: skelsec   File: encryption.py    License: MIT License 5 votes vote down vote up
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()) 
Example 6
Project: cracke-dit   Author: eth0izzle   File: crypto.py    License: MIT License 5 votes vote down vote up
def string_to_key(cls, string, salt, params):
        utf16string = string.decode('UTF-8').encode('UTF-16LE')
        return Key(cls.enctype, MD4.new(utf16string).digest()) 
Example 7
Project: PokemonGo-Bot-Backup   Author: PokemonGoF   File: pokecli.py    License: MIT License 5 votes vote down vote up
def parse_unicode_str(string):
    try:
        return string.decode('utf8')
    except UnicodeEncodeError:
        return string 
Example 8
Project: gd.py   Author: NeKitDS   File: coders.py    License: MIT License 5 votes vote down vote up
def byte_xor(stream: bytes, key: int) -> str:
        return bytes(byte ^ key for byte in stream).decode(errors="ignore") 
Example 9
Project: gd.py   Author: NeKitDS   File: coders.py    License: MIT License 5 votes vote down vote up
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") 
Example 10
Project: gd.py   Author: NeKitDS   File: coders.py    License: MIT License 5 votes vote down vote up
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") 
Example 11
Project: gd.py   Author: NeKitDS   File: coders.py    License: MIT License 5 votes vote down vote up
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 
Example 12
Project: gd.py   Author: NeKitDS   File: coders.py    License: MIT License 5 votes vote down vote up
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 
Example 13
Project: gd.py   Author: NeKitDS   File: coders.py    License: MIT License 5 votes vote down vote up
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 
Example 14
Project: gd.py   Author: NeKitDS   File: coders.py    License: MIT License 5 votes vote down vote up
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) 
Example 15
Project: stdm   Author: gltn   File: M_E_T_A_.py    License: GNU General Public License v2.0 5 votes vote down vote up
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 
Example 16
Project: python-scripts   Author: soarpenguin   File: lib.py    License: GNU General Public License v3.0 5 votes vote down vote up
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 
Example 17
Project: python-scripts   Author: soarpenguin   File: lib.py    License: GNU General Public License v3.0 5 votes vote down vote up
def to_native_string(string, encoding='ascii'):
    """
        Given a string object, regardless of type, returns a representation of that
        string in the native string type, encoding and decoding where necessary.
        This assumes ASCII unless told otherwise.
    """
    out = None
    if isinstance(string, builtin_str):
        out = string
    else:
        if is_py2:
            out = string.encode(encoding)
        else:
            out = string.decode(encoding)
    return out 
Example 18
Project: PiBunny   Author: tholum   File: crypto.py    License: MIT License 5 votes vote down vote up
def string_to_key(cls, string, salt, params):
        utf16string = string.decode('UTF-8').encode('UTF-16LE')
        return Key(cls.enctype, MD4.new(utf16string).digest())