zfc@sdZddddgZdZdZdZdZyd d lmZmZWne k ridZdZnXd Z d Z d dZ d d dZd dZd dZdZdZdZedkrendS(sHConversions to/from quoted-printable transport encoding as per RFC 1521.tencodetdecodet encodestringt decodestringt=iLt0123456789ABCDEFti(ta2b_qptb2a_qpcCsG|dkr|S|dkr |S|tkpFd|koCdkn S(sDecide whether a particular character 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 t_t t~(tESCAPE(tct quotetabstheader((s/usr/lib64/python2.7/quopri.pyt needsquotings   cCs(t|}tt|dt|dS(sQuote a single character.i(tordR tHEX(R ti((s/usr/lib64/python2.7/quopri.pytquote#s ic Cstdk rA|j}t|d|d|}|j|dS|dd}d}x|j}|soPng} d} |ddkr|d }d} nx^|D]V} t| ||rt| } n|r| dkr| jd q| j| qW|dk r||ntj | } x<t | t kre|| t d  d d | t d } q*W| }qYW|dk r||d | ndS( sRead 'input', apply quoted-printable encoding, and write to 'output'. 'input' and 'output' are files with readline() and write() methods. 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. RRNs cSsw|r<|ddkr<|j|d t|d|n7|dkrb|jt||n|j||dS(Nis t.(twriteR(tstoutputtlineEnd((s/usr/lib64/python2.7/quopri.pyR;s & RiR R iRs= ( RtNonetreadRtreadlineRRtappendt EMPTYSTRINGtjointlent MAXLINESIZE( tinputRRRtdatatodataRtprevlinetlinetoutlinetstrippedR tthisline((s/usr/lib64/python2.7/quopri.pyR*s>            cCsdtdk r"t|d|d|Sddlm}||}|}t|||||jS(NRRi(tStringIO(RRt cStringIOR*Rtgetvalue(RRRR*tinfptoutfp((s/usr/lib64/python2.7/quopri.pyRis   c CsXtdk r;|j}t|d|}|j|dSd}x|j}|sZPndt|}}|dkr||ddkrd} |d}x7|dkr||ddkr|d}qWnd} x@||kr||} | dkr|r|d }|d}q| tkr<|| }|d}q|d|kr]| r]d} Pq|d|kr||dtkr|t}|d }q|d |krt||drt||d r|tt ||d|d !}|d }q|| }|d}qW| sD|j|dd}qDqDW|rT|j|ndS( sRead 'input', apply quoted-printable decoding, and write to 'output'. 'input' and 'output' are files with readline() and write() methods. If 'header' is true, decode underscore as space (per RFC 1522).RNRiis s R R ii( RRRRRR R tishextchrtunhex( R"RRR#R$tnewR&RtntpartialR ((s/usr/lib64/python2.7/quopri.pyRtsR      #    $ 8%   cCs^tdk rt|d|Sddlm}||}|}t||d||jS(NRi(R*(RRR+R*RR,(RRR*R-R.((s/usr/lib64/python2.7/quopri.pyRs   cCsPd|kodknpOd|ko3dknpOd|koMdkSS(s8Return true if the character 'c' is a hexadecimal digit.t0t9tatftAtF((R ((s/usr/lib64/python2.7/quopri.pyR/scCsd}x|D]}d|ko*dknr>td}n_d|koUdknrmtdd}n0d|kodknrtdd}nP|d t||}q W|S( s.Get the integer value of a hexadecimal number.iR5R6R7R8i R9R:i(R(RtbitsR R((s/usr/lib64/python2.7/quopri.pyR1s c Csddl}ddl}y#|j|jdd\}}WnC|jk r}|j|_|GHdGHdGHdGH|jdnXd}d}x>|D]6\}}|d krd}n|d krd}qqW|r|r|j|_d GH|jdn|s d g}nd} x|D]} | d kr8|j} nIyt| } Wn6t k r}|jj d | |fd} qnX|rt | |jnt | |j|| |jk r| j qqW| r|j| ndS(Niittds"usage: quopri [-t | -d] [file] ...s-t: quote tabss-d: decode; default encodeiis-ts-ds -t and -d are mutually exclusivet-s%s: can't open (%s) (tsystgetopttargvterrortstderrtstdouttexittstdintopentIOErrorRRRtclose( R>R?toptstargstmsgtdecottabstoR7tststfiletfp((s/usr/lib64/python2.7/quopri.pytmainsR  #         t__main__N(t__doc__t__all__R R!RRtbinasciiRRt ImportErrorRRRRRRRR/R1RRt__name__(((s/usr/lib64/python2.7/quopri.pyts*     ? +   ,