
bc           @   sd  d  Z  d d d d g Z d d l Z d d l Z d Z d Z d	 Z d
 d d d d d d d d d d d d d d d d d d d d d d d  g Z d! d" d# d$ d% d& d' g Z i d( d) 6d( d* 6d( d+ 6d( d, 6d- d. 6d/ d0 6d1 d2 6d- d3 6d4 d5 6d1 d6 6d7 d8 6d4 d9 6d: d; 6d7 d< 6Z	 d=   Z
 d>   Z d?   Z d@   Z dA f  dB     YZ dC e f dD     YZ d S(E   sc   Email address parsing code.

Lifted directly from rfc822.py.  This should eventually be rewritten.
t	   mktime_tzt	   parsedatet   parsedate_tzt   quoteiNt    t    s   , t   jant   febt   mart   aprt   mayt   junt   jult   augt   sept   octt   novt   dect   januaryt   februaryt   marcht   aprilt   junet   julyt   augustt	   septembert   octobert   novembert   decembert   mont   tuet   wedt   thut   frit   satt   suni    t   UTt   UTCt   GMTt   Zipt   ASTit   ADTit   ESTt   EDTit   CSTt   CDTiDt   MSTt   MDTit   PSTt   PDTc      
   C   s  |  j    }  |  d j d  s5 |  d j   t k r? |  d =n8 |  d j d  } | d k rw |  d | d |  d <n  t |   d k r |  d j  d  } t |  d k r | |  d }  q n  t |   d k r(|  d } | j d  } | d k r| |  | | d g |  d )q(|  j d  n  t |   d	 k  r>d S|  d	  }  |  \ } } } } } | j   } | t	 k r| | j   } } | t	 k rd Sn  t	 j
 |  d } | d
 k r| d
 8} n  | d d k r| d  } n  | j d  } | d k r| | } } n  | d d k r,| d  } n  | d j   sL| | } } n  | d d k ri| d  } n  | j  d  } t |  d k r| \ }	 }
 d } n( t |  d k r| \ }	 }
 } n d Sy@ t |  } t |  } t |	  }	 t |
  }
 t |  } Wn t k
 rd SX| d k  rN| d k rA| d 7} qN| d 7} n  d } | j   } | t k ryt | } n$ y t |  } Wn t k
 rn X| r| d k  rd } | } n d } | | d d | d d } n  | | | |	 |
 | d d d | f
 S(   sQ   Convert a date string to a time tuple.

    Accounts for military timezones.
    i    t   ,i   i   t   -i   t   +R   i   i   it   :i   t   0id   iD   il  i  i  i<   N(   t   splitt   endswitht   lowert	   _daynamest   rfindt   lent   findt   appendt   Nonet   _monthnamest   indext   isdigitt   intt
   ValueErrort   uppert
   _timezones(   t   datat   it   stufft   st   ddt   mmt   yyt   tmt   tzt   thht   tmmt   tsst   tzoffsett   tzsign(    (    s&   /usr/lib/python2.7/email/_parseaddr.pyR   -   s    )


	
!c         C   s+   t  |   } t | t  r# | d  S| Sd S(   s&   Convert a time string to a time tuple.i	   N(   R   t
   isinstancet   tuple(   RG   t   t(    (    s&   /usr/lib/python2.7/email/_parseaddr.pyR      s    c         C   sD   |  d d k r% t j |  d  d  St j |   } | |  d Sd S(   sE   Turn a 10-tuple as returned by parsedate_tz() into a POSIX timestamp.i	   i   iN(   i(   R?   t   timet   mktimet   calendart   timegm(   RG   RW   (    (    s&   /usr/lib/python2.7/email/_parseaddr.pyR       s    c         C   s   |  j  d d  j  d d  S(   s   Prepare string to be used in a quoted string.

    Turns backslash and double quote characters into quoted pairs.  These
    are the only characters that need to be quoted inside a quoted string.
    Does not add the surrounding double quotes.
    s   \s   \\t   "s   \"(   t   replace(   t   str(    (    s&   /usr/lib/python2.7/email/_parseaddr.pyR      s    t   AddrlistClassc           B   s   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 e
 d  Z d	   Z d
   Z d   Z d d  Z d   Z RS(   s   Address parser class by Ben Escoto.

    To understand what this class does, it helps to have a copy of RFC 2822 in
    front of you.

    Note: this class interface is deprecated and may be removed in the future.
    Use rfc822.AddressList instead.
    c         C   s   d |  _  d |  _ d |  _ d |  _ |  j |  j |  _ |  j  |  j |  j |  _ |  j j d d  |  _ | |  _ g  |  _	 d S(   s   Initialize a new instance.

        `field' is an unparsed address header field, containing
        one or more addresses.
        s   ()<>@,:;."[]i    s    	s   
t   .R   N(
   t   specialst   post   LWSt   CRt   FWSt   atomendsR]   t
   phraseendst   fieldt   commentlist(   t   selfRh   (    (    s&   /usr/lib/python2.7/email/_parseaddr.pyt   __init__   s    					c         C   s   x{ |  j  t |  j  k  r} |  j |  j  |  j d k rJ |  j  d 7_  q |  j |  j  d k ry |  j j |  j    q Pq Wd S(   s*   Parse up to the start of the next address.s   
i   t   (N(   Rb   R<   Rh   Rc   Ri   R>   t
   getcomment(   Rj   (    (    s&   /usr/lib/python2.7/email/_parseaddr.pyt   gotonext   s    c         C   sU   g  } xH |  j  t |  j  k  rP |  j   } | r@ | | 7} q	 | j d  q	 W| S(   sV   Parse all addresses.

        Returns a list containing all of the addresses.
        R   (   R   R   (   Rb   R<   Rh   t
   getaddressR>   (   Rj   t   resultt   ad(    (    s&   /usr/lib/python2.7/email/_parseaddr.pyt   getaddrlist   s    c         C   s  g  |  _  |  j   |  j } |  j  } |  j   } |  j   g  } |  j t |  j  k r | rPt j |  j   | d f g } qPn|  j |  j d k r | |  _ | |  _  |  j   } t j |  j   | f g } nz|  j |  j d k rg  } t |  j  } |  j d 7_ x=|  j t |  j  k  r|  j   |  j | k  rm|  j |  j d k rm|  j d 7_ Pn  | |  j	   } qWn |  j |  j d k r|  j
   } |  j  rt j |  d d j |  j   d	 | f g } qPt j |  | f g } nS | r%t j |  j   | d f g } n+ |  j |  j |  j k rP|  j d 7_ n  |  j   |  j t |  j  k  r|  j |  j d
 k r|  j d 7_ n  | S(   s   Parse the next address.i    s   .@R5   i   t   ;t   <s    (R   t   )R2   (   Ri   Rn   Rb   t   getphraselistR<   Rh   t   SPACEt   joint   getaddrspecRo   t   getrouteaddrRa   (   Rj   t   oldpost   oldclt   plistt
   returnlistt   addrspect   fieldlent	   routeaddr(    (    s&   /usr/lib/python2.7/email/_parseaddr.pyRo      sL    	
		
%		
%	3"
.c         C   s   |  j  |  j d k r d St } |  j d 7_ |  j   d } x |  j t |  j   k  r| rs |  j   t } n |  j  |  j d k r |  j d 7_ Pnr |  j  |  j d k r |  j d 7_ t } nD |  j  |  j d k r |  j d 7_ n |  j   } |  j d 7_ P|  j   qB W| S(   s   Parse a route address (Return-path value).

        This method just skips all the route stuff and returns the addrspec.
        Rt   Ni   R   t   >t   @R5   (   Rh   Rb   t   FalseRn   R<   t	   getdomaint   TrueRy   (   Rj   t   expectroutet   adlist(    (    s&   /usr/lib/python2.7/email/_parseaddr.pyRz     s.    

		c         C   s\  g  } |  j    x |  j t |  j  k  r |  j |  j d k r` | j d  |  j d 7_ nf |  j |  j d k r | j d t |  j     n0 |  j |  j |  j k r Pn | j |  j    |  j    q W|  j t |  j  k s|  j |  j d k rt	 j
 |  S| j d  |  j d 7_ |  j    |  j   } | sKt	 St	 j
 |  | S(   s   Parse an RFC 2822 addr-spec.R`   i   R\   s   "%s"R   (   Rn   Rb   R<   Rh   R>   R   t   getquoteRf   t   getatomt   EMPTYSTRINGRx   R   (   Rj   t   aslistt   domain(    (    s&   /usr/lib/python2.7/email/_parseaddr.pyRy   <  s*    
 .
c         C   s7  g  } x!|  j  t |  j  k  r)|  j |  j  |  j k rL |  j  d 7_  q	 |  j |  j  d k r{ |  j j |  j    q	 |  j |  j  d k r | j |  j    q	 |  j |  j  d k r |  j  d 7_  | j d  q	 |  j |  j  d k r t S|  j |  j  |  j	 k rPq	 | j |  j
    q	 Wt j |  S(   s-   Get the complete domain name from an address.i   Rl   t   [R`   R   (   Rb   R<   Rh   Rc   Ri   R>   Rm   t   getdomainliteralR   Rf   R   Rx   (   Rj   t   sdlist(    (    s&   /usr/lib/python2.7/email/_parseaddr.pyR   Z  s"    c         C   s-  |  j  |  j | k r d Sd g } t } |  j d 7_ x |  j t |  j   k  r| ry | j |  j  |  j  t } n |  j  |  j | k r |  j d 7_ Pnk | r |  j  |  j d k r | j |  j    q; n6 |  j  |  j d k r t } n | j |  j  |  j  |  j d 7_ q; Wt j |  S(   s  Parse a header fragment delimited by special characters.

        `beginchar' is the start character for the fragment.
        If self is not looking at an instance of `beginchar' then
        getdelimited returns the empty string.

        `endchars' is a sequence of allowable end-delimiting characters.
        Parsing stops when one of these is encountered.

        If `allowcomments' is non-zero, embedded RFC 2822 comments are allowed
        within the parsed fragment.
        R   i   Rl   s   \(	   Rh   Rb   R   R<   R>   Rm   R   R   Rx   (   Rj   t	   beginchart   endcharst   allowcommentst   slistR   (    (    s&   /usr/lib/python2.7/email/_parseaddr.pyt   getdelimitedq  s(    			c         C   s   |  j  d d t  S(   s1   Get a quote-delimited fragment from self's field.R\   s   "(   R   R   (   Rj   (    (    s&   /usr/lib/python2.7/email/_parseaddr.pyR     s    c         C   s   |  j  d d t  S(   s7   Get a parenthesis-delimited fragment from self's field.Rl   s   )(   R   R   (   Rj   (    (    s&   /usr/lib/python2.7/email/_parseaddr.pyRm     s    c         C   s   d |  j  d d t  S(   s!   Parse an RFC 2822 domain-literal.s   [%s]R   s   ](   R   R   (   Rj   (    (    s&   /usr/lib/python2.7/email/_parseaddr.pyR     s    c         C   s   d g } | d k r! |  j } n  x\ |  j t |  j  k  r |  j |  j | k rV Pn | j |  j |  j  |  j d 7_ q$ Wt j |  S(   s  Parse an RFC 2822 atom.

        Optional atomends specifies a different set of end token delimiters
        (the default is to use self.atomends).  This is used e.g. in
        getphraselist() since phrase endings must not include the `.' (which
        is legal in phrases).R   i   N(   R?   Rf   Rb   R<   Rh   R>   R   Rx   (   Rj   Rf   t   atomlist(    (    s&   /usr/lib/python2.7/email/_parseaddr.pyR     s    	c         C   s   g  } x |  j  t |  j  k  r |  j |  j  |  j k rL |  j  d 7_  q	 |  j |  j  d k rx | j |  j    q	 |  j |  j  d k r |  j j |  j    q	 |  j |  j  |  j k r Pq	 | j |  j	 |  j   q	 W| S(   s   Parse a sequence of RFC 2822 phrases.

        A phrase is a sequence of words, which are in turn either RFC 2822
        atoms or quoted-strings.  Phrases are canonicalized by squeezing all
        runs of continuous whitespace into one space.
        i   R\   Rl   (
   Rb   R<   Rh   Re   R>   R   Ri   Rm   Rg   R   (   Rj   R}   (    (    s&   /usr/lib/python2.7/email/_parseaddr.pyRv     s    N(   t   __name__t
   __module__t   __doc__Rk   Rn   Rr   Ro   Rz   Ry   R   R   R   R   Rm   R   R?   R   Rv   (    (    (    s&   /usr/lib/python2.7/email/_parseaddr.pyR_      s   		
		;	 		%			t   AddressListc           B   sM   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   s@   An AddressList encapsulates a list of parsed RFC 2822 addresses.c         C   s5   t  j |  |  | r( |  j   |  _ n	 g  |  _ d  S(   N(   R_   Rk   Rr   t   addresslist(   Rj   Rh   (    (    s&   /usr/lib/python2.7/email/_parseaddr.pyRk     s    c         C   s   t  |  j  S(   N(   R<   R   (   Rj   (    (    s&   /usr/lib/python2.7/email/_parseaddr.pyt   __len__  s    c         C   sS   t  d   } |  j | _ x3 | j D]( } | |  j k r# | j j |  q# q# W| S(   N(   R   R?   R   R>   (   Rj   t   othert   newaddrt   x(    (    s&   /usr/lib/python2.7/email/_parseaddr.pyt   __add__  s    c         C   s:   x3 | j  D]( } | |  j  k r
 |  j  j |  q
 q
 W|  S(   N(   R   R>   (   Rj   R   R   (    (    s&   /usr/lib/python2.7/email/_parseaddr.pyt   __iadd__  s    c         C   sF   t  d   } x3 |  j D]( } | | j k r | j j |  q q W| S(   N(   R   R?   R   R>   (   Rj   R   R   R   (    (    s&   /usr/lib/python2.7/email/_parseaddr.pyt   __sub__  s
    c         C   s:   x3 | j  D]( } | |  j  k r
 |  j  j |  q
 q
 W|  S(   N(   R   t   remove(   Rj   R   R   (    (    s&   /usr/lib/python2.7/email/_parseaddr.pyt   __isub__  s    c         C   s   |  j  | S(   N(   R   (   Rj   RA   (    (    s&   /usr/lib/python2.7/email/_parseaddr.pyt   __getitem__  s    (
   R   R   R   Rk   R   R   R   R   R   R   (    (    (    s&   /usr/lib/python2.7/email/_parseaddr.pyR     s   							(   R   t   __all__RX   RZ   Rw   R   t
   COMMASPACER@   R:   RF   R   R   R    R   R_   R   (    (    (    s&   /usr/lib/python2.7/email/_parseaddr.pyt   <module>   s4   		b			
	
 "