e fCC@sddddgZddlmZddlZddlZddlmZddlmZd Z d Z d Z d Z d Z dZdZie e dfd6e e dfd6e e dfd6e e dfd6e e dfd6e e dfd6e e dfd6e e dfd6e e dfd6e e dfd6e e dfd6e e dfd6dEd 6e e dfd6e e dfd6e ddfd6e ddfd 6e ddfd6e e dfd!6e e d"fd"6Zidd#6dd$6dd%6dd&6dd'6dd(6dd)6dd*6dd+6dd,6dd-6dd.6dd/6dd06dd16dd26dd36dd46dd56dd66d7d86dd96d:d;6d d<6Zid=d6d>d6dd 6Zdddd?dZd@dZdAdZdBdCZGdDddZdS)FCharset add_alias add_charset add_codec)partialN)errors)encode_7or8bitzus-asciiz unknown-8bitz iso-8859-1z iso-8859-2z iso-8859-3z iso-8859-4z iso-8859-9z iso-8859-10z iso-8859-13z iso-8859-14z iso-8859-15z iso-8859-16z windows-1252Zvisciibig5gb2312z iso-2022-jpzeuc-jp shift_jiszkoi8-rzutf-8latin_1zlatin-1Zlatin_2zlatin-2Zlatin_3zlatin-3Zlatin_4zlatin-4Zlatin_5zlatin-5Zlatin_6zlatin-6Zlatin_7zlatin-7Zlatin_8zlatin-8Zlatin_9zlatin-9Zlatin_10zlatin-10zks_c_5601-1987cp949euc_jpzeuc-kreuc_krascii eucgb2312_cnbig5_twcCs2|tkrtdn|||ft|Add character set properties to the global registry. charset is the input character set, and must be the canonical name of a character set. Optional header_enc and body_enc is either Charset.QP for quoted-printable, Charset.BASE64 for base64 encoding, Charset.SHORTEST for the shortest of qp or base64 encoding, or None for no encoding. SHORTEST is only valid for header_enc. It describes how message headers and message bodies in the input charset are to be encoded. Default is no encoding. Optional output_charset is the character set that the output should be in. Conversions will proceed from input charset, to Unicode, to the output charset when the method Charset.convert() is called. The default is to output in the same character set as the input. Both input_charset and output_charset must have Unicode codec entries in the module's charset-to-codec mapping; use add_codec(charset, codecname) to add codecs the module does not know about. See the codecs module's documentation for more information. z!SHORTEST not allowed for body_encN)SHORTEST ValueErrorCHARSETS)charsetZ header_encZbody_encoutput_charsetr2/opt/alt/python34/lib64/python3.4/email/charset.pyrms cCs|t|s  zCharset.header_encodecCs|jp d}t||}|j|}t|jd|}|j}t|t}g} g} t||} x|D]} | j | t j | } |j t| |}|| kr| j | r| r| j dnC| rdnd}t j | }t||}| j ||| g} t||} qqWt j | }t||}| j ||| S)afHeader-encode a string by converting it first to bytes. This is similar to `header_encode()` except that the string is fit into maximum line lengths as given by the argument. :param string: A unicode string for the header. It must be possible to encode this string to bytes using the character set's output codec. :param maxlengths: Maximum line length iterator. Each element returned from this iterator will provide the next maximum line length. This parameter is used as an argument to built-in next() and should never be exhausted. The maximum line lengths should not count the RFC 2047 chrome. These line lengths are only a hint; the splitter does the best it can. :return: Lines of encoded strings, each with RFC 2047 chrome. zus-asciirN r )r1r'r=rr>r<lenRFC2047_CHROME_LENnextappend EMPTYSTRINGjoin header_lengthpop)r2r%Z maxlengthsr&r?r@encoderrZextralinesZ current_linemaxlen characterZ this_lineZlengthZ separatorZ joined_linerrrheader_encode_lines/s6       zCharset.header_encode_linescCs|jtkrtjS|jtkr,tjS|jtkr|tjj|}tjj|}||krrtjStjSndSdS)N)r/r.email base64mimer: quoprimimerrH)r2r?Zlen64Zlenqprrrr=ms  zCharset._get_encodercCs|s |S|jtkrMt|tr=|j|j}ntjj|S|jt krt|tr|j|j}n|j d}tj j|St|tr|j|jj d}n|SdS)avBody-encode a string by converting it first to bytes. The type of encoding (base64 or quoted-printable) will be based on self.body_encoding. If body_encoding is None, we assume the output charset is a 7bit encoding, so re-encoding the decoded string using the ascii codec produces the correct string version of the content. latin1rN) r0r.r(r)r$rrOrP body_encoder:decoderQ)r2r%rrrrS|s zCharset.body_encodeN)__name__ __module__ __qualname____doc__DEFAULT_CHARSETr3r4__repr__r6r7r;r<r>rNr=rSrrrrrs +!       > )NNN)__all__ functoolsrZemail.base64mimerOZemail.quoprimimerZemail.encodersrr:r.rrCrYr#rFrrr!rrrr'rrrrrs