�`^c@s�dZddddgZdZdZdZdZyd d
lmZmZWne k
ridZdZnXd�Zd�Zd
d�Z
d
d
d�Zd
d�Zd
d�Zd�Zd�Zd�Zedkr��ndS(sHConversions to/from quoted-printable transport encoding as per RFC 1521.tencodetdecodetencodestringtdecodestringt=iLt0123456789ABCDEFti�(ta2b_qptb2a_qpcCsG|dkr|S|dkr |S|tkpFd|koCdknS(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~(tESCAPE(tct quotetabstheader((s/sys/lib/python2.7/quopri.pytneedsquotings
cCs(t|�}tt|dt|dS(sQuote a single character.i(tordRtHEX(R
ti((s/sys/lib/python2.7/quopri.pytquote#sic
Cs�tdk rA|j�}t|d|d|�}|j|�dS|dd�}d}x|j�}|soPng} d}
|ddkr�|d }d}
nx^|D]V}t|||�r�t|�}n|r�dkr� jd �q�| j|�q�W|dk r||�ntj | �}x<t
|�tkre||td
dd�|td
}q*W|}qY|dk r�||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.
RRNs
cSsw|r<|ddkr<|j|d t|d�|�n7|dkrb|jt|�|�n|j||�dS(Ni�s t.(twriteR(tstoutputtlineEnd((s/sys/lib/python2.7/quopri.pyR;s
&Ri�R
R iRs=
(RtNonetreadRtreadlineRRtappendtEMPTYSTRINGtjointlentMAXLINESIZE(
tinputRRRtdatatodataRtprevlinetlinetoutlinetstrippedR
tthisline((s/sys/lib/python2.7/quopri.pyR*s>
cCsdtdk r"t|d|d|�Sddlm}||�}|�}t||||�|j�S(NRRi�(tStringIO(RRt cStringIOR*Rtgetvalue(RRRR*tinfptoutfp((s/sys/lib/python2.7/quopri.pyRis cCsWtdk r;|j�}t|d|�}|j|�dSd}x�j�}|sZPndt|�}}|dkr�||ddkr�d} |d}x7|dkr�||ddkr�|d}q�Wnd} x@||kr||}
|
dkr|r|d }|d}q�|
tkr<||
}|d}q�|d|kr]| r]d} Pq�|d|kr�||dtkr�|t}|d
}q�|d
|krt||d�rt||d
�r|tt ||d|d!��}|d}q�||
}|d}q�W| sD|j|d�d}qDqD|rS|j|�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).RNRiis
s
R R
ii(
RRRRRR Rtishextchrtunhex(R"RRR#R$tnewR&RtntpartialR
((s/sys/lib/python2.7/quopri.pyRtsR
#
$
8%
cCs^tdk rt|d|�Sddlm}||�}|�}t||d|�|j�S(NRi�(R*(RRR+R*RR,(RRR*R-R.((s/sys/lib/python2.7/quopri.pyR�s cCsPd|kodknpOd|ko3dknpOd|koMdkSS(s8Return true if the character 'c' is a hexadecimal digit.t0t9tatftAtF((R
((s/sys/lib/python2.7/quopri.pyR/�scCs�d}x�|D]�}d|ko*dknr>td�}n_d|koUdknrmtd�d}n0d|ko�dknr�td�d}nP|d t|�|}q
W|S(
s.Get the integer value of a hexadecimal number.iR5R6R7R8i
R9R:i(R(RtbitsR
R((s/sys/lib/python2.7/quopri.pyR1�s
cCs�ddl}ddl}y#|j|jdd�\}}WnC|jk
r�}|j|_|GHdGHdGHdGH|jd�nXd}d}x>|D]6\}}|d kr�d}n|d
kr�d}q�q�W|r�r�j|_dGH|jd�n|s
dg}nd} x�|D]�}
|
dkr8|j}nIyt|
�}Wn6t k
r�}|jj
d
|
|f�d} qnX|r�t||j�nt||j|�||jk r|j
�qqW| r�j| �ndS(Ni�ittds"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/sys/lib/python2.7/quopri.pytmain�sR#
t__main__N(t__doc__t__all__RR!RRtbinasciiRRtImportErrorRRRRRRRR/R1RRt__name__(((s/sys/lib/python2.7/quopri.pyt<module>s*
?+ ,
|