ó
	Q˜[c           @` sü   d  Z  d d l m Z d d l m Z d d l m Z d d d d g Z d d	 l Z d d
 l m Z m	 Z	 d d l
 m Z m Z d d l m Z d d l m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 S(   u-   A parser of RFC 2822 and MIME email messages.i    (   t   unicode_literals(   t   division(   t   absolute_importu   Parseru   HeaderParseru   BytesParseru   BytesHeaderParserN(   t   StringIOt   TextIOWrapper(   t
   FeedParsert   BytesFeedParser(   t   Message(   t   compat32t   Parserc           B` s,   e  Z e d  „ Z e d „ Z e d „ Z RS(   c         K` s<   d | k r  | d } | d =n t  } | |  _ | |  _ d S(   u†  Parser of RFC 2822 and MIME email messages.

        Creates an in-memory object tree representing the email message, which
        can then be manipulated and turned over to a Generator to return the
        textual representation of the message.

        The string must be formatted as a block of RFC 2822 headers and header
        continuation lines, optionally preceeded by a `Unix-from' header.  The
        header block is terminated either by the end of the string or by a
        blank line.

        _class is the class to instantiate for new message objects when they
        must be created.  This class must have a constructor that can take
        zero arguments.  Default is Message.Message.

        The policy keyword specifies a policy object that controls a number of
        aspects of the parser's operation.  The default policy maintains
        backward compatibility.

        u   policyN(   R   t   _classt   policy(   t   selfR
   t   _3to2kwargsR   (    (    s<   lib/python2.7/site-packages/future/backports/email/parser.pyt   __init__   s     
 
	c         C` sh   t  |  j d |  j ƒ} | r+ | j ƒ  n  x0 t r] | j d ƒ } | sM Pn  | j | ƒ q. W| j ƒ  S(   u\  Create a message structure from the data in a file.

        Reads all the data from the file and returns the root of the message
        structure.  Optional headersonly is a flag specifying whether to stop
        parsing after reading the headers or not.  The default is False,
        meaning it parses the entire contents of the file.
        R   i    (   R   R
   R   t   _set_headersonlyt   Truet   readt   feedt   close(   R   t   fpt   headersonlyt
   feedparsert   data(    (    s<   lib/python2.7/site-packages/future/backports/email/parser.pyt   parse/   s    	c         C` s   |  j  t | ƒ d | ƒS(   u-  Create a message structure from a string.

        Returns the root of the message structure.  Optional headersonly is a
        flag specifying whether to stop parsing after reading the headers or
        not.  The default is False, meaning it parses the entire contents of
        the file.
        R   (   R   R   (   R   t   textR   (    (    s<   lib/python2.7/site-packages/future/backports/email/parser.pyt   parsestrA   s    (   t   __name__t
   __module__R   R   t   FalseR   R   (    (    (    s<   lib/python2.7/site-packages/future/backports/email/parser.pyR	      s   t   HeaderParserc           B` s    e  Z e d  „ Z e d „ Z RS(   c         C` s   t  j |  | t ƒ S(   N(   R	   R   R   (   R   R   R   (    (    s<   lib/python2.7/site-packages/future/backports/email/parser.pyR   N   s    c         C` s   t  j |  | t ƒ S(   N(   R	   R   R   (   R   R   R   (    (    s<   lib/python2.7/site-packages/future/backports/email/parser.pyR   Q   s    (   R   R   R   R   R   (    (    (    s<   lib/python2.7/site-packages/future/backports/email/parser.pyR   M   s   t   BytesParserc           B` s)   e  Z d  „  Z e d „ Z e d „ Z RS(   c         O` s   t  | | Ž  |  _ d S(   uÑ  Parser of binary RFC 2822 and MIME email messages.

        Creates an in-memory object tree representing the email message, which
        can then be manipulated and turned over to a Generator to return the
        textual representation of the message.

        The input must be formatted as a block of RFC 2822 headers and header
        continuation lines, optionally preceeded by a `Unix-from' header.  The
        header block is terminated either by the end of the input or by a
        blank line.

        _class is the class to instantiate for new message objects when they
        must be created.  This class must have a constructor that can take
        zero arguments.  Default is Message.Message.
        N(   R	   t   parser(   R   t   argst   kw(    (    s<   lib/python2.7/site-packages/future/backports/email/parser.pyR   W   s    c         C` s<   t  | d d d d ƒ} |  |  j j | | ƒ SWd QXd S(   uc  Create a message structure from the data in a binary file.

        Reads all the data from the file and returns the root of the message
        structure.  Optional headersonly is a flag specifying whether to stop
        parsing after reading the headers or not.  The default is False,
        meaning it parses the entire contents of the file.
        t   encodingu   asciit   errorsu   surrogateescapeN(   R   R    R   (   R   R   R   (    (    s<   lib/python2.7/site-packages/future/backports/email/parser.pyR   i   s    c         C` s(   | j  d d d ƒ} |  j j | | ƒ S(   u2  Create a message structure from a byte string.

        Returns the root of the message structure.  Optional headersonly is a
        flag specifying whether to stop parsing after reading the headers or
        not.  The default is False, meaning it parses the entire contents of
        the file.
        u   ASCIIR$   u   surrogateescape(   t   decodeR    R   (   R   R   R   (    (    s<   lib/python2.7/site-packages/future/backports/email/parser.pyt
   parsebytesv   s    (   R   R   R   R   R   R&   (    (    (    s<   lib/python2.7/site-packages/future/backports/email/parser.pyR   U   s   	t   BytesHeaderParserc           B` s    e  Z e d  „ Z e d „ Z RS(   c         C` s   t  j |  | d t ƒS(   NR   (   R   R   R   (   R   R   R   (    (    s<   lib/python2.7/site-packages/future/backports/email/parser.pyR   ƒ   s    c         C` s   t  j |  | d t ƒS(   NR   (   R   R&   R   (   R   R   R   (    (    s<   lib/python2.7/site-packages/future/backports/email/parser.pyR&   †   s    (   R   R   R   R   R&   (    (    (    s<   lib/python2.7/site-packages/future/backports/email/parser.pyR'   ‚   s   (   t   __doc__t
   __future__R    R   R   t   __all__t   warningst   ioR   R   t!   future.backports.email.feedparserR   R   t   future.backports.email.messageR   t"   future.backports.email._policybaseR   t   objectR	   R   R   R'   (    (    (    s<   lib/python2.7/site-packages/future/backports/email/parser.pyt   <module>   s   9-