3 SÉLj ã@s dZddlZddlZdd„eddƒDƒZded<ded <d ed <d ed <ded<ded<dd„eddƒDƒdd„eddƒDƒdd„eddƒDƒZded<ded <d ed <d ed <ded<ded<dd„ZejdƒZdd„eddƒDƒdd„eddƒDƒZ dd„Z dS)zEncoding related utilities.éNcCsg|] }t|ƒ‘qS©)Úchr)Ú.0Úirrú#/usr/lib/python3.6/text_encoding.pyú %sréz\té z\né z\ré z\'é'z\"é"z\\é\cCsg|] }d|‘qS)z\%03or)rrrrrr/sé cCsg|] }t|ƒ‘qSr)r)rrrrrr0sécCsg|] }d|‘qS)z\%03or)rrrrrr1scsLt|tjƒrtndd„‰|r4dj‡fdd„|DƒƒSdj‡fdd„|DƒƒS)a-Escape a bytes string for use in an ascii protocol buffer. text.encode('string_escape') does not seem to satisfy our needs as it encodes unprintable characters using two-digit hex escapes whereas our C++ unescaping function allows hex escapes to be any length. So, "1".encode('string_escape') ends up being "\x011", which will be decoded in C++ as a single-character string with char code 0x11. Args: text: A byte string to be escaped as_utf8: Specifies if result should be returned in UTF-8 encoding Returns: Escaped string cSs|S)Nr)ÚxrrrÚLszCEscape..Úc3s|]}tˆ|ƒVqdS)N)Ú_cescape_utf8_to_str)rÚc)ÚOrdrrú NszCEscape..c3s|]}tˆ|ƒVqdS)N)Ú_cescape_byte_to_str)rr)rrrrOs)Ú isinstanceÚsixZ string_typesÚordÚjoin)ÚtextZas_utf8r)rrÚCEscape;srz"(\\+)x([0-9a-fA-F])(?![0-9a-fA-F])cCsg|] }t|ƒ‘qSr)r)rrrrrrSscCsg|] }d|‘qS)z\%03or)rrrrrrTscCsPdd„}tj||ƒ}ttkr&|jdƒSdjdd„|Dƒƒ}|jdƒjdƒjd ƒS) zDUnescape a text string with C-style escape sequences to UTF-8 bytes.cSs4t|jdƒƒd@r*|jdƒd|jdƒS|jdƒS)NéZx0ér)ÚlenÚgroup)ÚmrrrÚ ReplaceHexZszCUnescape..ReplaceHexZ string_escapercss|]}tt|ƒVqdS)N)Ú_cescape_highbit_to_strr)rrrrrrgszCUnescape..ÚasciiZunicode_escapeZraw_unicode_escape)Ú_CUNESCAPE_HEXÚsubÚstrÚbytesÚdecoderÚencode)rr$ÚresultrrrÚ CUnescapeWs   r.) Ú__doc__ÚrerÚrangerrrÚcompiler'r%r.rrrrÚs,&