\d]!4dZddlZddlZddlZddlZddlmZmZddlm Z gdZ ej ej dj dZdZGd d eZeZd eed <d ZdZdZdZdZeedZdZeedZeedZddZdS)z Routines for manipulating RFC2047 encoded words. This is currently a package-private API, but will be considered for promotion to a public API if there is demand. N) ascii_lettersdigits)errors)decode_qencode_qdecode_bencode_blen_qlen_bdecodeencodes=([a-fA-F0-9]{2})ct|dS)N)bytesfromhexgroupr )ms %..\python\lib\email\_encoded_words.pyrAs(%-- 1 1 3 344cP|dd}t|gfS)N_ )replace_q_byte_subber)encodeds rrrCs(oodD))G ' " "B &&rc\eZdZdejdzejdzZdZdS) _QByteMaps-!*+/asciicz||jvrt|||<nd|||<||S)Nz={:02X})safechrformat)selfkeys r __missing__z_QByteMap.__missing__MsA $)  CDII!((--DICyrN)__name__ __module__ __qualname__rr rr!r&rrrrIsL *m*733 3mfmG6L6L LDrr_ c@dd|DS)Nc30K|]}t|VdSN) _q_byte_map.0xs r zencode_q..Zs&33a;q>333333r)joinbstrings rrrYs# 77337333 3 33rc4td|DS)Nc3JK|]}tt|VdSr0)lenr1r2s rr5zlen_q..]s.44qs;q>""444444r)sumr7s rr r \s 44G444 4 44rc8t|dz}|r ddd|z nd} tj||zd|rtjgngfS#t j$r tj|dtjgfcYS#t j$rt tj|dzdtjtjgfcYcYS#t j$r|tjgfcYcYcYSwxYwwxYwwxYw)Ns===rT)validateFs==) r;base64 b64decoderInvalidBase64PaddingDefectbinasciiErrorInvalidBase64CharactersDefectInvalidBase64LengthDefect)rpad_errmissing_paddings rrrds'llQG,3EEE  E 59995778   ~ E E E E$Wu_uEEE9;;688: > E E E !A!C!C DDDDDDDDD  E EEsS0AD&)BDD">C% D!D%%D D DDDDcPtj|dS)Nr)r@ b64encoder r7s rr r s!  G $ $ + +G 4 44rcZtt|d\}}|dz|rdndzS)Nr>r)divmodr;)r8 groups_of_3leftovers rr r s4"3w<<33K ?82aa 33r)qbc|d\}}}}}|d\}}}|}|dd}t ||\}} ||}n#t $rD|tj d|d||d}Ynottf$r\|dd}|dkr+|tj d|d YnwxYw||||fS) aDecode encoded word and return (string, charset, lang, defects) tuple. An RFC 2047/2243 encoded word has the form: =?charset*lang?cte?encoded_string?= where '*lang' may be omitted but the other parts may not be. This function expects exactly such a string (that is, it does not check the syntax and may raise errors if the string is not well formed), and returns the encoded_string decoded first from its Content Transfer Encoding and then from the resulting bytes into unicode using the specified charset. If the cte-decoded string does not successfully decode using the specified character set, a defect is added to the defects list and the unknown octets are replaced by the unicode 'unknown' character \uFDFF. The specified charset and language are returned. The default for language, which is rarely if ever encountered, is the empty string. ?*rsurrogateescapez0Encoded word contains bytes not decodable using z charset unknown-8bitzUnknown charset z* in encoded word; decoded as unknown bytes) split partitionlowerr _cte_decodersr UnicodeDecodeErrorappendrUndecodableBytesDefect LookupErrorUnicodeEncodeError CharsetError) ewr+charsetcte cte_stringlangr8defectsstrings rr r s*&(XXc]]"AwZ((--GQ ))++C):;;G$S)'22GW ?(( <<<v46F296F6F6FGG H H H):;; + ,???):;; ==??n , , NN6.0='0=0=0=>> ? ? ?? 7D' ))s8BA EA)EEutf-8r.c@|dkr|dd}n||}|7td|}td|}||z dkrdnd}t||}|rd|z}d ||||S) aEncode string using the CTE encoding that produces the shorter result. Produces an RFC 2047/2243 encoded word of the form: =?charset*lang?cte?encoded_string?= where '*lang' is omitted unless the 'lang' parameter is given a value. Optional argument charset (defaults to utf-8) specifies the charset to use to encode the string to binary before CTE encoding it. Optional argument 'encoding' is the cte specifier for the encoding that should be used ('q' or 'b'); if it is None (the default) the encoding which produces the shortest encoded sequence is used, except that 'q' is preferred if it is up to five characters longer. Optional argument 'lang' (default '') gives the RFC 2243 language string to specify in the encoded word. rVrrUNrPrQrTz=?{}{}?{}?{}?=)r _cte_encode_length _cte_encodersr#)rgrbencodingrer8qlenblenrs rr r s".  --):;;--((!#&w//!#&w//+//33sH%g..G Tz  " "7D(G D DDr)rhNr.)__doc__rer@rC functoolsrgrremailr__all__partialcompilesubrrdictrr1ordrr rr r rZr rlrkr r*rrrzsR ((((((((   #":2:.C#D#D#H4466'''        ikk  CCHH444555$E$E$EL555444   '*'*'*V     EEEEEEr