Python string.decode() Examples
The following are 18
code examples of string.decode().
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 also want to check out all available functions/classes of the module
string
, or try the search function
.
Example #1
Source File: rhodiola.py From rhodiola with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Source File: coders.py From gd.py with MIT License | 5 votes |
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 #3
Source File: crypto.py From PiBunny with MIT License | 5 votes |
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 #4
Source File: lib.py From python-scripts with GNU General Public License v3.0 | 5 votes |
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 #5
Source File: lib.py From python-scripts with GNU General Public License v3.0 | 5 votes |
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 #6
Source File: M_E_T_A_.py From stdm with GNU General Public License v2.0 | 5 votes |
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 #7
Source File: coders.py From gd.py with MIT License | 5 votes |
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 #8
Source File: coders.py From gd.py with MIT License | 5 votes |
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 #9
Source File: coders.py From gd.py with MIT License | 5 votes |
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 #10
Source File: sutils.py From plugin.video.sosac.ph with GNU General Public License v2.0 | 5 votes |
def encode(string): return unicodedata.normalize('NFKD', string.decode('utf-8')).encode('ascii', 'ignore')
Example #11
Source File: coders.py From gd.py with MIT License | 5 votes |
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 #12
Source File: coders.py From gd.py with MIT License | 5 votes |
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 #13
Source File: coders.py From gd.py with MIT License | 5 votes |
def byte_xor(stream: bytes, key: int) -> str: return bytes(byte ^ key for byte in stream).decode(errors="ignore")
Example #14
Source File: pokecli.py From PokemonGo-Bot-Backup with MIT License | 5 votes |
def parse_unicode_str(string): try: return string.decode('utf8') except UnicodeEncodeError: return string
Example #15
Source File: crypto.py From cracke-dit with MIT License | 5 votes |
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 #16
Source File: encryption.py From minikerberos with MIT License | 5 votes |
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 #17
Source File: crypto.py From CVE-2017-7494 with GNU General Public License v3.0 | 5 votes |
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 #18
Source File: pokecli.py From PokemonGo-Bot with MIT License | 5 votes |
def parse_unicode_str(string): try: return string.decode('utf8') except (UnicodeEncodeError, UnicodeDecodeError): return string