Every line of 'python decode utf-8' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
14 def decode(s, encoding=None): 15 encoding = encoding or DEFAULT_ENCODING 16 return s.decode(encoding, "replace")
41 def decode(obj, encoding): 42 if isinstance(obj, bytes): 43 return obj.decode(encoding) 44 elif isinstance(obj, list): 45 return [decode(o, encoding) for o in obj] 46 return obj
8 def decode_utf8(bytes): 9 return bytes.decode('utf-8')
55 def decode(bytes_): 56 """Decode bytes with default locale and return (unicode) string 57 58 No-op if parameter is not bytes (assumed unicode string). 59 60 :param bytes bytes_: the bytes to decode 61 """ 62 if isinstance(bytes_, unicode): 63 return bytes_ 64 if isinstance(bytes_, bytes): 65 enc = _get_encoding() 66 return bytes_.decode(enc) 67 return unicode(bytes_)
22 def decode_utf8(message, errors='strict'): 23 """Wrapper that prints the decoded message if an error occurs.""" 24 try: 25 return message.decode('utf-8', errors=errors) 26 except UnicodeDecodeError as ex: 27 error_message = "{}. Original exception: {} Text: {}".format(unicode(ex), type(ex).__name__, repr(ex.args[1])) 28 raise UnicodeError, UnicodeError(error_message), sys.exc_info()[2]
17 def decode(input, errors='strict'): 18 return codecs.utf_16_decode(input, errors, True)
13 def decode_bytes_to_str(data: Union[bytes, bytearray], encoding: str = 'utf-8', errors: str = 'strict') -> str: 14 return data.split(b'\0', 1)[0].decode(encoding=encoding, errors=errors)
26 def decode(s): 27 return s.decode() if isinstance(s, bytes) else s
58 def decode(s): 59 return s.decode(ENCODING, 'ignore')
15 def decode_string(v, encoding="utf-8"): 16 """ Returns the given value as a Unicode string (if possible). 17 """ 18 if isinstance(encoding, str): 19 encoding = ((encoding,),) + (("windows-1252",), ("utf-8", "ignore")) 20 if isinstance(v, bytes): 21 for e in encoding: 22 try: 23 return v.decode(*e) 24 except: 25 pass 26 return v 27 return str(v)