Plan 9 from Bell Labs’s /usr/web/sources/contrib/bichued/root/sys/lib/python/mimetools.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�
��c@srdZddkZddkZddkZddddddgZdeifd	��YZyddkZWnej
oddkZnXei	�Z
[d
ad�Zdad�Zd
�Zd�ZdZhed<ed<ed<ed<dd<dd<Zhdd<dd<dd<dd<dd<dd<Zd�Zd�Zd�Zd�ZdS(s<Various tools used by MIME-reading or MIME-writing programs.i�NtMessagetchoose_boundarytencodetdecodetcopyliteralt
copybinarycBskeZdZdd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�ZRS(s�A derived class of rfc822.Message that knows about MIME headers and
    contains some hooks for decoding encoded and multipart messages.icCsRtii|||�|id�|_|id�|_|i�|i�dS(Nscontent-transfer-encodingscontent-type(trfc822Rt__init__t	getheadertencodingheadert
typeheadert	parsetypet
parseplist(tselftfptseekable((s/sys/lib/python/mimetools.pyRs

cCs�|i}|djo
d}nd|jo*|id�}|||_|| }n
d|_|id�}x4tt|��D] }||i�i�||<q�Wdi	|�|_
|d|_di	|d�|_dS(Ns
text/plaint;tt/ii(
R
tNonetindext	plisttexttsplittrangetlentstriptlowertjointtypetmaintypetsubtype(R
tstrtitfields((s/sys/lib/python/mimetools.pyRs	



	
cCs�|i}g|_x�|d djo�|d}d|jo|id�}n
t|�}|| }d|jo?|id�}|| i�i�d||di�}n|ii|i��||}qWdS(NiRt=(RtplistRRRRtappend(R
RtendtfR ((s/sys/lib/python/mimetools.pyR)s		



0cCs|iS(N(R#(R
((s/sys/lib/python/mimetools.pytgetplist;scCsZ|i�d}t|�}x7|iD],}|| |joti||�Sq&q&WdS(NR"(RRR#RtunquoteR(R
tnametntp((s/sys/lib/python/mimetools.pytgetparam>s
cCsUg}xH|iD]=}|id�}|djo|i|| i��qqW|S(NR"i(R#tfindR$R(R
tresultR+R ((s/sys/lib/python/mimetools.pyt
getparamnamesFs

cCs%|idjodSn|ii�S(Nt7bit(R	RR(R
((s/sys/lib/python/mimetools.pytgetencodingNscCs|iS(N(R(R
((s/sys/lib/python/mimetools.pytgettypeSscCs|iS(N(R(R
((s/sys/lib/python/mimetools.pytgetmaintypeVscCs|iS(N(R(R
((s/sys/lib/python/mimetools.pyt
getsubtypeYs(
t__name__t
__module__t__doc__RRRR'R,R/R1R2R3R4(((s/sys/lib/python/mimetools.pyRs									icCs(ti�td7at}ti�|S(Ni(t
_counter_locktacquiret_countertrelease(R.((s/sys/lib/python/mimetools.pyt_get_next_counterjs



cCs�ddk}tdjo�ddk}y|i|i��}Wn|ij
o
d}nXytti	��}Wnt
j
o
d}nXytti��}Wnt
j
o
d}nX|d|d|andt|i�t�fS(sxReturn a string usable as a multipart boundary.

    The string chosen is unique within a single program run, and
    incorporates the user id (if available), process id (if available),
    and current time.  So it's very unlikely the returned string appears
    in message text, but there's no guarantee.

    The boundary contains dots so you have to quote it in the header.i�Ns	127.0.0.1t1t.s
%s.%.3f.%d(
ttimet_prefixRtsockett
gethostbynametgethostnametgaierrortreprtostgetuidtAttributeErrortgetpidR<(R?RAthostidtuidtpid((s/sys/lib/python/mimetools.pyRts"
cCs�|djo ddk}|i||�Sn|djo ddk}|i||�Sn|djo ddk}|i||�Sn|d
jo|i|i��Sn|tjot|t||�ntd|�dS(sDDecode common content-transfer-encodings (base64, quopri, uuencode).tbase64i�Nsquoted-printabletuuencodes
x-uuencodetuuesx-uueR0t8bits%unknown Content-Transfer-Encoding: %s(RNs
x-uuencodeROsx-uue(s7bitRP(	RMRtquoprituutwritetreadt	decodetabtpipethrought
ValueError(tinputtoutputtencodingRMRQRR((s/sys/lib/python/mimetools.pyR�s




cCs�|djo ddk}|i||�Sn|djo#ddk}|i||d�Sn|d
jo ddk}|i||�Sn|djo|i|i��Sn|tjot|t||�ntd|�dS(sDEncode common content-transfer-encodings (base64, quopri, uuencode).RMi�Nsquoted-printableiRNs
x-uuencodeROsx-uueR0RPs%unknown Content-Transfer-Encoding: %s(suuencodes
x-uuencodesuuesx-uue(s7bits8bit(	RMRRQRRRSRTt	encodetabRVRW(RXRYRZRMRQRR((s/sys/lib/python/mimetools.pyR�s




sa(
TEMP=/tmp/@uu.$$
sed "s%^begin [0-7][0-7]* .*%begin 600 $TEMP%" | uudecode
cat $TEMP
rm $TEMP
)RNs
x-uuencodeROsx-uuesmmencode -u -qsquoted-printablesmmencode -u -bRMsuuencode tempfilesmmencode -qsmmencode -bcCs-ti|d�}t||�|i�dS(Ntw(RFtpopenRtclose(RXtcommandtpipe((s/sys/lib/python/mimetools.pytpipeto�s
cCs}ti�\}}ti|d�}t||�|i�ti|d|d�}t||�|i�ti|�dS(NR\s <tr(	ttempfiletmkstempRFtfdopenRR^R]Rtunlink(RXR_RYtfdttempnamettempR`((s/sys/lib/python/mimetools.pyRV�s



cCs/x(|i�}|pPn|i|�qdS(N(treadlineRS(RXRYtline((s/sys/lib/python/mimetools.pyR�scCs8d}x+|i|�}|pPn|i|�q	dS(Ni (RTRS(RXRYtBUFSIZERk((s/sys/lib/python/mimetools.pyR�s
(R7RFRRct__all__RtthreadtImportErrortdummy_threadt
allocate_lockR8R:R<RR@RRRt
uudecode_pipeRUR[RaRVRR(((s/sys/lib/python/mimetools.pys<module>sJ	W		 														
	

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.