o ,] @s:dZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z dd l Z dd l Z dd l Z dd l Z dd lmZmZdd lmZgd Ze e d jddZddZGdddeZeZdeed<ddZddZddZddZ ddZ!eed Z"d!d"Z#ee d Z$ee!d Z%d'd%d&Z&d S)(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. )unicode_literals)division)absolute_import)bytes)chr)int)strN) ascii_lettersdigits)errors)decode_qencode_qdecode_bencode_blen_qlen_bdecodeencodes=([a-fA-F0-9]{2})cCstt|ddgS)N)rrgroup)mrG/usr/lib/python3/dist-packages/future/backports/email/_encoded_words.pyHsrcCst|dd}t|gfS)N_ )rreplace_q_byte_subber)encodedrrrr Js r c@s0eZdZedededZddZdS) _QByteMaps-!*+/asciicCs4||jvrt|||<||Sd|||<||S)Nz={:02X})saferformat)selfkeyrrr __missing__Ts  z_QByteMap.__missing__N) __name__ __module__ __qualname__rr rr r"r&rrrrr Ps r _ cCstdddt|DS)Ncss|]}t|VqdSN) _q_byte_map.0xrrr aszencode_q..)rjoinrbstringrrrr `sr cCstddt|DS)Ncss|] }tt|VqdSr-)lenr.r/rrrr2dszlen_q..)sumrr4rrrrcsrc Csg}t|d}|r|t|ddd|}n|}ztd|s*tdt ||fWStjynt g}dD])}zt |d||fWYStjt fyi|dkrg|tYq@wt dw) Ns===s^[A-Za-z0-9+/]*={0,2}$zNon-base64 digit found)rr=rzunexpected binascii.Error) r6appendr InvalidBase64PaddingDefectrematchbinasciiErrorbase64 b64decodeInvalidBase64CharactersDefect TypeErrorAssertionError)rdefectspad_errpadded_encodedirrrrks,     rcCst|dS)Nr!)rB b64encoderr4rrrrsrcCs(tt|d\}}|d|rdSdS)Nr:r8r)divmodr6)r5 groups_of_3leftoverrrrrsr)qbc Cst|d\}}}}}|d\}}}|}|dd}t||\}}z||}Wn9tyG|t d |||d}Yn t yf|dd}|dkrd|t d |Ynw||||fS)uDecode 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 ﷿. 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-8bitzrBr@ functoolsrbr r future.backports.emailr __all__partialcompilesubrr dictr r.ordr rrrrrXrrfrerrrrrsL       $  +