U e5dTã@s´dZddddgZdZdZdZdZzd 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. ó ó_ó ó~)Ú isinstanceÚbytesÚAssertionErrorÚESCAPE)ÚcÚ quotetabsÚheader©rú/usr/lib64/python3.8/quopri.pyÚ needsquotings rcCsBt|tƒrt|ƒdkst‚t|ƒ}ttt|dt|dfƒS)zQuote a single character.éé)rrÚlenrÚordrÚHEX©rrrrÚquote$srFc Cs2tdk r,| ¡}t|||d�}| |¡dS|dfdd„}d}| ¡}|sN�qg} d} |dd…dkrv|dd…}d} |D]D} t| fƒ} t| ||ƒrœt| ƒ} |r´| dkr´|  d ¡qz|  | ¡qz|dk rÐ||ƒt  | ¡} t | ƒt k�r|| dt d …d d �| t d d…} qÚ| }q>|dk �r.||| 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<| |dd…t|dd…ƒ|¡n*|dkrX| t|ƒ|¡n| ||¡dS)Néÿÿÿÿr ó.)Úwriter)ÚsÚoutputÚlineEndrrrr$;s (zencode..writerr"r r rs= )r') r Úreadr$ÚreadlinerrrÚappendÚ EMPTYSTRINGÚjoinrÚ MAXLINESIZE) Úinputr&rrÚdataÚodatar$ZprevlineÚlineZoutlineÚstrippedrZthislinerrrr,s>           cCsFtdk rt|||d�Sddlm}||ƒ}|ƒ}t||||ƒ| ¡S)Nr r©ÚBytesIO)r Úior4rÚgetvalue)r%rrr4ÚinfpÚoutfprrrrjs c Csötdk r*| ¡}t||d�}| |¡dSd}| ¡}|s>�qâdt|ƒ}}|dkrœ||d|…dkrœd} |d}|dkr ||d|…dkr |d}qtnd} ||k�rÊ|||d…} | dkrØ|rØ|d }|d}q | tkrò|| }|d}q |d|k�r| �sd} �qÊq |d|k�rJ||d|d …tk�rJ|t}|d }q |d |k�r¸t||d|d …ƒ�r¸t||d |d …ƒ�r¸|tt||d|d …ƒfƒ}|d }q || }|d}q | s.| |d¡d}q.|�rò| |¡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©rrrrr!s r r éé) r r(r$r)rrÚishexrÚunhex) r.r&rr/r0Únewr1ÚiÚnÚpartialrrrrrusP       ( B"  cCsDtdk rt||d�Sddlm}||ƒ}|ƒ}t|||d�| ¡S)Nr9rr3)r r5r4rr6)r%rr4r7r8rrrr 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)rrrrrrrr<¬sr<cCs²d}|D]¤}t|fƒ}d|kr*dkr8nn tdƒ}n`d|krLdkr^nntdƒd}n:d |krrd kr„nntd ƒd}nd s˜td t|ƒƒ‚|d t|ƒ|}q|S)z.Get the integer value of a hexadecimal number.rrBrCÚ0rDrEÚaé rFrGFznon-hex digit r)rrrÚrepr)r%Úbitsrr?rrrr=±s  r=c Cs¨ddl}ddl}z| |jdd…d¡\}}WnV|jk r„}z6|j|_t|ƒtdƒtdƒtdƒ| d¡W5d}~XYnXd}d}|D] \}}|dkr¦d}|d kr’d}q’|rÖ|rÖ|j|_td ƒ| d¡|sàd g}d} |D]ª} | d krþ|jj } nTzt | d ƒ} WnDt k �rP}z$|j  d | |f¡d} WY¢qèW5d}~XYnXz*|�rjt| |jj ƒnt| |jj |ƒW5| d k�r�|   ¡Xqè| �r¤| | ¡dS)NrrZtdz"usage: quopri [-t | -d] [file] ...z-t: quote tabsz-d: decode; default encoder:z-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$Úcloserr) rOrPZoptsÚargsÚmsgZdecoZtabsÚorIÚstsÚfileÚfprrrÚmainÃsT     rbÚ__main__)F)FF)F)F)Ú__doc__Ú__all__rr-rr+Zbinasciir r Ú ImportErrorrrrrrrr<r=rbÚ__name__rrrrÚs*   > + .