a 97a*@s~dZddlmZddlmZddlmZddlmZmZmZm Z m Z m Z gdZ ddl Z ddlZddlmZmZmZd Zd Zd Zed d e dDZeZedededD]Zeeee<qdeed<edD]Zeeee<qddZddZddZddZd0ddZ ddZ!d d!Z"d1d#d$Z#Gd%d&d&ej$Z%d'efd(d)Z&efd*d+Z'e'Z(e'Z)d,d-Z*d.d/Z+dS)2aFQuoted-printable content transfer encoding per RFCs 2045-2047. This module handles the content transfer encoding method defined in RFC 2045 to encode US ASCII-like 8-bit data called `quoted-printable'. It is used to safely encode text that is in a character set similar to the 7-bit US ASCII character set, but that includes some 8-bit characters that are normally not allowed in email bodies or headers. Quoted-printable is very space-inefficient for encoding binary files; use the email.base64mime module for that instead. This module provides an interface to encode and decode both headers and bodies with quoted-printable encoding. RFC 2045 defines a method for including character set information in an `encoded-word' in a header. This method is commonly used for 8-bit real names in To:/From:/Cc: etc. fields, as well as Subject: lines. This module does not do the line wrapping or end-of-line character conversion necessary for proper internationalized headers; it only does dumb encoding and decoding. To deal with the various line wrapping issues, use the email.header module. )unicode_literals)division)absolute_import)byteschrdictintrangesuper) body_decode body_encode body_lengthdecode decodestring header_decode header_encode header_lengthquoteunquoteN) ascii_lettersdigits hexdigits  ccs|]}|d|fVqdS)=%02XN).0crr|/private/var/folders/s6/9n5zrl012gv99k63s4q6ccsd4s6mqz/T/pip-target-f5cq3f2q/lib/python/future/backports/email/quoprimime.py <r s-!*+/ascii_ s_ !"#$%&'()*+,-./0123456789:;<>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ cCst|t|kS)z>Return True if the octet should be escaped with header quopri.)r_QUOPRI_HEADER_MAPoctetrrr header_checkNsr)cCst|t|kS)z.sum bytearrayrrrrXs rcCstdd|DS)zReturn a body quoted-printable encoding length. :param bytearray: An array of bytes (a.k.a. octets). :return: The length in bytes of the byte array when it is encoded with quoted-printable for bodies. css|]}tt|VqdSr,)r-r*r.rrrr lr!zbody_length..r/r1rrrr esr cCsft|tst|}|s&||n)rYrLrRrrW)rMrZ is_last_charrrr write_chars     z_body_accumulator.write_char)r) __name__ __module__ __qualname__rIrSrUrWrYr[ __classcell__rrrPrrHs   rHLc Cs|dkrtd|s|S|ddv}t||}|}t|d}t|D]^\}}t|d} t|D],\} } tt| rt| } || | | kqf||ks|rJ| qJ| S)aEncode with quoted-printable, wrapping at maxlinelen characters. Each line of encoded text will end with eol, which defaults to "\n". Set this to "\r\n" if you will be using the result of this function directly in an email. Each line will be wrapped at, at most, maxlinelen characters before the eol string (maxlinelen defaults to 76 characters, the maximum value permitted by RFC 2045). Long lines will have the 'soft line break' quoted-printable character "=" appended to them, so the decoded text will be identical to the original text. The minimum maxlinelen is 4 to have room for a quoted character ("=XX") followed by a soft line break. Smaller values will generate a ValueError. zmaxlinelen must be at least 4r3rr=) ValueErrorrH splitlinesr- enumerater+rArr[rUgetvalue) bodyrKrJZ last_has_eol encoded_bodylinesZ last_line_noline_nolineZlast_char_indexirrrrr s"       r cCs|s|Sd}|D]}|}|s.||7}qd}t|}||kr||}|dkrd||7}|d7}nv|d|kr||d7}q:n^|d|kr||dtvr||dtvr|t|||d7}|d7}n||7}|d7}||kr:||7}q:q|ddvr||r|d d}|S) z_Decode a quoted-printable string. Lines are separated with eol, which defaults to \n. rrrVr=rZr>r3rN)rcrstripr-rrendswith)rGrJdecodedrjrknrrrrrs8   ,   rcCs|d}t|S)zCTurn a match in the form =AB to the ASCII character with value 0xabr)groupr)matchr9rrr_unquote_match7s rrcCs|dd}tdt|tjS)aDecode a string encoded with RFC 2045 MIME header `Q' encoding. This function does not parse a full MIME header value encoded with quoted-printable (like =?iso-8895-1?q?Hello_World?=) -- please use the high level email.header class for that functionality. r$r%z=[a-fA-F0-9]{2})replaceresubrrASCIIr@rrrr>s r)r)rB),__doc__ __future__rrrZfuture.builtinsrrrrr r __all__rtiostringrrrCRLFNLrCr&copyr*encoderrAr)r+rr r<rrrStringIOrHr rr rrrrrrrrsB           61 0