ó
ăĂVc           @   sČ   d  Z  d g Z d d l Z d d l m Z d d l m Z e j d  Z e j d  Z e j d  Z	 e j d  Z
 e j d	  Z d
 Z d Z e   Z d e f d     YZ d d d     YZ d S(   s  FeedParser - An email feed parser.

The feed parser implements an interface for incrementally parsing an email
message, line by line.  This has advantages for certain applications, such as
those reading email messages off a socket.

FeedParser.feed() is the primary interface for pushing new data into the
parser.  It returns when there's nothing more it can do with the available
data.  When you have no more data to push into the parser, call .close().
This completes the parsing and returns the root message object.

The other advantage of this parser is that it will never raise a parsing
exception.  Instead, when it finds something unexpected, it adds a 'defect' to
the current message.  Defects are just instances that live on the message
object's .defects attribute.
t
   FeedParseri˙˙˙˙N(   t   errors(   t   messages   
||
s   (
||
)s
   (
||
)\Zs(   ^(From |[\041-\071\073-\176]{1,}:|[\t ])t    s   
t   BufferedSubFilec           B   sz   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z
 d
   Z d   Z d   Z RS(   sk  A file-ish object that can have new data loaded into it.

    You can also push and pop line-matching predicates onto a stack.  When the
    current predicate matches the current line, a false EOF response
    (i.e. empty string) is returned instead.  This lets the parser adhere to a
    simple abstraction -- it parses until EOF closes the current message.
    c         C   s(   g  |  _  g  |  _ g  |  _ t |  _ d  S(   N(   t   _partialt   _linest	   _eofstackt   Falset   _closed(   t   self(    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyt   __init__3   s    			c         C   s   |  j  j |  d  S(   N(   R   t   append(   R
   t   pred(    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyt   push_eof_matcher=   s    c         C   s   |  j  j   S(   N(   R   t   pop(   R
   (    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyt   pop_eof_matcher@   s    c         C   s8   |  j  d j |  j  j t   g  |  _ t |  _ d  S(   NR   (   t	   pushlinest   joinR   t
   splitlinest   TrueR	   (   R
   (    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyt   closeC   s    "	c         C   sn   |  j  s |  j r d St S|  j  j   } x> |  j d  d  d  D]& } | |  r@ |  j  j |  d Sq@ W| S(   NR   i˙˙˙˙(   R   R	   t   NeedMoreDataR   R   R   (   R
   t   linet   ateof(    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyt   readlineI   s    		c         C   s   |  j  j |  d  S(   N(   R   R   (   R
   R   (    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyt
   unreadline[   s    c         C   sż   | j  t  } | s* | d j d  r= |  j | 7_ d S|  j r |  j j | d  d j |  j  j  t  | d d +|  j 2n  | d j d  sŽ | j   g |  _ n  |  j |  d S(	   s$   Push some new data into this object.i    s   
s   NR   i   i˙˙˙˙(   s   
s   (   R   R   t   endswithR   R   R   R   R   (   R
   t   datat   parts(    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyt   push`   s    	"
c         C   s˝   t  j t  } | j   |  _ |  j r` | r` | d j d  r` | j d  | j   |  _ n  g  } xC t t |  d  D]+ } | j | | d | | d d  q} W|  j	 |  d  S(   Ni˙˙˙˙s   iţ˙˙˙i   i   (
   t   NLCRE_crackt   splitR   R   R   R   t   ranget   lenR   R   (   R
   t   linesR   t   i(    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyR   x   s    #)c         C   s   | d  d  d  |  j  d *d  S(   Ni˙˙˙˙i    (   R   (   R
   R#   (    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyR      s    c         C   s   |  j  S(   N(   R	   (   R
   (    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyt	   is_closed   s    c         C   s   |  S(   N(    (   R
   (    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyt   __iter__   s    c         C   s%   |  j    } | d k r! t  n  | S(   NR   (   R   t   StopIteration(   R
   R   (    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyt   next   s    	(   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R   R   R%   R&   R(   (    (    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyR   +   s   	
										c           B   se   e  Z d  Z e j d  Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z d	   Z RS(
   s   A feed-style parser of email.c         C   sO   | |  _  t   |  _ g  |  _ |  j   j |  _ d |  _ d |  _	 t
 |  _ d S(   s@   _factory is called with no arguments to create a new message objN(   t   _factoryR   t   _inputt	   _msgstackt	   _parsegenR(   t   _parset   Nonet   _curt   _lastR   t   _headersonly(   R
   R,   (    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyR   Ą   s    				c         C   s   t  |  _ d  S(   N(   R   R4   (   R
   (    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyt   _set_headersonlyŹ   s    c         C   s   |  j  j |  |  j   d S(   s   Push more data into the parser.N(   R-   R   t   _call_parse(   R
   R   (    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyt   feedŻ   s    c         C   s&   y |  j    Wn t k
 r! n Xd  S(   N(   R0   R'   (   R
   (    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyR6   ´   s    c         C   s_   |  j  j   |  j   |  j   } | j   d k r[ | j   r[ | j j t j	    n  | S(   s<   Parse all remaining data and return the root message object.t	   multipart(
   R-   R   R6   t   _pop_messaget   get_content_maintypet   is_multipartt   defectsR   R   t!   MultipartInvariantViolationDefect(   R
   t   root(    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyR   ş   s    
c         C   s   |  j    } |  j r: |  j j   d k r: | j d  n  |  j rZ |  j d j |  n  |  j j |  | |  _ | |  _ d  S(   Ns   multipart/digests   message/rfc822i˙˙˙˙(   R,   R2   t   get_content_typet   set_default_typeR.   t   attachR   R3   (   R
   t   msg(    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyt   _new_messageĆ   s    		c         C   s8   |  j  j   } |  j  r+ |  j  d |  _ n	 d  |  _ | S(   Ni˙˙˙˙(   R.   R   R2   R1   (   R
   t   retval(    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyR9   Đ   s
    		c         c   s  |  j    g  } xj |  j D]_ } | t k r7 t Vq n  t j |  sl t j |  sh |  j j |  n  Pn  | j |  q W|  j |  |  j	 rg  } xM t
 rč |  j j   } | t k rČ t Vq n  | d k rŘ Pn  | j |  q W|  j j t j |   d  S|  j j   d k rxí t
 r
|  j j t j  x, |  j   D] } | t k rat VqDn  PqDW|  j   } |  j j   x1 t
 r˛|  j j   } | t k rŽt Vqn  PqWx1 t
 rć|  j j   } | t k rât Vqśn  PqśW| d k r÷Pn  |  j j |  qWd  S|  j j   d k rax, |  j   D] } | t k rNt Vq1n  Pq1W|  j   d  S|  j j   d k r.|  j j   } | d  k r|  j j j t j    g  } x5 |  j D]* } | t k r×t Vqşn  | j |  qşW|  j j t j |   d  Sd | } t j d t j |  d  } t
 }	 g  }
 t } xˇt
 rú|  j j   } | t k rpt VqDn  | d k rPn  | j |  } | rę| j d  rˇ| j d	  } Pn  |	 r7|
 r|
 d
 } t  j! |  } | r| t" | j d    |
 d
 <n  t j |
  |  j _# n  t }	 |  j j |  qDn  xY t
 r|  j j   } | t k rft Vq:n  | j |  } | s:|  j j |  Pq:q:W|  j j | j  x, |  j   D] } | t k rĐt Vqłn  PqłW|  j$ j   d k ra|  j$ j% } | d k rd  |  j$ _% qÄ| d  k	 rÄt  j! |  } | r^t" | j d   } | |  |  j$ _% q^qÄnc |  j$ j&   } t' | t(  rÄt  j! |  } | rÄ| t" | j d    } |  j$ j |  qÄn  |  j j   |  j   |  j |  _$ qD|
 j |  qDW|	 r}|  j j j t j)    |  j j t j |
   g  } x( |  j D] } | t k rCt VqCqCqCWt j |  |  j _% d  S| rd g } n g  } x5 |  j D]* } | t k rźt Vqn  | j |  qW| r| d } t* j |  } | r| t" | j d   | d <qn  t j |  |  j _% d  Sg  } x5 |  j D]* } | t k r[t Vq>n  | j |  q>W|  j j t j |   d  S(   NR   s   message/delivery-statusR   R8   s   --s   (?P<sep>s4   )(?P<end>--)?(?P<ws>[ \t]*)(?P<linesep>\r\n|\r|\n)?$t   endt   linesepi˙˙˙˙i    (+   RC   R-   R   t   headerREt   matcht   NLCRER   R   t   _parse_headersR4   R   R   R2   t   set_payloadt   EMPTYSTRINGR   R?   R   R/   R9   R   R:   t   get_boundaryR1   R<   R   t   NoBoundaryInMultipartDefectt   ret   compilet   escapeR   t   groupt	   NLCRE_eolt   searchR"   t   preambleR3   t   epiloguet   get_payloadt
   isinstancet
   basestringt   StartBoundaryNotFoundDefectt	   NLCRE_bol(   R
   t   headersR   R#   RD   RB   t   boundaryt	   separatort
   boundaryret   capturing_preambleRU   RF   t   mot   lastlinet   eolmoRV   RE   t   payloadt	   firstlinet   bolmo(    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyR/   Ř   sJ   
					


	
!	


#c   
      C   sţ  d } g  } xĂt  |  D]ľ\ } } | d d k rv | sc t j |  } |  j j j |  q n  | j |  q n  | rľ t j |  d  j d  } | |  j | <d g  } } n  | j	 d  rj| d k rt
 j |  } | r| t | j d    } n  |  j j |  q qj| t |  d k rB|  j j |  d  St j |  } |  j j j |  q n  | j d  }	 |	 d k  r­t j |  } |  j j j |  q n  | |	  } | |	 d j   g } q W| rút j |  j d  |  j | <n  d  S(	   NR   i    s    	i˙˙˙˙s   
s   From i   t   :(   t	   enumerateR   t#   FirstHeaderLineIsContinuationDefectR2   R<   R   RL   R   t   rstript
   startswithRS   RT   R"   RR   t   set_unixfromR-   R   t   MisplacedEnvelopeHeaderDefectt   findt   MalformedHeaderDefectt   lstrip(
   R
   R#   t
   lastheadert	   lastvaluet   linenoR   t   defectt   lhdrRa   R$   (    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyRJ   Ä  sH    
(   R)   R*   R+   R   t   MessageR   R5   R7   R6   R   RC   R9   R/   RJ   (    (    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyR       s   					
		ě(    (   R+   t   __all__RO   t   emailR   R   RP   RI   R[   RS   R   RG   RL   t   NLt   objectR   R   R    (    (    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyt   <module>   s   		s