ó
Û¨[Qc           @   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 throw 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   sq   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 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(   d |  _  g  |  _ g  |  _ t |  _ d  S(   NR   (   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   s)   |  j  j |  j ƒ d |  _ t |  _ d  S(   NR   (   R   R   R   t   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  | d } |  _  t j | ƒ } | j ƒ  |  _  |  j  rw | rw | d j d ƒ rw | j d ƒ | j ƒ  |  _  n  g  } xC t t | ƒ d ƒ D]+ } | j | | d | | d d ƒ q” W|  j | ƒ d S(   s$   Push some new data into this object.R   iÿÿÿÿs   iþÿÿÿi   i   N(	   R   t   NLCRE_crackt   splitR   t   endswitht   ranget   lenR   t	   pushlines(   R
   t   datat   partst   linest   i(    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyt   push`   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   w   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   R2   (   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(   R.   R%   (   R
   (    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyR4   Ÿ   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   R4   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*   R0   t   get_content_typet   set_default_typeR,   t   attachR   R1   (   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   R0   R/   (   R
   t   retval(    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyR7   »   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   R6   s   --s   (?P<sep>s4   )(?P<end>--)?(?P<ws>[ \t]*)(?P<linesep>\r\n|\r|\n)?$t   endt   linesepiÿÿÿÿi    (+   RA   R+   R   t   headerREt   matcht   NLCRER   R   t   _parse_headersR2   R   R   R0   t   set_payloadt   EMPTYSTRINGt   joinR=   R   R-   R7   R   R8   t   get_boundaryR/   R:   R   t   NoBoundaryInMultipartDefectt   ret   compilet   escapeR   t   groupt	   NLCRE_eolt   searchR   t   preambleR1   t   epiloguet   get_payloadt
   isinstancet
   basestringt   StartBoundaryNotFoundDefectt	   NLCRE_bol(   R
   t   headersR   R    RB   R@   t   boundaryt	   separatort
   boundaryret   capturing_preambleRT   RD   t   mot   lastlinet   eolmoRU   RC   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#   FirstHeaderLineIsContinuationDefectR0   R:   R   RJ   RK   t   rstript
   startswithRR   RS   R   RQ   t   set_unixfromR+   R   t   MisplacedEnvelopeHeaderDefectt   findt   MalformedHeaderDefectt   lstrip(
   R
   R    t
   lastheadert	   lastvaluet   linenoR   t   defectt   lhdrR`   R!   (    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyRH   ¯  sH    
(   R'   R(   R)   R   t   MessageR   R3   R5   R4   R   RA   R7   R-   RH   (    (    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyR    ‰   s   					
		ì(    (   R)   t   __all__RN   t   emailR   R   RO   RG   RZ   RR   R   RE   RJ   t   NLt   objectR   R   R    (    (    (    sD   /home/tom/ab/x64lucid-deps/install/lib/python2.7/email/feedparser.pyt   <module>   s   		^