grthtrhthjhtyjytjytkergtrhtrjytjerhrfh3 \^ã @s´dZddddgZdZdZdZdZyd d lmZmZWne k rPd Zd ZYnXd d „Z dd„Z ddd„Z ddd„Z ddd„Zddd„Zdd„Zdd„Zdd„Zedkr°eƒd S) zHConversions to/from quoted-printable transport encoding as per RFC 1521.ÚencodeÚdecodeÚ encodestringÚ decodestringó=éLs0123456789ABCDEFóé)Úa2b_qpÚb2a_qpNcCsHt|tƒst‚|dkr|S|dkr&|S|tkpFd|ko@dkn S)zìDecide whether a particular byte ordinal needs to be quoted. The 'quotetabs' flag indicates whether embedded tabs and spaces should be quoted. Note that line-ending tabs and spaces are always encoded, as per RFC 1521. s ó_ó ó~)Ú isinstanceÚbytesÚAssertionErrorÚESCAPE)ÚcÚ quotetabsÚheader©rú/usr/lib64/python3.6/quopri.pyÚ needsquotings rcCsBt|tƒrt|ƒdkst‚t|ƒ}ttt|dt|dfƒS)zQuote a single character.éé)rrÚlenrÚordrÚHEX)rrrrÚquote$srFc Cs<tdk r,|jƒ}t|||d�}|j|ƒdS|dfdd„}d}xâ|jƒ}|sNPg} d} |d d…dkrv|dd …}d} xL|D]D} t| fƒ} t| ||ƒržt| ƒ} |r¶| dkr¶| jd ƒq|| j| ƒq|W|dk rÔ||ƒtj | ƒ} x:t | ƒt k�r|| dt d…d d �| t dd…} qàW| }q@W|dk �r8||| d �dS)avRead 'input', apply quoted-printable encoding, and write to 'output'. 'input' and 'output' are binary file objects. The 'quotetabs' flag indicates whether embedded tabs and spaces should be quoted. Note that line-ending tabs and spaces are always encoded, as per RFC 1521. The 'header' flag indicates whether we are encoding spaces as _ as per RFC 1522.N)rró cSsj|r<|dd…dkr<|j|dd…t|dd…ƒ|ƒn*|dkrX|jt|ƒ|ƒn|j||ƒdS)Nrs ó.éÿÿÿÿr r )Úwriter)ÚsÚoutputÚlineEndrrrr!;s (zencode..writerrr r s= )r$r r ) r Úreadr!ÚreadlinerrrÚappendÚ EMPTYSTRINGÚjoinrÚ MAXLINESIZE) Úinputr#rrÚdataÚodatar!ZprevlineÚlineZoutlineÚstrippedrZthislinerrrr,s@           cCsFtdk rt|||d�Sddlm}||ƒ}|ƒ}t||||ƒ|jƒS)N)rrr)ÚBytesIO)r Úior0rÚgetvalue)r"rrr0ÚinfpÚoutfprrrrjs c Cstdk r*|jƒ}t||d�}|j|ƒdSd}�xÀ|jƒ}|s@Pdt|ƒ}}|dkr¢||d|…dkr¢d} |d}x.|dkrž||d|…dkrž|d}qxWnd} �x.||k�rÖ|||d…} | dkrâ|râ|d }|d}qª| tk�rþ|| }|d}qª|d|k�r| �rd} Pqª|d|k�rV||d|d …tk�rV|t}|d }qª|d |k�rÄt||d|d …ƒ�rÄt||d |d …ƒ�rÄ|tt||d|d …ƒfƒ}|d }qª|| }|d}qªW| s2|j|dƒd}q2W|�r|j|ƒdS) z»Read 'input', apply quoted-printable decoding, and write to 'output'. 'input' and 'output' are binary file objects. If 'header' is true, decode underscore as space (per RFC 1522).N)rrrrrs r r éé) r r%r!r&rrÚishexrÚunhex) r+r#rr,r-Únewr.ÚiÚnÚpartialrrrrrusR      ( B"  cCsDtdk rt||d�Sddlm}||ƒ}|ƒ}t|||d�|jƒS)N)rr)r0)r r1r0rr2)r"rr0r3r4rrrr s  cCsVt|tƒst‚d|ko dknpTd|ko8dknpTd|koPdkSS)zDReturn true if the byte ordinal 'c' is a hexadecimal digit in ASCII.ó0ó9óaófóAóF)rrr)rrrrr7¬sr7cCs¶d}x¬|D]¤}t|fƒ}d|ko*dknr:tdƒ}n`d|koLdknr`tdƒd}n:d |kord knr†td ƒd}nd sštd t|ƒƒ‚|d t|ƒ|}q W|S)z.Get the integer value of a hexadecimal number.rr=r>Ú0r?r@Úaé rArBFznon-hex digit r)rrrÚrepr)r"Úbitsrr:rrrr8±s   r8c (Cs¬ddl}ddl}y|j|jdd…dƒ\}}WnV|jk r„}z8|j|_t|ƒtdƒtdƒtdƒ|jdƒWYdd}~XnXd}d}x(|D] \}}|dkr¨d}|d kr”d}q”W|rÚ|rÚ|j|_td ƒ|jdƒ|säd g}d} x®|D]¦} | d k�r|jj } nNyt | d ƒ} Wn>t k �rR}z |jj d | |fƒd} wîWYdd}~XnXz*|�rlt | |jj ƒnt| |jj |ƒWd| d k�r’| jƒXqîW| �r¨|j| ƒdS)NrrZtdz"usage: quopri [-t | -d] [file] ...z-t: quote tabsz-d: decode; default encoder5z-tz-dz -t and -d are mutually exclusiveú-Úrbz%s: can't open (%s) )ÚsysÚgetoptÚargvÚerrorÚstderrÚstdoutÚprintÚexitÚstdinÚbufferÚopenÚOSErrorr!rrÚclose) rJrKZoptsÚargsÚmsgZdecoZtabsÚorDÚstsÚfileÚfprrrÚmainÃsT     r]Ú__main__)F)FF)F)F)Ú__doc__Ú__all__rr*rr(Zbinasciir r Ú ImportErrorrrrrrrr7r8r]Ú__name__rrrrÚs*   > + .