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,&