mò %U²Ic@sådZddddgZdZdZdZdZyd klZlZWne j odZdZnXd „Z d „Z d d „Z d d d„Zd d„Zd d„Zd„Zd„Zd„Zedjo eƒndS(sHConversions to/from quoted-printable transport encoding as per RFC 1521.tencodetdecodet encodestringt decodestringt=iLt0123456789ABCDEFt(sa2b_qpsb2a_qpcCsS|djo|Sn|djo|Sn|tjpd|jo djn S(séDecide 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~N(tct quotetabstheadertESCAPE(R R R ((t#/data/zmath/lib/python2.4/quopri.pyt needsquotings   cCs(t|ƒ}tt|dt|dS(sQuote a single character.iN(tordR tiR tHEX(R R((Rtquote#s ic Cs¨tdj o9|iƒ} t| d|d|ƒ}|i |ƒdSn|dd„} d}x%|i ƒ} | pPng}d}| ddjo| d } d}nxc| D][}t|||ƒot|ƒ}n|o|d jo|id ƒq®|i|ƒq®W|dj o| |ƒnti|ƒ} x>t| ƒtjo*| | td d d ƒ| td} q:W| }q^W|dj o| |d |ƒndS( s–Read '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. R R Ns cCs||o8|ddjo'|i|d t|dƒ|ƒn:|djo|it|ƒ|ƒn|i||ƒdS(Niÿÿÿÿs t.(tstoutputtwriteRtlineEnd(RRR((RR;s ' iRiÿÿÿÿRRRs= (tb2a_qptNonetinputtreadtdataR R todataRRtprevlinetreadlinetlinetoutlinetstrippedR RRtappendt EMPTYSTRINGtjointthislinetlent MAXLINESIZE( RRR R R"R#RR RRR!RR'((RR*sF           cCsftdj ot|d|d|ƒSndkl}||ƒ}|ƒ}t ||||ƒ|i ƒS(NR R (sStringIO( RRRR R t cStringIOtStringIOtinfptoutfpRtgetvalue(RR R R-R+R,((RRis    c Cs{tdj o3|iƒ} t| d|ƒ}|i|ƒdSnd}x|i ƒ} | pPndt | ƒ}}|djo]| |ddjoHd}|d}x;|djo#| |ddjo|d}q©Wnd}xQ||joC| |}|djo|o|d }|d}qç|tjo||}|d}qç|d|jo| o d}Pqç|d|jo-| |dtjo|t}|d }qç|d |jo]t| |dƒoHt| |d ƒo3|tt| |d|d !ƒƒ}|d }qç||}|d}qçW|p|i|dƒd}qIqIW|o|i|ƒndS( sÑRead '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).R NRiis s RRii(ta2b_qpRRRRR RRRtnewR R!R(RtntpartialR R tishextchrtunhex( RRR R2RRR R0R1R!R((RRtsL    ""    &;3cCs`tdj ot|d|ƒSndkl}||ƒ}|ƒ}t||d|ƒ|i ƒS(NR (sStringIO( R/RRR R*R+R,R-RR.(RR R-R+R,((RRŸs    cCsWd|jo djnp9d|jo djnpd|jo djnS(s8Return true if the character 'c' is a hexadecimal digit.t0t9tatftAtFN(R (R ((RR3«scCsÆd}x¹|D]±}d|jo djnotdƒ}nfd|jo djnotdƒd}n4d|jo djnotdƒd}nP|d t|ƒ|}q W|S( s.Get the integer value of a hexadecimal number.iR6R7R8R9i R:R;iN(tbitsRR RR(RRR<R ((RR5¯sc Csödk}dk} y#| i|iddƒ\} }WnE| ij o6} |i|_| GHdGHdGHdGH|i dƒnXd}d}xB| D]:\}}|djo d}n|d jo d}qqW|o)|o"|i|_d GH|i dƒn|p d g}nd}x¿|D]·}|d jo |i}nLyt|ƒ}Wn8tj o,} |iid || fƒd}qnX|ot||iƒnt||i|ƒ||ij o|iƒqqW|o|i |ƒndS( Nittds"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) (tsystgetopttargvtoptstargsterrortmsgtstderrtstdouttexittdecottabstoR8tststfiletstdintfptopentIOErrorRRRtclose( R8RORIRJRCRKR?RMRLRER@RB((RtmainÀsV  #        t__main__N(t__doc__t__all__R R)RR%tbinasciiR/Rt ImportErrorRRRRRRRR3R5RSt__name__(R5R)RRVRR/R3RRR%RRR RRSR((Rt?s*    ? +   ,