mς
­fIc           @   sc  d  Z  d k Z d k Z d k Z d d d d d d g Z d e i f d     YZ y d k Z Wn e j
 o d k Z n Xe i	   Z
 [ d	 a d
   Z d a d   Z d   Z d   Z d Z h  d e <d e <d e <d e <d d <d d <Z h  d d <d d <d d <d d <d d <d d <Z d   Z d   Z d   Z d   Z d S(   s<   Various tools used by MIME-reading or MIME-writing programs.Nt   Messaget   choose_boundaryt   encodet   decodet   copyliteralt
   copybinaryc           B   sk   t  Z d  Z d d  Z d   Z d   Z d   Z d   Z d   Z d   Z	 d	   Z
 d
   Z d   Z RS(   s   A derived class of rfc822.Message that knows about MIME headers and
    contains some hooks for decoding encoded and multipart messages.i   c         C   sR   t  i i |  | |  |  i d  |  _ |  i d  |  _ |  i	   |  i
   d  S(   Ns   content-transfer-encodings   content-type(   t   rfc822R    t   __init__t   selft   fpt   seekablet	   getheadert   encodingheadert
   typeheadert	   parsetypet
   parseplist(   R   R	   R
   (    (    t&   /mit/python/lib/python2.4/mimetools.pyR      s
    
c         C   sί   |  i } | d  j o
 d } n d | j o* | i d  } | | |  _ | |  } n
 d |  _ | i d  } x4 t	 t
 |   D]  } | | i   i   | | <q Wd i |  |  _ | d |  _ d i | d  |  _ d  S(   Ns
   text/plaint   ;t    t   /i    i   (   R   R   t   strt   Nonet   indext   it	   plisttextt   splitt   fieldst   ranget   lent   stript   lowert   joint   typet   maintypet   subtype(   R   R   R   R   (    (    R   R      s    	
	 c         C   sΫ   |  i } g  |  _ xΒ | d  d j o° | d } d | j o | i d  } n t |  } | |  } d | j o? | i d  } | |  i	   i
   d | | d i	   } n |  i i | i	    | | } q Wd  S(   Ni   R   t   =(   R   R   R   t   plistR   t   endR   t   fR   R   R   t   append(   R   R%   R&   R   R   (    (    R   R   )   s    		 

0c         C   s   |  i S(   N(   R   R$   (   R   (    (    R   t   getplist;   s    c         C   sZ   | i   d } t |  } x7 |  i D], } | |  | j o t i | |  Sq& q& Wd  S(   NR#   (
   t   nameR   R   t   nR   R$   t   pR   t   unquoteR   (   R   R)   R*   R+   (    (    R   t   getparam>   s    
 c         C   sU   g  } xH |  i D]= } | i d  } | d j o | i | |  i    q q W| S(   NR#   i    (   t   resultR   R$   R+   t   findR   R'   R   (   R   R   R+   R.   (    (    R   t   getparamnamesF   s    
 c         C   s%   |  i d  j o d Sn |  i i   S(   Nt   7bit(   R   R   R   R   (   R   (    (    R   t   getencodingN   s    c         C   s   |  i S(   N(   R   R    (   R   (    (    R   t   gettypeS   s    c         C   s   |  i S(   N(   R   R!   (   R   (    (    R   t   getmaintypeV   s    c         C   s   |  i S(   N(   R   R"   (   R   (    (    R   t
   getsubtypeY   s    (   t   __name__t
   __module__t   __doc__R   R   R   R(   R-   R0   R2   R3   R4   R5   (    (    (    R   R       s    									i    c          C   s(   t  i   t d 7a t }  t  i   |  S(   Ni   (   t   _counter_lockt   acquiret   _counterR.   t   release(   R.   (    (    R   t   _get_next_counterj   s     


c          C   sΜ   d k  } t d j o d k } | i | i    }  y t t i	    } Wn t j
 o d } n Xy t t i    } Wn t j
 o d } n X|  d | d | a n d t | i    t   f S(   sx  Return 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.Nt   1t   .s
   %s.%.3f.%d(   t   timet   _prefixR   t   sockett   gethostbynamet   gethostnamet   hostidt   reprt   ost   getuidt   uidt   AttributeErrort   getpidt   pidR=   (   RE   RI   RL   R@   RB   (    (    R   R   t   s       		c         C   sΨ   | d j o d k } | i |  |  Sn | d j o d k } | i |  |  Sn | d j o d k } | i |  |  Sn | d j o | i |  i    Sn | t	 j o t
 |  t	 | |  n t d
 |  d S(   sD   Decode common content-transfer-encodings (base64, quopri, uuencode).t   base64Ns   quoted-printablet   uuencodes
   x-uuencodet   uues   x-uueR1   t   8bits%   unknown Content-Transfer-Encoding: %s(   RN   s
   x-uuencodeRO   s   x-uue(   s   7bitRP   (   t   encodingRM   R   t   inputt   outputt   quoprit   uut   writet   readt	   decodetabt   pipethrought
   ValueError(   RR   RS   RQ   RU   RM   RT   (    (    R   R      s     			c         C   sΫ   | d j o d k } | i |  |  Sn | d j o  d k } | i |  | d  Sn | d j o d k } | i |  |  Sn | d j o | i |  i    Sn | t	 j o t
 |  t	 | |  n t d |  d S(   sD   Encode common content-transfer-encodings (base64, quopri, uuencode).RM   Ns   quoted-printablei    RN   s
   x-uuencodeRO   s   x-uueR1   RP   s%   unknown Content-Transfer-Encoding: %s(   s   uuencodes
   x-uuencodes   uues   x-uue(   s   7bits   8bit(   RQ   RM   R   RR   RS   RT   RU   RV   RW   t	   encodetabRY   RZ   (   RR   RS   RQ   RU   RM   RT   (    (    R   R   €   s     			sa   (
TEMP=/tmp/@uu.$$
sed "s%^begin [0-7][0-7]* .*%begin 600 $TEMP%" | uudecode
cat $TEMP
rm $TEMP
)RN   s
   x-uuencodeRO   s   x-uues   quoted-printables   mmencode -u -qRM   s   mmencode -u -bs   uuencode tempfiles   mmencode -qs   mmencode -bc         C   s-   t  i | d  } t |  |  | i   d  S(   Nt   w(   RG   t   popent   commandt   pipeR   RR   t   close(   RR   R^   R_   (    (    R   t   pipetoΤ   s    c         C   s}   t  i   \ } } t i | d  } t |  |  | i	   t i
 | d | d  } t | |  | i	   t i |  d  S(   NR\   s    <t   r(   t   tempfilet   mkstempt   fdt   tempnameRG   t   fdopent   tempR   RR   R`   R]   R^   R_   R   RS   t   unlink(   RR   R^   RS   Rh   R_   Re   Rf   (    (    R   RY   Ω   s    

c         C   s1   x* |  i   } | p Pn | i |  q Wd  S(   Ni   (   RR   t   readlinet   lineRS   RV   (   RR   RS   Rk   (    (    R   R   γ   s       c         C   s:   d } x- |  i |  } | p Pn | i |  q	 Wd  S(   Ni    i   (   t   BUFSIZERR   RW   Rk   RS   RV   (   RR   RS   Rk   Rl   (    (    R   R   ι   s       (   R8   RG   R   Rc   t   __all__R    t   threadt   ImportErrort   dummy_threadt   allocate_lockR9   R;   R=   R   RA   R   R   R   t   uudecode_pipeRX   R[   Ra   RY   R   R   (   RX   RY   R9   R[   R   Ra   Rr   Rm   Rc   R   R   R=   R   R   Rn   R   R    RG   (    (    R   t   ?   s0   			W				<	<			
	