a DOgo@sdZgdZdZdZdZdZzddlmZmZWne yJdZdZYn0d d Z d d Z dddZ dddZ dddZd ddZddZddZddZedkredS)!zHConversions to/from quoted-printable transport encoding as per RFC 1521.)encodedecode encodestring decodestring=Ls0123456789ABCDEF)a2b_qpb2a_qpNcCsHt|tsJ|dvr|S|dkr&|S|tkpFd|ko@dkn S)zDecide 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.  _ ~) isinstancebytesESCAPE)c quotetabsheaderr+/opt/alt/python39/lib64/python3.9/quopri.py needsquotings rcCsBt|trt|dksJt|}ttt|dt|dfS)zQuote a single character.)rrlenordrHEXrrrrquote$srFc Cs2tdur,|}t|||d}||dS|dfdd}d}|}|sNqg} d} |dddkrv|dd}d} |D]D} t| f} t| ||rt| } |r| dkr| d qz| | qz|dur||t | } t | t kr|| dt d d d | t d d} q| }q>|dur.||| 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.Nrr cSsj|r<|dddvr<||ddt|dd|n*|dkrX|t||n|||dS)Nr .)writer)soutputlineEndrrrr#;s (zencode..writerr!r r rs= )r&) r readr#readlinerrrappend EMPTYSTRINGjoinr MAXLINESIZE) inputr%rrdataodatar#ZprevlinelineZoutlinestrippedrZthislinerrrr,s>           rcCsFtdurt|||dSddlm}||}|}t|||||S)NrrBytesIO)r ior3rgetvalue)r$rrr3infpoutfprrrrjs rc Cstdur*|}t||d}||dSd}|}|s>qdt|}}|dkr||d|dkrd} |d}|dkr||d|dvr|d}qtnd} ||kr|||d} | dkr|r|d }|d}q| tkr|| }|d}q|d|kr| sd} qq|d|krJ||d|d tkrJ|t}|d }q|d |krt||d|d rt||d |d r|tt||d|d f}|d }q|| }|d}q| s.||dd}q.|r||dS) zRead '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).Nrrrrr s r r ) r r'r#r(rrishexrunhex) r-r%rr.r/newr0inpartialrrrrrus@       (B,rcCsDtdurt||dSddlm}||}|}t|||d|S)Nr8rr2)r r4r3rr5)r$rr3r6r7rrrrs  rcCsVt|tsJd|ko dknpTd|ko8dknpTd|koPdkSS)zDReturn true if the byte ordinal 'c' is a hexadecimal digit in ASCII.09afAF)rrrrrrr;sr;cCsd}|D]}t|f}d|kr*dkr8nn td}n`d|krLdkr^nntdd}n:d |krrd krnntd d}nd sJd t||d t||}q|S)z.Get the integer value of a hexadecimal number.rrArB0rCrDa rErFFznon-hex digit r)rrrepr)r$bitsrr>rrrr<s  r<c Csddl}ddl}z||jddd\}}WnX|jy}z>|j|_t|tdtdtd|dWYd}~n d}~00d}d}|D] \}}|d krd }|d krd }q|r|r|j|_td |d|sd g}d} |D]} | d kr|jj } nZzt | d} WnJt yZ}z0|j d| |fd} WYd}~qWYd}~n d}~00z<|rtt | |jj nt| |jj |W| d kr| q| d kr| 0q| r|| dS)NrrZtdz"usage: quopri [-t | -d] [file] ...z-t: quote tabsz-d: decode; default encoder9Fz-tTz-dz -t and -d are mutually exclusive-rbz%s: can't open (%s) )sysgetoptargverrorstderrstdoutprintexitstdinbufferopenOSErrorr#rrclose) rNrOZoptsargsmsgZdecoZtabsorHstsfilefprrrmainsR       "   ra__main__)F)FF)F)F)__doc____all__rr,rr*Zbinasciir r ImportErrorrrrrrrr;r<ra__name__rrrrs*   > + .