³ò
™›\Kc           @   sr  d  Z  d d k Z d d k Z d d k Z d d d d d d g Z d e i f d	 „  ƒ  YZ y d d k Z Wn e j
 o d d k Z n Xe i	 ƒ  Z
 [ d
 a d „  Z d a d „  Z d „  Z d „  Z d Z h  e d <e d <e d <e d <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.iÿÿÿÿNt   Messaget   choose_boundaryt   encodet   decodet   copyliteralt
   copybinaryc           B   sk   e  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	   getheadert   encodingheadert
   typeheadert	   parsetypet
   parseplist(   t   selft   fpt   seekable(    (    s   /usr/lib/python2.5/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
   t   Nonet   indext	   plisttextt   splitt   ranget   lent   stript   lowert   joint   typet   maintypet   subtype(   R   t   strt   it   fields(    (    s   /usr/lib/python2.5/mimetools.pyR      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   t   plistR   R   R   R   t   append(   R   R   t   endt   fR    (    (    s   /usr/lib/python2.5/mimetools.pyR   )   s    		 

0c         C   s   |  i  S(   N(   R#   (   R   (    (    s   /usr/lib/python2.5/mimetools.pyt   getplist;   s    c         C   sZ   | i  ƒ  d } t | ƒ } x7 |  i D], } | |  | j o t i | | ƒ Sq& q& Wd  S(   NR"   (   R   R   R#   R   t   unquoteR   (   R   t   namet   nt   p(    (    s   /usr/lib/python2.5/mimetools.pyt   getparam>   s    
 c         C   sU   g  } xH |  i  D]= } | i d ƒ } | d j o | i | |  i ƒ  ƒ q q W| S(   NR"   i    (   R#   t   findR$   R   (   R   t   resultR+   R    (    (    s   /usr/lib/python2.5/mimetools.pyt   getparamnamesF   s    
 c         C   s%   |  i  d  j o d Sn |  i  i ƒ  S(   Nt   7bit(   R	   R   R   (   R   (    (    s   /usr/lib/python2.5/mimetools.pyt   getencodingN   s    c         C   s   |  i  S(   N(   R   (   R   (    (    s   /usr/lib/python2.5/mimetools.pyt   gettypeS   s    c         C   s   |  i  S(   N(   R   (   R   (    (    s   /usr/lib/python2.5/mimetools.pyt   getmaintypeV   s    c         C   s   |  i  S(   N(   R   (   R   (    (    s   /usr/lib/python2.5/mimetools.pyt
   getsubtypeY   s    (   t   __name__t
   __module__t   __doc__R   R   R   R'   R,   R/   R1   R2   R3   R4   (    (    (    s   /usr/lib/python2.5/mimetools.pyR       s   									i    c          C   s(   t  i ƒ  t d 7a t }  t  i ƒ  |  S(   Ni   (   t   _counter_lockt   acquiret   _countert   release(   R.   (    (    s   /usr/lib/python2.5/mimetools.pyt   _get_next_counterj   s
    


c          C   sõ   d d k  }  t d j oÂ d d k } y | i | i ƒ  ƒ } Wn | i j
 o d } n Xy 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.iÿÿÿÿNs	   127.0.0.1t   1t   .s
   %s.%.3f.%d(   t   timet   _prefixR   t   sockett   gethostbynamet   gethostnamet   gaierrort   reprt   ost   getuidt   AttributeErrort   getpidR<   (   R?   RA   t   hostidt   uidt   pid(    (    s   /usr/lib/python2.5/mimetools.pyR   t   s"    c         C   sá   | d j o  d d k  } | i |  | ƒ Sn | d j o  d d k } | i |  | ƒ Sn | d j o  d 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   base64iÿÿÿÿNs   quoted-printablet   uuencodes
   x-uuencodet   uues   x-uueR0   t   8bits%   unknown Content-Transfer-Encoding: %s(   RN   s
   x-uuencodeRO   s   x-uue(   s   7bitRP   (	   RM   R   t   quoprit   uut   writet   readt	   decodetabt   pipethrought
   ValueError(   t   inputt   outputt   encodingRM   RQ   RR   (    (    s   /usr/lib/python2.5/mimetools.pyR   ”   s    c         C   sä   | d j o  d d k  } | i |  | ƒ Sn | d j o# d d k } | i |  | d ƒ Sn | d j o  d 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   iÿÿÿÿNs   quoted-printablei    RN   s
   x-uuencodeRO   s   x-uueR0   RP   s%   unknown Content-Transfer-Encoding: %s(   s   uuencodes
   x-uuencodes   uues   x-uue(   s   7bits   8bit(	   RM   R   RQ   RR   RS   RT   t	   encodetabRV   RW   (   RX   RY   RZ   RM   RQ   RR   (    (    s   /usr/lib/python2.5/mimetools.pyR   §   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   mmencode -u -qs   quoted-printables   mmencode -u -bRM   s   uuencode tempfiles   mmencode -qs   mmencode -bc         C   s-   t  i | d ƒ } t |  | ƒ | i ƒ  d  S(   Nt   w(   RF   t   popenR   t   close(   RX   t   commandt   pipe(    (    s   /usr/lib/python2.5/mimetools.pyt   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   mkstempRF   t   fdopenR   R^   R]   R   t   unlink(   RX   R_   RY   t   fdt   tempnamet   tempR`   (    (    s   /usr/lib/python2.5/mimetools.pyRV   Ü   s    

c         C   s/   x( |  i  ƒ  } | p Pn | i | ƒ q d  S(   N(   t   readlineRS   (   RX   RY   t   line(    (    s   /usr/lib/python2.5/mimetools.pyR   æ   s
     c         C   s8   d } x+ |  i  | ƒ } | p Pn | i | ƒ q	 d  S(   Ni    (   RT   RS   (   RX   RY   t   BUFSIZERk   (    (    s   /usr/lib/python2.5/mimetools.pyR   ì   s     (   R7   RF   R   Rc   t   __all__R    t   threadt   ImportErrort   dummy_threadt   allocate_lockR8   R:   R<   R   R@   R   R   R   t   uudecode_pipeRU   R[   Ra   RV   R   R   (    (    (    s   /usr/lib/python2.5/mimetools.pys   <module>   sJ   	W		 														
	