3 Õì2aNã@sÈdddgZddlZddlZddlZddlZddlmZddlmZm Z ddl m Z dZ d Z ejd ƒZejd ejƒZGd d„dƒZGd d„deƒZdZGdd„deƒZeeejdƒƒZdeZejZdS)Ú GeneratorÚDecodedGeneratorÚBytesGeneratoréN)Údeepcopy)ÚStringIOÚBytesIO)Ú_has_surrogatesÚ_Ú z \r\n|\r|\nz^From c@s¬eZdZd&ddœdd„Zdd„Zd'dd „Zd d „Zd d „Zdd„Zdd„Z dd„Z dd„Z dd„Z dd„Z e Zdd„Zdd„Zdd„Zd d!„Zed(d"d#„ƒZed$d%„ƒZdS))rN)ÚpolicycCs6|dkr|dkrdn|j}||_||_||_||_dS)NT)Ú mangle_from_Ú_fpÚ _mangle_from_Ú maxheaderlenr )ÚselfÚoutfpr rr ©rú./opt/alt/python36/lib64/python3.6/generator.pyÚ__init__$s zGenerator.__init__cCs|jj|ƒdS)N)r Úwrite)rÚsrrrrDszGenerator.writeFc CsØ|jdkr|jn|j}|dk r*|j|d�}|jdk rB|j|jd�}|j|_|j|jƒ|_d|_|j|jƒ|_|j}|j}zL||_||_|r¸|j ƒ}|s¨dt j t j ƒƒ}|j ||jƒ|j |ƒWd||_||_XdS)N)Úlinesep)Úmax_line_lengthÚz From nobody )r ÚclonerrÚ_NLÚ_encodeÚ _encoded_NLZ_EMPTYÚ_encoded_EMPTYZ get_unixfromÚtimeZctimerÚ_write)rÚmsgÚunixfromrr Zold_gen_policyZold_msg_policyZufromrrrÚflattenHs,  zGenerator.flattencCs|j||jd|jd�S)N)r )Ú __class__rr )rÚfprrrryszGenerator.clonecCstƒS)N)r)rrrrÚ _new_buffer�szGenerator._new_buffercCs|S)Nr)rrrrrr‘szGenerator._encodecCsX|sdStj|ƒ}x*|dd…D]}|j|ƒ|j|jƒq W|drT|j|dƒdS)Nééÿÿÿÿr(r()ÚNLCREÚsplitrr)rÚlinesÚlinerrrÚ _write_lines•s  zGenerator._write_linesc Cs¤|j}z"d|_|jƒ|_}|j|ƒWd||_|j}|`X|rht|ƒ}|jd|dƒ|jd|dƒt|ddƒ}|dkrˆ|j|ƒn||ƒ|jj|j ƒƒdS)Nzcontent-transfer-encodingrz content-typer'Ú_write_headers) r Ú _munge_cter&Ú _dispatchrZreplace_headerÚgetattrr.rÚgetvalue)rr!ZoldfpZsfpZ munge_cteÚmethrrrr ¥s"   zGenerator._writecCst|jƒ}|jƒ}tj||fƒjddƒ}t|d|dƒ}|dkrh|jddƒ}t|d|dƒ}|dkrh|j}||ƒdS)Nú-r Z_handle_)Úget_content_maintypeÚget_content_subtypeÚ UNDERSCOREÚjoinÚreplacer1Ú _writeBody)rr!ÚmainÚsubZspecificr3Zgenericrrrr0Ès zGenerator._dispatchcCs:x(|jƒD]\}}|j|jj||ƒƒq W|j|jƒdS)N)Ú raw_itemsrr Zfoldr)rr!ÚhÚvrrrr.ÜszGenerator._write_headerscCsž|jƒ}|dkrdSt|tƒs.tdt|ƒƒ‚t|jƒr~|jdƒ}|dk r~t|ƒ}|d=|j ||ƒ|jƒ}|d|df|_ |j r�t j d|ƒ}|j|ƒdS)Nzstring payload expected: %sÚcharsetzcontent-transfer-encodingz content-typez>From )Ú get_payloadÚ isinstanceÚstrÚ TypeErrorÚtyperÚ_payloadZ get_paramrZ set_payloadr/rÚfcrer<r-)rr!Úpayloadr@rrrÚ _handle_textæs"      zGenerator._handle_textc Cs¢g}|jƒ}|dkrg}n(t|tƒr2|j|ƒdSt|tƒsB|g}x>|D]6}|jƒ}|j|ƒ}|j|d|jd�|j |j ƒƒqHW|j ƒ}|s®|j j |ƒ}|j|ƒ}|j|ƒ|jdk rê|jrÎtjd|jƒ} n|j} |j| ƒ|j|jƒ|jd||jƒ|�r|jj|jdƒƒx4|D],} |j|jd||jƒ|jj| ƒ�qW|j|jd|d|jƒ|jdk �rž|j�rŽtjd|jƒ} n|j} |j| ƒdS)NF)r"rz>From z--r)rArBrCrÚlistr&rr#rÚappendr2Z get_boundaryrr8Ú_make_boundaryZ set_boundaryÚpreamblerrGr<r-r ÚpopÚepilogue) rr!ZmsgtextsZsubpartsÚpartrÚgÚboundaryZalltextrMZ body_partrOrrrÚ_handle_multipartþsJ             zGenerator._handle_multipartc Cs0|j}|jdd�|_z|j|ƒWd||_XdS)Nr)r)r rrS)rr!ÚprrrÚ_handle_multipart_signed8s z"Generator._handle_multipart_signedcCsžg}x€|jƒD]t}|jƒ}|j|ƒ}|j|d|jd�|jƒ}|j|jƒ}|rx|d|jkrx|j |jj |dd…ƒƒq|j |ƒqW|j j |jj |ƒƒdS)NF)r"rr'r(r() rAr&rr#rr2r*rrrKr8r r)rr!ZblocksrPrrQÚtextr+rrrÚ_handle_message_delivery_statusCs  z)Generator._handle_message_delivery_statuscCs^|jƒ}|j|ƒ}|j}t|tƒrD|j|jdƒd|jd�|jƒ}n |j |ƒ}|j j |ƒdS)NrF)r"r) r&rrFrBrJr#rArr2rr r)rr!rrQrHrrrÚ_handle_messageXs    zGenerator._handle_messagecCsztjtjƒ}d t|d}|dkr(|S|}d}xD|jdtj|ƒdtjƒ}|j |ƒsZP|dt |ƒ}|d7}q2W|S) Nú=éz==rz^--z(--)?$Ú.r'z===============) ÚrandomZ randrangeÚsysÚmaxsizeÚ_fmtÚ _compile_reÚreÚescapeÚ MULTILINEÚsearchrC)ÚclsrVÚtokenrRÚbZcounterZcrerrrrLqs   zGenerator._make_boundarycCs tj||ƒS)N)raÚcompile)rerÚflagsrrrr`ƒszGenerator._compile_re)NN)FN)N)Ú__name__Ú __module__Ú __qualname__rrr#rr&rr-r r0r.rIr:rSrUrWrXÚ classmethodrLr`rrrrrs(  1# :  csLeZdZdd„Zdd„Zdd„Zdd„Z‡fd d „ZeZe d d „ƒZ ‡Z S) rcCs|jj|jddƒƒdS)NÚasciiÚsurrogateescape)r rÚencode)rrrrrr•szBytesGenerator.writecCstƒS)N)r)rrrrr&˜szBytesGenerator._new_buffercCs |jdƒS)Nrn)rp)rrrrrr›szBytesGenerator._encodecCs<x*|jƒD]\}}|jj|jj||ƒƒq W|j|jƒdS)N)r=r rr Z fold_binaryr)rr!r>r?rrrr.žszBytesGenerator._write_headerscs^|jdkrdSt|jƒrJ|jjdk rJ|jrFrom ) rFrr Zcte_typerrGr<r-ÚsuperrrI)rr!)r$rrrI¦s zBytesGenerator._handle_textcCstj|jdƒ|ƒS)Nrn)rarhrp)rerrirrrr`µszBytesGenerator._compile_re) rjrkrlrr&rr.rIr:rmr`Ú __classcell__rr)r$rrˆs  zD[Non-text (%(type)s) part of message omitted, filename %(filename)s]c@s$eZdZdddœdd„Zdd„ZdS)rN)r cCs.tj|||||d�|dkr$t|_n||_dS)N)r )rrÚ_FMTr_)rrr rZfmtr rrrrÃs  zDecodedGenerator.__init__c Csˆx‚|jƒD]v}|jƒ}|dkr4t|jdd�|d�q |dkr>q t|j|jƒ|jƒ|jƒ|jdƒ|jddƒ|jd d ƒd œ|d�q WdS) NrVF)Údecode)ÚfileZ multipartz [no filename]zContent-Descriptionz[no description]zContent-Transfer-Encodingz [no encoding])rEÚmaintypeÚsubtypeÚfilenameÚ descriptionÚencoding) Úwalkr5ÚprintrAr_Zget_content_typer6Ú get_filenameÚget)rr!rPrvrrrr0ás  zDecodedGenerator._dispatch)NNN)rjrkrlrr0rrrrr½sr'z%%0%dd)Ú__all__rar]rr\ÚcopyrÚiorrZ email.utilsrr7ÚNLrhr)rcrGrrrsrÚlenÚreprr^Ú_widthr_rLrrrrÚs(    p3;