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 dfdZdddddddddddddddddddddddd d Zd!d"dd#Zd+d$dZd%dZd&dZd'd(ZGd)ddZdS),Charset add_alias add_charset add_codec)partialN)errors)encode_7or8bitzus-asciiz unknown-8bitz 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-asciibig5gb2312zeuc-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-10cp949euc_jpeuc_krascii eucgb2312_cnbig5_tw)rrzus-asciicCs"|tkrtd|||ft|<dS)Nz!SHORTEST not allowed for body_enc)SHORTEST ValueErrorCHARSETS)charsetZ header_encZbody_encoutput_charsetr%/usr/lib64/python3.6/email/charset.pyrmscCs |t|<dS)N)ALIASES)aliasZ canonicalrrrrscCs |t|<dS)N) CODEC_MAP)rZ codecnamerrrrscCs"|tkr|jddS|j|SdS)Nrsurrogateescape) UNKNOWN8BITencode)stringcodecrrr_encodes r'c@s\eZdZefddZddZeZddZddZd d Z d d Z d dZ ddZ ddZ dS)rc Csy$t|tr|jdn t|d}Wntk rBtj|YnX|j}tj|||_ t j|j t t df\}}}|s~|j }||_ ||_tj|||_tj|j |j |_tj|j|j|_dS)Nr) isinstancestrr$ UnicodeErrorrZ CharsetErrorlowerrget input_charsetrrBASE64header_encoding body_encodingrr!Z input_codec output_codec)selfr-ZhencZbencZconvrrr__init__s&   zCharset.__init__cCs |jjS)N)r-r+)r2rrr__str__szCharset.__str__cCst|t|jkS)N)r)r+)r2otherrrr__eq__szCharset.__eq__cCs$|jtkrdS|jtkrdStSdS)Nzquoted-printablebase64)r0QPr.r)r2rrrget_body_encodings   zCharset.get_body_encodingcCs |jp |jS)N)rr-)r2rrrget_output_charsetszCharset.get_output_charsetcCs6|jpd}t||}|j|}|dkr*|S|j||S)Nzus-ascii)r1r' _get_encoder header_encode)r2r%r& header_bytesencoder_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 dn.| rdnd}t j | }t||}| j ||| g} t||} qZWt j | }t||}| j ||| S)Nzus-ascii)r 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|jtkrXtjj|}tjj|}||krPtjStjSndSdS)N)r/r.email base64mimer8 quoprimimerrF)r2r=Zlen64Zlenqprrrr;js     zCharset._get_encodercCs|s|S|jtkr4t|tr(|j|j}tjj|S|jt krjt|trT|j|j}|j d}tj j|St|tr|j|jj d}|SdS)Nlatin1r) r0r.r(r)r$rrMrN body_encoder8decoderO)r2r%rrrrQys           zCharset.body_encodeN)__name__ __module__ __qualname__DEFAULT_CHARSETr3r4__repr__r6r9r:r<rLr;rQrrrrrs, !>)NNN)NNN)__all__ functoolsrZemail.base64mimerMZemail.quoprimimerZemail.encodersrr8r.rrArVr#rDrrr!rrrr'rrrrrs