3 \F!ã@sòdZddlZddlZddlZddlZddlmZmZddlm Z ddddd d d d gZ ej ej d ƒj dd„ƒZdd„ZGdd„deƒZeƒZdeedƒ<dd„Zdd „Zdd„Zdd„Zdd „ZeedœZdd „ZeedœZeedœZddd „ZdS) 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_lettersÚdigits)ÚerrorsÚdecode_qÚencode_qÚdecode_bÚencode_bÚlen_qÚlen_bÚdecodeÚencodes=([a-fA-F0-9]{2})cCstt|jdƒdƒgƒS)Néé)ÚbytesÚintÚgroup)Úm©rú,/usr/lib64/python3.6/email/_encoded_words.pyÚAsrcCs|jddƒ}t|ƒgfS)Nó_ó )ÚreplaceÚ_q_byte_subber)ÚencodedrrrrCs c@s,eZdZdejdƒejdƒZdd„ZdS)Ú _QByteMaps-!*+/ÚasciicCs.||jkrt|ƒ||<ndj|ƒ||<||S)Nz={:02X})ÚsafeÚchrÚformat)ÚselfÚkeyrrrÚ __missing__Ms z_QByteMap.__missing__N)Ú__name__Ú __module__Ú __qualname__rr rrr"rrrrrIsrÚ_ú cCsdjdd„|DƒƒS)NÚcss|]}t|VqdS)N)Ú _q_byte_map)Ú.0Úxrrrú Zszencode_q..)Újoin)ÚbstringrrrrYscCstdd„|DƒƒS)Ncss|]}tt|ƒVqdS)N)Úlenr))r*r+rrrr,]szlen_q..)Úsum)r.rrrr \scCsØt|ƒd}|r ddd|…nd}y$tj||dd�|rDtjƒgngfStjk rÒytj|dd�tjƒgfStjk rÌy"tj|ddd�tjƒtjƒgfStjk rÆ|tjƒgfSXYnXYnXdS)Nés===óT)ZvalidateFs==) r/Úbase64Z b64decoderZInvalidBase64PaddingDefectÚbinasciiÚErrorZInvalidBase64CharactersDefectZInvalidBase64LengthDefect)rZpad_errZmissing_paddingrrrrds     cCstj|ƒjdƒS)Nr)r3Z b64encoder )r.rrrrŠscCs&tt|ƒdƒ\}}|d|r dndS)Nér1r)Údivmodr/)r.Z groups_of_3Zleftoverrrrr �s)ÚqÚbc CsÚ|jdƒ\}}}}}|jdƒ\}}}|jƒ}|jddƒ}t||ƒ\}}y|j|ƒ}Wnvtk rŒ|jtj dj |ƒƒƒ|j|dƒ}YnBt k rÌ|jddƒ}|jƒdkrÈ|jtj dj |ƒƒƒYnX||||fS)a�Decode 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. ú?Ú*rÚsurrogateescapez:Encoded word contains bytes not decodable using {} charsetz unknown-8bitzsB$    &+