;
Ïâ"Ic               @   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 Gd „  d e ƒ Z Gd „  d ƒ Z d S(   u  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.
u
   FeedParseri    N(   u   errors(   u   messageu   
||
u   (
||
)u	   (
||
)$u(   ^(From |[\041-\071\073-\176]{1,}:|[\t ])u    u   
c             B   sw   |  Ee  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 S(   uk  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  |  _ d |  _ d  S(   Nu    F(   u   _partialu   _linesu	   _eofstacku   Falseu   _closed(   u   self(    (    u-   /mit/python/lib/python3.0/email/feedparser.pyu   __init__3   s    			c             C   s   |  j  j | ƒ d  S(   N(   u	   _eofstacku   append(   u   selfu   pred(    (    u-   /mit/python/lib/python3.0/email/feedparser.pyu   push_eof_matcher=   s    c             C   s   |  j  j ƒ  S(   N(   u	   _eofstacku   pop(   u   self(    (    u-   /mit/python/lib/python3.0/email/feedparser.pyu   pop_eof_matcher@   s    c             C   s)   |  j  j |  j ƒ d |  _ d |  _ d  S(   Nu    T(   u   _linesu   appendu   _partialu   Trueu   _closed(   u   self(    (    u-   /mit/python/lib/python3.0/email/feedparser.pyu   closeC   s    	c             C   st   |  j  p |  j o d St S|  j  j ƒ  } x@ |  j d  d  d … D]( } | | ƒ o |  j  j | ƒ d SqD W| S(   Nu    iÿÿÿÿ(   u   _linesu   _closedu   NeedMoreDatau   popu	   _eofstacku   append(   u   selfu   lineu   ateof(    (    u-   /mit/python/lib/python3.0/email/feedparser.pyu   readlineI   s    

 	c             C   s   |  j  j | ƒ d  S(   N(   u   _linesu   append(   u   selfu   line(    (    u-   /mit/python/lib/python3.0/email/feedparser.pyu
   unreadline[   s    c             C   s’   |  j  | d } |  _  t j | ƒ } | j ƒ  |  _  g  } xC t t | ƒ d ƒ D]+ } | j | | d | | d d ƒ qR W|  j | ƒ d S(   u$   Push some new data into this object.u    i   i   N(   u   _partialu   NLCRE_cracku   splitu   popu   rangeu   lenu   appendu	   pushlines(   u   selfu   datau   partsu   linesu   i(    (    u-   /mit/python/lib/python3.0/email/feedparser.pyu   push`   s     )c             C   s$   | d  d  d … |  j  d  d … <d  S(   Niÿÿÿÿi    (   u   _lines(   u   selfu   lines(    (    u-   /mit/python/lib/python3.0/email/feedparser.pyu	   pushliness   s    c             C   s   |  j  S(   N(   u   _closed(   u   self(    (    u-   /mit/python/lib/python3.0/email/feedparser.pyu	   is_closedw   s    c             C   s   |  S(   N(    (   u   self(    (    u-   /mit/python/lib/python3.0/email/feedparser.pyu   __iter__z   s    c             C   s'   |  j  ƒ  } | d k o
 t ‚ n | S(   Nu    (   u   readlineu   StopIteration(   u   selfu   line(    (    u-   /mit/python/lib/python3.0/email/feedparser.pyu   __next__}   s    
N(   u   __name__u
   __module__u   __doc__u   __init__u   push_eof_matcheru   pop_eof_matcheru   closeu   readlineu
   unreadlineu   pushu	   pushlinesu	   is_closedu   __iter__u   __next__(   u
   __locals__(    (    u-   /mit/python/lib/python3.0/email/feedparser.pyu   BufferedSubFile+   s   
	
									u   BufferedSubFilec             B   sk   |  Ee  Z d  Z e j d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z d
 S(   u   A feed-style parser of email.c             C   sO   | |  _  t ƒ  |  _ g  |  _ |  j ƒ  j |  _ d |  _ d |  _	 d |  _ d S(   u@   _factory is called with no arguments to create a new message objNF(   u   _factoryu   BufferedSubFileu   _inputu	   _msgstacku	   _parsegenu   __next__u   _parseu   Noneu   _curu   _lastu   Falseu   _headersonly(   u   selfu   _factory(    (    u-   /mit/python/lib/python3.0/email/feedparser.pyu   __init__ˆ   s    				c             C   s   d |  _ d  S(   NT(   u   Trueu   _headersonly(   u   self(    (    u-   /mit/python/lib/python3.0/email/feedparser.pyu   _set_headersonly“   s    c             C   s   |  j  j | ƒ |  j ƒ  d S(   u   Push more data into the parser.N(   u   _inputu   pushu   _call_parse(   u   selfu   data(    (    u-   /mit/python/lib/python3.0/email/feedparser.pyu   feed–   s    c             C   s)   y |  j  ƒ  Wn t k
 o Yn Xd  S(   N(   u   _parseu   StopIteration(   u   self(    (    u-   /mit/python/lib/python3.0/email/feedparser.pyu   _call_parse›   s    c             C   sb   |  j  j ƒ  |  j ƒ  |  j ƒ  } | j ƒ  d k o( | j ƒ  o | j j t j	 ƒ  ƒ n | S(   u<   Parse all remaining data and return the root message object.u	   multipart(
   u   _inputu   closeu   _call_parseu   _pop_messageu   get_content_maintypeu   is_multipartu   defectsu   appendu   errorsu!   MultipartInvariantViolationDefect(   u   selfu   root(    (    u-   /mit/python/lib/python3.0/email/feedparser.pyu   close¡   s    
c             C   s…   |  j  ƒ  } |  j o' |  j j ƒ  d k o | j d ƒ n |  j o |  j d j | ƒ n |  j j | ƒ | |  _ | |  _ d  S(   Nu   multipart/digestu   message/rfc822iÿÿÿÿ(   u   _factoryu   _curu   get_content_typeu   set_default_typeu	   _msgstacku   attachu   appendu   _last(   u   selfu   msg(    (    u-   /mit/python/lib/python3.0/email/feedparser.pyu   _new_message­   s     
	c             C   s:   |  j  j ƒ  } |  j  o |  j  d |  _ n
 d  |  _ | S(   Niÿÿÿÿ(   u	   _msgstacku   popu   _curu   None(   u   selfu   retval(    (    u-   /mit/python/lib/python3.0/email/feedparser.pyu   _pop_message·   s
    
	c             c   sÅ  |  j  ƒ  g  } xp |  j D]e } | t k o t Vq n t j | ƒ p) t j | ƒ p |  j j | ƒ n Pn | j | ƒ q W|  j | ƒ |  j	 oq g  } xJ |  j j
 ƒ  } | t k o t Vq£ n | d k o Pn | j | ƒ q£ |  j j t j | ƒ ƒ d  S|  j j ƒ  d k oè xà |  j j t j ƒ x. |  j ƒ  D]  } | t k o t VqDn PqDW|  j ƒ  } |  j j ƒ  x, |  j j
 ƒ  } | t k o t Vq„n Pq„x, |  j j
 ƒ  } | t k o t Vq³n Pq³| d k o Pn |  j j | ƒ q$d  S|  j j ƒ  d k o@ x. |  j ƒ  D]  } | t k o t Vq,n Pq,W|  j ƒ  d  S|  j j ƒ  d k oó|  j j ƒ  } | d  k ow |  j j j t j ƒ  ƒ g  } x7 |  j D], } | t k o t Vqºn | j | ƒ qºW|  j j t j | ƒ ƒ d  Sd | } t j d t j | ƒ d ƒ } d }	 g  }
 d } xÛ|  j j
 ƒ  } | t k o t VqGn | d k o Pn | j | ƒ } | o{| j d ƒ o | j d	 ƒ } Pn |	 o… |
 oa |
 d
 } t  j! | ƒ } | o( | d  t" | j d ƒ ƒ … |
 d
 <n t j |
 ƒ |  j _# n d }	 |  j j | ƒ qGn xV |  j j
 ƒ  } | t k o t VqJn | j | ƒ } | p |  j j | ƒ PqJqJ|  j j | j ƒ x. |  j ƒ  D]  } | t k o t VqÀn PqÀW|  j$ j ƒ  d k o„ |  j$ j% } | d k o d  |  j$ _% që| d  k	 oJ t  j! | ƒ } | o0 t" | j d ƒ ƒ } | d  | … |  j$ _% qzqënn |  j$ j& ƒ  } t' | t( ƒ oN t  j! | ƒ } | o4 | d  t" | j d ƒ ƒ … } |  j$ j | ƒ qën |  j j ƒ  |  j ƒ  |  j |  _$ qG|
 j | ƒ qG|	 o |  j j j t j) ƒ  ƒ |  j j t j |
 ƒ ƒ g  } x* |  j D] } | t k o t VqkqkqkWt j | ƒ |  j _% d  S| o d g } n g  } x7 |  j D], } | t k o t VqÌn | j | ƒ qÌW| oK | d } t* j | ƒ } | o' | t" | j d ƒ ƒ d  … | d <qNn t j | ƒ |  j _% d  Sg  } x7 |  j D], } | t k o t Vqxn | j | ƒ qxW|  j j t j | ƒ ƒ d  S(   Nu    u   message/delivery-statusu   messageu	   multipartu   --u   (?P<sep>u4   )(?P<end>--)?(?P<ws>[ \t]*)(?P<linesep>\r\n|\r|\n)?$u   endu   linesepiÿÿÿÿi    TF(+   u   _new_messageu   _inputu   NeedMoreDatau   headerREu   matchu   NLCREu
   unreadlineu   appendu   _parse_headersu   _headersonlyu   readlineu   _curu   set_payloadu   EMPTYSTRINGu   joinu   get_content_typeu   push_eof_matcheru	   _parsegenu   _pop_messageu   pop_eof_matcheru   get_content_maintypeu   get_boundaryu   Noneu   defectsu   errorsu   NoBoundaryInMultipartDefectu   reu   compileu   escapeu   Trueu   Falseu   groupu	   NLCRE_eolu   searchu   lenu   preambleu   _lastu   epilogueu   get_payloadu
   isinstanceu   stru   StartBoundaryNotFoundDefectu	   NLCRE_bol(   u   selfu   headersu   lineu   linesu   retvalu   msgu   boundaryu	   separatoru
   boundaryreu   capturing_preambleu   preambleu   linesepu   mou   lastlineu   eolmou   epilogueu   endu   payloadu	   firstlineu   bolmo(    (    u-   /mit/python/lib/python3.0/email/feedparser.pyu	   _parsegen¿   sZ   

 
  

 


( # 

 
 
+
 c       
      C   s(  d } g  } xët  | ƒ D]Ý\ } } | d d k oD | p) t j | ƒ } |  j j j | ƒ q n | j | ƒ q n | o@ t j | ƒ d  d … j d ƒ } | |  j | <d g  } } n | j	 d ƒ o³ | d k oQ t
 j | ƒ } | o$ | d  t | j d ƒ ƒ … } n |  j j | ƒ q q„| t | ƒ d k o |  j j | ƒ d  St j | ƒ } |  j j j | ƒ q n | j d ƒ }	 |	 d k  o) t j | ƒ } |  j j j | ƒ q n | d  |	 … } | |	 d d  … j ƒ  g } q W| o# t j | ƒ j d ƒ |  j | <n d  S(	   Nu    i    u    	iÿÿÿÿu   
u   From i   u   :(   u	   enumerateu   errorsu#   FirstHeaderLineIsContinuationDefectu   _curu   defectsu   appendu   EMPTYSTRINGu   joinu   rstripu
   startswithu	   NLCRE_eolu   searchu   lenu   groupu   set_unixfromu   _inputu
   unreadlineu   MisplacedEnvelopeHeaderDefectu   findu   MalformedHeaderDefectu   lstrip(
   u   selfu   linesu
   lastheaderu	   lastvalueu   linenou   lineu   defectu   lhdru   mou   i(    (    u-   /mit/python/lib/python3.0/email/feedparser.pyu   _parse_headers«  sJ     "$!N(   u   __name__u
   __module__u   __doc__u   messageu   Messageu   __init__u   _set_headersonlyu   feedu   _call_parseu   closeu   _new_messageu   _pop_messageu	   _parsegenu   _parse_headers(   u
   __locals__(    (    u-   /mit/python/lib/python3.0/email/feedparser.pyu
   FeedParser…   s   
					
		ì(   u   __doc__u   __all__u   reu   emailu   errorsu   messageu   compileu   NLCREu	   NLCRE_bolu	   NLCRE_eolu   NLCRE_cracku   headerREu   EMPTYSTRINGu   NLu   objectu   NeedMoreDatau   BufferedSubFileu
   FeedParser(    (    (    u-   /mit/python/lib/python3.0/email/feedparser.pyu   <module>   s   		Z