ó
è¾bc           @   s  d  Z  d d d d d d d d d	 d
 d d d g Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 m Z d d l
 m Z d d l
 m Z d d l
 m Z d d l
 m Z d d l m Z d d l m Z m Z d Z d Z d Z d Z d Z e j d ƒ Z e j d ƒ Z  d „  Z! d „  Z" d  „  Z# d! „  Z$ d" „  Z% e j d# e j& e j' Bƒ Z( d e* e* d$ „ Z+ d d% „ Z, d& „  Z d' „  Z d( „  Z- d) „  Z. d* „  Z/ d d d+ „ Z0 e j d, ƒ Z1 d- „  Z2 d. d/ d0 „ Z3 d S(1   s   Miscellaneous utilities.t   collapse_rfc2231_valuet   decode_paramst   decode_rfc2231t   encode_rfc2231t
   formataddrt
   formatdatet   getaddressest
   make_msgidt	   mktime_tzt	   parseaddrt	   parsedatet   parsedate_tzt   unquoteiÿÿÿÿN(   t   quote(   t   AddressList(   R   (   R
   (   R   (   t   decodestring(   t   _bencodet   _qencodes   , t    u    s   
t   's   [][\\()<>@,:;".]s	   [][\\()"]c         C   s   |  S(   N(    (   t   s(    (    s!   /usr/lib/python2.7/email/utils.pyt	   _identity:   s    c         C   s   |  s
 |  St  j |  ƒ S(   så   Decodes a base64 string.

    This function is equivalent to base64.decodestring and it's retained only
    for backward compatibility. It used to remove the last \n of the decoded
    string, if it had any (see issue 7143).
    (   t   base64R   (   R   (    (    s!   /usr/lib/python2.7/email/utils.pyt   _bdecode>   s    c         C   s.   t  j d t |  ƒ }  t  j d t |  ƒ }  |  S(   s-   Replace all line-ending characters with \r\n.s	   (?<!\r)\ns   \r(?!\n)(   t   ret   subt   CRLF(   R   (    (    s!   /usr/lib/python2.7/email/utils.pyt   fix_eolsK   s    c         C   sZ   |  \ } } | rV d } t  j | ƒ r0 d } n  t j d | ƒ } d | | | | f S| S(   s  The inverse of parseaddr(), this takes a 2-tuple of the form
    (realname, email_address) and returns the string value suitable
    for an RFC 2822 From, To or Cc header.

    If the first element of pair is false, then the second element is
    returned unmodified.
    R   t   "s   \\\g<0>s   %s%s%s <%s>(   t
   specialsret   searcht	   escapesreR   (   t   pairt   namet   addresst   quotes(    (    s!   /usr/lib/python2.7/email/utils.pyR   U   s    	c         C   s"   t  j |  ƒ } t | ƒ } | j S(   s7   Return a list of (REALNAME, EMAIL) for each fieldvalue.(   t
   COMMASPACEt   joint   _AddressListt   addresslist(   t   fieldvaluest   allt   a(    (    s!   /usr/lib/python2.7/email/utils.pyR   h   s    s_  
  =\?                   # literal =?
  (?P<charset>[^?]*?)   # non-greedy up to the next ? is the charset
  \?                    # literal ?
  (?P<encoding>[qb])    # either a "q" or a "b", case insensitive
  \?                    # literal ?
  (?P<atom>.*?)         # non-greedy up to the next ?= is the atom
  \?=                   # literal ?=
  c   	      C   sM  |  d$ k r t j ƒ  }  n  | r¨ t j |  ƒ } t j rO | d rO t j } n	 t j } t t | ƒ d ƒ \ } } | d k rˆ d } n d } d | | | d f } n$ t j |  ƒ } | rÆ d } n d	 } d
 d d d d d d d g | d | d d d d d d d d d d d d d g | d  d  | d | d! | d" | d# | f S(%   sƒ  Returns a date string as specified by RFC 2822, e.g.:

    Fri, 09 Nov 2001 01:08:47 -0000

    Optional timeval if given is a floating point time value as accepted by
    gmtime() and localtime(), otherwise the current time is used.

    Optional localtime is a flag that when True, interprets timeval, and
    returns a date relative to the local timezone instead of UTC, properly
    taking daylight savings time into account.

    Optional argument usegmt means that the timezone is written out as
    an ascii string, not numeric one (so "GMT" instead of "+0000"). This
    is needed for HTTP, and is only used when localtime==False.
    iÿÿÿÿi  i    t   -t   +s
   %s%02d%02di<   t   GMTs   -0000s"   %s, %02d %s %04d %02d:%02d:%02d %st   Mont   Tuet   Wedt   Thut   Frit   Satt   Suni   i   t   Jant   Febt   Mart   Aprt   Mayt   Junt   Jult   Augt   Sept   Octt   Novt   Deci   i   i   i   N(	   t   Nonet   timet	   localtimet   daylightt   altzonet   timezonet   divmodt   abst   gmtime(	   t   timevalRC   t   usegmtt   nowt   offsett   hourst   minutest   signt   zone(    (    s!   /usr/lib/python2.7/email/utils.pyR   |   s.    			 !c         C   sy   t  t j ƒ  d ƒ } t j ƒ  } t j d ƒ } |  d k rF d }  n
 d |  }  t j ƒ  } d | | | |  | f } | S(   sõ   Returns a string suitable for RFC 2822 compliant Message-ID, e.g:

    <142480216486.20800.16526388040877946887@nightshade.la.mastaler.com>

    Optional idstring if given is a string used to strengthen the
    uniqueness of the message id.
    id   i@   R   t   .s   <%d.%d.%d%s@%s>N(	   t   intRB   t   ost   getpidt   randomt   getrandbitsRA   t   sockett   getfqdn(   t   idstringRJ   t   pidt   randintt   idhostt   msgid(    (    s!   /usr/lib/python2.7/email/utils.pyR   ±   s    	
c         C   s   |  s
 d  St |  ƒ S(   N(   RA   t
   _parsedate(   t   data(    (    s!   /usr/lib/python2.7/email/utils.pyR
   É   s    c         C   s   |  s
 d  St |  ƒ S(   N(   RA   t   _parsedate_tz(   R`   (    (    s!   /usr/lib/python2.7/email/utils.pyR   Ï   s    c         C   s!   t  |  ƒ j } | s d S| d S(   sÆ   
    Parse addr into its constituent realname and email address parts.

    Return a tuple of realname and email address, unless the parse fails, in
    which case return a 2-tuple of ('', '').
    R   i    (   R   R   (   R&   R'   (   t   addrt   addrs(    (    s!   /usr/lib/python2.7/email/utils.pyR	   Õ   s    c         C   sƒ   t  |  ƒ d k r |  j d ƒ rS |  j d ƒ rS |  d d !j d d ƒ j d d ƒ S|  j d ƒ r |  j d ƒ r |  d d !Sn  |  S(	   s   Remove quotes from a string.i   R   iÿÿÿÿs   \\s   \s   \"t   <t   >(   t   lent
   startswitht   endswitht   replace(   t   str(    (    s!   /usr/lib/python2.7/email/utils.pyR   ã   s    #c         C   s5   |  j  t d ƒ } t | ƒ d k r1 d d |  f S| S(   s#   Decode string according to RFC 2231i   N(   t   splitt   TICKRf   RA   (   R   t   parts(    (    s!   /usr/lib/python2.7/email/utils.pyR   ï   s    c         C   sc   d d l  } | j |  d d ƒ}  | d k r= | d k r= |  S| d k rR d } n  d | | |  f S(   sÜ   Encode string according to RFC 2231.

    If neither charset nor language is given, then s is returned as-is.  If
    charset is given but not language, the string is encoded using the empty
    string for language.
    iÿÿÿÿNt   safeR   s   %s'%s'%s(   t   urllibR   RA   (   R   t   charsett   languageRo   (    (    s!   /usr/lib/python2.7/email/utils.pyR   ÷   s    	s&   ^(?P<name>\w+)\*((?P<num>[0-9]+)\*?)?$c         C   s   |  }  g  } i  } |  j  d ƒ \ } } | j | | f ƒ xÓ |  r|  j  d ƒ \ } } | j d ƒ rq t } n t } t | ƒ } t j | ƒ } | rð | j d d ƒ \ } } | d k	 rË t
 | ƒ } n  | j | g  ƒ j | | | f ƒ q> | j | d t | ƒ f ƒ q> W| rüxâ | j ƒ  D]Ñ \ } } g  } t }	 | j ƒ  xB | D]: \ } }
 } | rzt j |
 ƒ }
 t }	 n  | j |
 ƒ qMWt t j | ƒ ƒ } |	 rÞt | ƒ \ } } } | j | | | d | f f ƒ q$| j | d | f ƒ q$Wn  | S(   s   Decode parameters list according to RFC 2231.

    params is a sequence of 2-tuples containing (param name, string value).
    i    t   *R!   t   nums   "%s"N(   t   popt   appendRh   t   Truet   FalseR   t   rfc2231_continuationt   matcht   groupRA   RS   t
   setdefaultR   t   itemst   sortRo   t   EMPTYSTRINGR%   R   (   t   paramst
   new_paramst   rfc2231_paramsR!   t   valuet   encodedt   moRs   t   continuationst   extendedR   Rp   Rq   (    (    s!   /usr/lib/python2.7/email/utils.pyR   	  sD    		%!
	#Ri   s   us-asciic         C   su   t  |  t ƒ rg t |  d ƒ } |  d p, d } y t | | | ƒ SWqq t k
 rc t | | | ƒ SXn
 t |  ƒ Sd  S(   Ni   i    s   us-ascii(   t
   isinstancet   tupleR   t   unicodet   LookupError(   R‚   t   errorst   fallback_charsett   rawvalRp   (    (    s!   /usr/lib/python2.7/email/utils.pyR    >  s    (4   t   __doc__t   __all__RT   R   RB   R   RV   RX   Ro   t   warningst   email._parseaddrR   R   R&   R   R
   R_   R   Ra   t   quopriR   t   _qdecodet   email.encodersR   R   R$   R~   t   UEMPTYSTRINGR   Rl   t   compileR   R   R   R   R   R   R   t   VERBOSEt
   IGNORECASEt   ecreRA   Rw   R   R   R	   R   R   R   Rx   R   R    (    (    (    s!   /usr/lib/python2.7/email/utils.pyt   <module>   sl   				
		5						5