ó
è¾bc           @   sÆ  d  Z  d d l Z d d l Z d d l Z d d l m Z m Z e ƒ  - e j rf e d d e ƒ n  d d l	 Z	 Wd QXd d l m
 Z
 e
 d d d	 ƒd
 d d d d d g Z d
 e	 j f d „  ƒ  YZ y d d l Z Wn e k
 rø d d l Z n Xe j ƒ  Z [ d a d „  Z d a d „  Z d „  Z d „  Z d Z i e d 6e d 6e d 6e d 6d d 6d d 6Z i d d 6d d 6d d 6d d 6d  d 6d! d 6Z d" „  Z d# „  Z d$ „  Z d% „  Z d S(&   s<   Various tools used by MIME-reading or MIME-writing programs.iÿÿÿÿN(   t   filterwarningst   catch_warningst   ignores   .*rfc822 has been removed(   t   warnpy3ks@   in 3.x, mimetools has been removed in favor of the email packaget
   stackleveli   t   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  j j |  | | ƒ |  j d ƒ |  _ |  j d ƒ |  _ |  j ƒ  |  j ƒ  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.7/mimetools.pyR      s
    
c         C   sÛ   |  j  } | d  k r d } n  d | k rS | j d ƒ } | | |  _ | |  } n	 d |  _ | j d ƒ } x4 t t | ƒ ƒ D]  } | | j ƒ  j ƒ  | | <q~ Wd j	 | ƒ |  _
 | d |  _ d j	 | 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.7/mimetools.pyR   !   s    			c         C   sÕ   |  j  } g  |  _ x¼ | d  d k rÐ | d } d | k rM | j d ƒ } n t | ƒ } | |  } d | k r­ | j d ƒ } | |  j ƒ  j ƒ  d | | d j ƒ  } n  |  j j | j ƒ  ƒ | | } q Wd  S(   Ni   R   t   =(   R   t   plistR   R   R   R   t   append(   R   R$   t   endt   fR%   (    (    s   /usr/lib/python2.7/mimetools.pyR   2   s    		

/c         C   s   |  j  S(   N(   R(   (   R   (    (    s   /usr/lib/python2.7/mimetools.pyt   getplistD   s    c         C   sU   | j  ƒ  d } t | ƒ } x2 |  j D]' } | |  | k r& t j | | ƒ Sq& Wd  S(   NR'   (   R   R   R(   R   t   unquoteR   (   R   t   namet   nt   p(    (    s   /usr/lib/python2.7/mimetools.pyt   getparamG   s    c         C   sS   g  } xF |  j  D]; } | j d ƒ } | d k r | j | |  j ƒ  ƒ q q W| S(   NR'   i    (   R(   t   findR)   R   (   R   t   resultR0   R%   (    (    s   /usr/lib/python2.7/mimetools.pyt   getparamnamesO   s    c         C   s    |  j  d  k r d S|  j  j ƒ  S(   Nt   7bit(   R   R   R   (   R   (    (    s   /usr/lib/python2.7/mimetools.pyt   getencodingW   s    c         C   s   |  j  S(   N(   R!   (   R   (    (    s   /usr/lib/python2.7/mimetools.pyt   gettype\   s    c         C   s   |  j  S(   N(   R"   (   R   (    (    s   /usr/lib/python2.7/mimetools.pyt   getmaintype_   s    c         C   s   |  j  S(   N(   R#   (   R   (    (    s   /usr/lib/python2.7/mimetools.pyt
   getsubtypeb   s    (   t   __name__t
   __module__t   __doc__R   R   R   R,   R1   R4   R6   R7   R8   R9   (    (    (    s   /usr/lib/python2.7/mimetools.pyR      s   									i    c          C   s(   t  j ƒ  t d 7a t }  t  j ƒ  |  S(   Ni   (   t   _counter_lockt   acquiret   _countert   release(   R3   (    (    s   /usr/lib/python2.7/mimetools.pyt   _get_next_counters   s
    


c          C   sí   d d l  }  t d k rÓ d d l } y | j | j ƒ  ƒ } Wn | j k
 rY d } n Xy t t j	 ƒ  ƒ } Wn t
 k
 r‰ d } n Xy t t j ƒ  ƒ } Wn t
 k
 r¹ d } n X| d | d | a n  d t |  j  ƒ  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   getpidRA   (   RD   RF   t   hostidt   uidt   pid(    (    s   /usr/lib/python2.7/mimetools.pyR   }   s"    


c         C   sË   | d k r( d d l  } | j |  | ƒ S| d k rP d d l } | j |  | ƒ S| d k rx d d l } | j |  | ƒ S| d k r— | j |  j ƒ  ƒ S| t k rº 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-uueR5   t   8bits%   unknown Content-Transfer-Encoding: %s(   RS   s
   x-uuencodeRT   s   x-uue(   R5   RU   (	   RR   R   t   quoprit   uut   writet   readt	   decodetabt   pipethrought
   ValueError(   t   inputt   outputt   encodingRR   RV   RW   (    (    s   /usr/lib/python2.7/mimetools.pyR      s    c         C   sÎ   | d k r( d d l  } | j |  | ƒ S| d k rS d d l } | j |  | d ƒ S| d k r{ d d l } | j |  | ƒ S| d k rš | j |  j ƒ  ƒ S| t k r½ t |  t | | ƒ n t d | ‚ d S(   sD   Encode common content-transfer-encodings (base64, quopri, uuencode).RR   iÿÿÿÿNs   quoted-printablei    RS   s
   x-uuencodeRT   s   x-uueR5   RU   s%   unknown Content-Transfer-Encoding: %s(   RS   s
   x-uuencodeRT   s   x-uue(   R5   RU   (	   RR   R   RV   RW   RX   RY   t	   encodetabR[   R\   (   R]   R^   R_   RR   RV   RW   (    (    s   /usr/lib/python2.7/mimetools.pyR   °   s    sa   (
TEMP=/tmp/@uu.$$
sed "s%^begin [0-7][0-7]* .*%begin 600 $TEMP%" | uudecode
cat $TEMP
rm $TEMP
)RS   s
   x-uuencodeRT   s   x-uues   mmencode -u -qs   quoted-printables   mmencode -u -bRR   s   uuencode tempfiles   mmencode -qs   mmencode -bc         C   s-   t  j | d ƒ } t |  | ƒ | j ƒ  d  S(   Nt   w(   RK   t   popenR	   t   close(   R]   t   commandt   pipe(    (    s   /usr/lib/python2.7/mimetools.pyt   pipetoà   s    c         C   s}   t  j ƒ  \ } } t j | d ƒ } t |  | ƒ | j ƒ  t j | d | d ƒ } t | | ƒ | j ƒ  t j | ƒ d  S(   NRa   s    <t   r(	   t   tempfilet   mkstempRK   t   fdopenR	   Rc   Rb   R
   t   unlink(   R]   Rd   R^   t   fdt   tempnamet   tempRe   (    (    s   /usr/lib/python2.7/mimetools.pyR[   å   s    

c         C   s.   x' |  j  ƒ  } | s Pn  | j | ƒ q Wd  S(   N(   t   readlineRX   (   R]   R^   t   line(    (    s   /usr/lib/python2.7/mimetools.pyR	   ï   s
     c         C   s7   d } x* |  j  | ƒ } | s" Pn  | j | ƒ q	 Wd  S(   Ni    (   RY   RX   (   R]   R^   t   BUFSIZERp   (    (    s   /usr/lib/python2.7/mimetools.pyR
   õ   s     (    R<   RK   t   sysRh   t   warningsR    R   t   py3kwarningt   DeprecationWarningR   R   t   __all__R   t   threadt   ImportErrort   dummy_threadt   allocate_lockR=   R?   RA   R   RE   R   R   R   t   uudecode_pipeRZ   R`   Rf   R[   R	   R
   (    (    (    s   /usr/lib/python2.7/mimetools.pyt   <module>   sZ   
			W		 		

		
	