U e5dL!ã@sòdZddlZddlZddlZddlZddlmZmZddlm Z ddddd d d d gZ e  e  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})cCst | d¡ ¡¡S)Né)ÚbytesÚfromhexÚgroupr )Úm©rú,/usr/lib64/python3.8/email/_encoded_words.pyÚAórcCs| dd¡}t|ƒgfS)Nó_ó )ÚreplaceÚ_q_byte_subber)ÚencodedrrrrCs c@s,eZdZde d¡e d¡Zdd„ZdS)Ú _QByteMaps-!*+/ÚasciicCs.||jkrt|ƒ||<nd |¡||<||S)Nz={:02X})ÚsafeÚchrÚformat)ÚselfÚkeyrrrÚ __missing__Ms z_QByteMap.__missing__N)Ú__name__Ú __module__Ú __qualname__rr rrr"rrrrrIsrÚ_ú cCsd dd„|Dƒ¡S)NÚcss|]}t|VqdS©N)Ú _q_byte_map©Ú.0ÚxrrrÚ Zszencode_q..)Újoin©ÚbstringrrrrYscCstdd„|DƒƒS)Ncss|]}tt|ƒVqdSr))Úlenr*r+rrrr.]szlen_q..)Úsumr0rrrr \scCsøt|ƒd}|r ddd|…nd}z&tj||dd�|rDt ¡gngfWStjk �ròztj|dd�t ¡gfWYStjk rìz,tj|ddd�t ¡t ¡gfWYYStjk ræ|t ¡gfYYYSXYnXYnXdS)Nés===rT)ZvalidateFs==) r2Úbase64Z b64decoderZInvalidBase64PaddingDefectÚbinasciiÚErrorZInvalidBase64CharactersDefectZInvalidBase64LengthDefect)rZpad_errZmissing_paddingrrrrds( þ þ ÿþcCst |¡ d¡S)Nr)r5Z b64encoder r0rrrrŠscCs&tt|ƒdƒ\}}|d|r dndS)Nér4r)Údivmodr2)r1Z groups_of_3Zleftoverrrrr �s)ÚqÚbc CsÚ| d¡\}}}}}| d¡\}}}| ¡}| dd¡}t||ƒ\}}z| |¡}Wnvtk rŒ| t  d  |¡¡¡| |d¡}YnBt k rÌ| dd¡}| ¡dkrÈ| t  d  |¡¡¡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 {} charsetú unknown-8bitzNr:r;ér=z=?{}{}?{}?{}?=)r Ú_cte_encode_lengthÚ _cte_encodersr)rIrGÚencodingrHr1ZqlenZblenrrrrr Ìs    )rJNr()Ú__doc__Úrer5r6Ú functoolsrIrrZemailrÚ__all__ÚpartialÚcompileÚsubrrÚdictrr*Úordrr rrr rCr rMrLr rrrrÚsL) ùÿ  &þ+þþ