Every line of 'ascii to string python' 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.
9 def from_unicode_to_ascii(string): 10 if isinstance(string, str): 11 return string 12 if string is None: 13 return "" 14 return unicodedata.normalize("NFKD", string).encode("ascii", "ignore")
68 def to_bytestring(ascii_): 69 """ 70 Convert an iterable of integers into a bytestring. 71 72 :param iterable ascii_: Iterable of integers 73 :return: bytestring 74 """ 75 return b("".join(chr(a) for a in ascii_))
110 def unicodeToAscii(s): 111 return ''.join(c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn')
82 def utoascii(text): 83 """ 84 Convert unicode text into ascii and escape quotes and backslashes. 85 """ 86 if text is None: 87 return '' 88 out = text.encode('ascii', 'replace') 89 # swig will require us to replace blackslash with 4 backslashes 90 out = out.replace(b'\\', b'\\\\\\\\') 91 out = out.replace(b'"', b'\\"').decode('ascii') 92 return str(out)
201 def _string_ascii(translator, expr): 202 (arg,) = expr.op().args 203 return 'TO_CODE_POINTS({})[SAFE_OFFSET(0)]'.format( 204 translator.translate(arg) 205 )
278 @__builtin__ 279 def ascii_encode(string, errors=None): 280 return __truffle_encode(string, "ascii", errors)
26 def ascii_escape(c, is_unicode): 27 if c == '"': 28 return '\\"' 29 elif c == '\\': 30 return '\\\\' 31 elif c == '\b': 32 return '\\b' 33 elif c == '\f': 34 return '\\f' 35 elif c == '\n': 36 return '\\n' 37 elif c == '\r': 38 return '\\r' 39 elif c == '\t': 40 return '\\t' 41 ordc = ord(c) 42 if ordc < 0x7f: 43 return '\\u00%02x' % (ordc,) 44 elif not is_unicode: 45 raise NeedsUTF8Decoding 46 elif ordc < 0x10000: 47 return '\\u%04x' % (ordc,) 48 # surrogate pair 49 ordc -= 0x10000 50 s1 = 0xd800 | ((ordc >> 10) & 0x3ff) 51 s2 = 0xdc00 | (ordc & 0x3ff) 52 return '\\u%04x\\u%04x' % (s1, s2)
126 def to_ascii_utf8(string): 127 """Convert non-ascii character in a utf-8 encoded string to ascii""" 128 string = string.decode('utf-8') 129 for char in string: 130 if char in LATIN_DICT: 131 string = string.replace(char, LATIN_DICT[char]) 132 return string.encode('utf-8')