3 \F!@sddlZddlZddlZddlZddlmZmZddlmZdddddd d d gZ ej ej d j d dZ ddZGdddeZeZdeed<ddZddZddZddZdd ZeedZdd ZeedZeedZddd ZdS)N) ascii_lettersdigits)errorsdecode_qencode_qdecode_bencode_blen_qlen_bdecodeencodes=([a-fA-F0-9]{2})cCstt|jddgS)N)bytesintgroup)mr,/usr/lib64/python3.6/email/_encoded_words.pyAsrcCs|jdd}t|gfS)N_ )replace_q_byte_subber)encodedrrrrCs c@s,eZdZdejdejdZddZdS) _QByteMaps-!*+/asciicCs.||jkrt|||<ndj|||<||S)Nz={:02X})safechrformat)selfkeyrrr __missing__Ms z_QByteMap.__missing__N)__name__ __module__ __qualname__rr rrr"rrrrrIsr_ cCsdjdd|DS)Ncss|]}t|VqdS)N) _q_byte_map).0xrrr Zszencode_q..)join)bstringrrrrYscCstdd|DS)Ncss|]}tt|VqdS)N)lenr))r*r+rrrr,]szlen_q..)sum)r.rrrr \scCst|d}|r ddd|nd}y$tj||dd|rDtjgngfStjk rytj|ddtjgfStjk ry"tj|dddtjtjgfStjk r|tjgfSXYnXYnXdS)Ns===T)ZvalidateFs==) r/base64Z b64decoderZInvalidBase64PaddingDefectbinasciiErrorZInvalidBase64CharactersDefectZInvalidBase64LengthDefect)rZpad_errZmissing_paddingrrrrds     cCstj|jdS)Nr)r3Z b64encoder )r.rrrrscCs&tt|d\}}|d|r dndS)Nr1r)divmodr/)r.Z groups_of_3Zleftoverrrrr s)qbc Cs|jd\}}}}}|jd\}}}|j}|jdd}t||\}}y|j|}Wnvtk r|jtj dj ||j|d}YnBt k r|jdd}|jdkr|jtj dj |YnX||||fS)N?*rsurrogateescapez:Encoded word contains bytes not decodable using {} charsetz unknown-8bitz*s@    &+