3 \ÿBã@srddddgZddlmZddlZddlZddlmZddlmZd Z d Z d Z d Z d Z dZdZe e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfd*e e dfe e dfe ddfe ddfe ddfe e dfe e dfdœZdddddddddddddddddddddddd d œZd!d"dd#œZd+d$d„Zd%d„Zd&d„Zd'd(„ZGd)d„dƒZdS),ÚCharsetÚ add_aliasÚ add_charsetÚ add_codecé)ÚpartialN)Úerrors)Úencode_7or8bitéééézus-asciiz unknown-8bitÚz iso-2022-jpzutf-8)z 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-1252Zvisciizus-asciiÚbig5Úgb2312zeuc-jpÚ shift_jisz iso-2022-jpzkoi8-rzutf-8z 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-16zks_c_5601-1987zeuc-jpzeuc-kr)Úlatin_1zlatin-1Zlatin_2zlatin-2Zlatin_3zlatin-3Zlatin_4zlatin-4Zlatin_5zlatin-5Zlatin_6zlatin-6Zlatin_7zlatin-7Zlatin_8zlatin-8Zlatin_9zlatin-9Zlatin_10zlatin-10Úcp949Úeuc_jpÚeuc_krÚasciiÚ eucgb2312_cnÚbig5_tw)rrzus-asciicCs"|tkrtdƒ‚|||ft|<dS)Nz!SHORTEST not allowed for body_enc)ÚSHORTESTÚ ValueErrorÚCHARSETS)ÚcharsetZ header_encZbody_encÚoutput_charset©rú%/usr/lib64/python3.6/email/charset.pyrmscCs |t|<dS)N)ÚALIASES)ÚaliasZ canonicalrrrr‰scCs |t|<dS)N)Ú CODEC_MAP)rZ codecnamerrrr’scCs"|tkr|jddƒS|j|ƒSdS)NrÚsurrogateescape)Ú UNKNOWN8BITÚencode)ÚstringÚcodecrrrÚ_encodeŸs r'c@s\eZdZefdd„Zdd„ZeZdd„Zdd„Zd d „Z d d „Z d d„Z dd„Z dd„Z dS)rc CsÀy$t|tƒr|jdƒn t|dƒ}Wntk rBtj|ƒ‚YnX|jƒ}tj||ƒ|_ t j|j t t dfƒ\}}}|s~|j }||_ ||_tj||ƒ|_tj|j |j ƒ|_tj|j|jƒ|_dS)Nr)Ú isinstanceÚstrr$Ú UnicodeErrorrZ CharsetErrorÚlowerrÚgetÚ input_charsetrrÚBASE64Úheader_encodingÚ body_encodingrr!Z input_codecÚ output_codec)Úselfr-ZhencZbencZconvrrrÚ__init__Ós&   zCharset.__init__cCs |jjƒS)N)r-r+)r2rrrÚ__str__ôszCharset.__str__cCst|ƒt|ƒjƒkS)N)r)r+)r2ÚotherrrrÚ__eq__ùszCharset.__eq__cCs$|jtkrdS|jtkrdStSdS)Nzquoted-printableÚbase64)r0ÚQPr.r)r2rrrÚget_body_encodingüs   zCharset.get_body_encodingcCs |jp |jS)N)rr-)r2rrrÚget_output_charsetszCharset.get_output_charsetcCs6|jpd}t||ƒ}|j|ƒ}|dkr*|S|j||ƒS)Nzus-ascii)r1r'Ú _get_encoderÚ header_encode)r2r%r&Ú header_bytesÚencoder_modulerrrr<s   zCharset.header_encodecCs|jpd}t||ƒ}|j|ƒ}t|j|d�}|jƒ}t|ƒt}g} g} t|ƒ|} x˜|D]�} | j | ƒt j | ƒ} |j t| |ƒƒ}|| krZ| j ƒ| rª| rª| j dƒn.| r²dnd}t j | ƒ}t||ƒ}| j ||ƒƒ| g} t|ƒ|} qZWt j | ƒ}t||ƒ}| j ||ƒƒ| S)Nzus-ascii)rú r )r1r'r;rr<r:ÚlenÚRFC2047_CHROME_LENÚnextÚappendÚ EMPTYSTRINGÚjoinÚ header_lengthÚpop)r2r%Z maxlengthsr&r=r>ÚencoderrZextraÚlinesZ current_lineÚmaxlenÚ characterZ this_lineZlengthZ separatorZ joined_linerrrÚheader_encode_lines,s6               zCharset.header_encode_linescCs`|jtkrtjS|jtkr tjS|jtkrXtjj|ƒ}tjj|ƒ}||krPtjStjSndSdS)N)r/r.ÚemailÚ base64mimer8Ú quoprimimerrF)r2r=Zlen64Zlenqprrrr;js     zCharset._get_encodercCsŽ|s|S|jtkr4t|tƒr(|j|jƒ}tjj|ƒS|jt krjt|tƒrT|j|jƒ}|j dƒ}tj j|ƒSt|tƒr†|j|jƒj dƒ}|SdS)NÚlatin1r) r0r.r(r)r$rrMrNÚ body_encoder8ÚdecoderO)r2r%rrrrQys           zCharset.body_encodeN)Ú__name__Ú __module__Ú __qualname__ÚDEFAULT_CHARSETr3r4Ú__repr__r6r9r:r<rLr;rQrrrrr§s, !>)NNN)NNN)Ú__all__Ú functoolsrZemail.base64mimerMZemail.quoprimimerZemail.encodersrr8r.rrArVr#rDrrr!rrrr'rrrrrÚs†