3 \T @sdZddddgZdZdZdZdZyd d lmZmZWne k rPd Zd ZYnXd d Z ddZ dddZ dddZ dddZdddZddZddZddZedkred S) zHConversions to/from quoted-printable transport encoding as per RFC 1521.encodedecode encodestring decodestring=Ls0123456789ABCDEF)a2b_qpb2a_qpNcCs:|dkr |S|dkr|S|tkp8d|ko2dkn 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. s _ ~)ESCAPE)c quotetabsheaderr/usr/lib64/python3.6/quopri.py needsquotings rcCs(t|}ttt|dt|dfS)zQuote a single character.)ordrbytesHEX)rrrrquote$srFc Cs<tdk r,|j}t|||d}|j|dS|dfdd}d}x|j}|sNPg} d} |d ddkrv|dd }d} xL|D]D} t| f} t| ||rt| } |r| dkr| jd q|| j| q|W|dk r||tj | } x:t | t kr|| dt dd d | t dd} qW| }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<|dddkr<|j|ddt|dd|n*|dkrX|jt||n|j||dS)Ns .rr)writer)soutputlineEndrrrr;s (zencode..writerrr r s= )r!rr) r readrreadlinerrrappend EMPTYSTRINGjoinlen MAXLINESIZE) inputr rrdataodatarZprevlinelineZoutlinestrippedrZthislinerrrr,s@           cCsFtdk rt|||dSddlm}||}|}t|||||jS)N)rrr)BytesIO)r ior.rgetvalue)rrrr.infpoutfprrrrjs c Cstdk r*|j}t||d}|j|dSd}x|j}|s@Pdt|}}|dkr||d|dkrd} |d}x.|dkr||d|dkr|d}qxWnd} x.||kr|||d} | dkr|r|d }|d}q| tkr|| }|d}q|d|kr| rd} Pq|d|krV||d|d tkrV|t}|d }q|d |krt||d|d rt||d |d r|tt||d|d f}|d }q|| }|d}qW| s2|j|dd}q2W|r|j|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).N)rrrrrs r r ) r r"rr#r'rishexrunhex) r)r rr*r+newr,inpartialrrrrrusR      ( B"  cCsDtdk rt||dSddlm}||}|}t|||d|jS)N)rr)r.)r r/r.rr0)rrr.r1r2rrrrs  cCsHd|kodknpFd|ko*dknpFd|koBdkSS)zDReturn true if the byte ordinal 'c' is a hexadecimal digit in ASCII.09afAFr)rrrrr5sr5cCsd}x|D]}t|f}d|ko*dknr:td}nLd|koLdknr`tdd}n&d |kord knrtd d}n|d t||}q W|S) z.Get the integer value of a hexadecimal number.rr;r<0r=r>a r?r@r)rr)rbitsrr8rrrr6s   r6c (Csddl}ddl}y|j|jddd\}}WnV|jk r}z8|j|_t|tdtdtd|jdWYdd}~XnXd}d}x(|D] \}}|dkrd}|d krd}qW|r|r|j|_td |jd|sd g}d} x|D]} | d kr|jj } nNyt | d } Wn>t k rR}z |jj d | |fd} wWYdd}~XnXz*|rlt | |jj nt| |jj |Wd| d kr| jXqW| r|j| dS)NrrZtdz"usage: quopri [-t | -d] [file] ...z-t: quote tabsz-d: decode; default encoder3z-tz-dz -t and -d are mutually exclusive-rbz%s: can't open (%s) )sysgetoptargverrorstderrstdoutprintexitstdinbufferopenOSErrorrrrclose) rGrHZoptsargsmsgZdecoZtabsorBstsfilefprrrmainsT     rZ__main__)F)FF)F)F)__doc____all__rr(rr%Zbinasciir r ImportErrorrrrrrrr5r6rZ__name__rrrrs*   > + .