a `L!@sdZddlZddlZddlZddlZddlmZmZddlm Z gdZ e e dj ddZd d ZGd d d eZeZd eed<ddZddZddZddZddZeedZddZeedZeedZd ddZdS)!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})cCst|dS)N)bytesfromhexgroupr )mr7/usr/local/src/Python-3.9.6/Lib/email/_encoded_words.pyArcCs|dd}t|gfS)N_ )replace_q_byte_subber)encodedrrrrCs rc@s,eZdZdededZddZdS) _QByteMaps-!*+/asciicCs.||jvrt|||<nd|||<||S)Nz={:02X})safechrformat)selfkeyrrr __missing__Ms z_QByteMap.__missing__N)__name__ __module__ __qualname__rr rrr"rrrrrIsr_ cCsddd|DS)Ncss|]}t|VqdSN) _q_byte_map.0xrrr Zrzencode_q..)joinbstringrrrrYsrcCstdd|DS)Ncss|]}tt|VqdSr))lenr*r+rrrr.]rzlen_q..)sumr0rrrr \sr cCst|d}|r ddd|nd}z&tj||dd|rDtgngfWStjyztj|ddtgfWYStjyz,tj|dddttgfWYYStjy|tgfYYYS0Yn0Yn0dS)Ns===rT)validateFs==) r2base64 b64decoderInvalidBase64PaddingDefectbinasciiErrorInvalidBase64CharactersDefectInvalidBase64LengthDefect)rZpad_errZmissing_paddingrrrrds(   rcCst|dS)Nr)r6 b64encoder r0rrrrsrcCs&tt|d\}}|d|r dndS)Nr4r)divmodr2)r1 groups_of_3leftoverrrrr sr )qbc Cs|d\}}}}}|d\}}}|}|dd}t||\}}z||}Wnrty|t d |||d}Yn@t y|dd}|dkr|t d |Yn0||||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. ?*rsurrogateescapez:Encoded word contains bytes not decodable using {} charset unknown-8bitzs<)   &+