ó
o€
\c           @   s¬   d  Z  d d l Z d d l Z d d l m Z d d l m Z d „  Z d e	 f d „  ƒ  YZ
 d	 e	 f d
 „  ƒ  YZ d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   sŽ   

requests_toolbelt.multipart.decoder
===================================

This holds all the implementation details of the MultipartDecoder

iÿÿÿÿNi   (   t   encode_with(   t   CaseInsensitiveDictc         C   s+   |  j  | ƒ } |  |  |  | t | ƒ f S(   N(   t   findt   len(   t   contentt   boundt   point(    (    sX   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyt   _split_on_find   s    t    ImproperBodyPartContentExceptionc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sX   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyR      s   t    NonMultipartContentTypeExceptionc           B   s   e  Z RS(    (   R	   R
   (    (    (    sX   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyR      s   c            s]   t  j d } | d k r+ |  j ˆ  ƒ }  n  t j j ƒ  j |  ƒ j ƒ  } ‡  f d †  | Dƒ S(   Ni    i   c         3   s3   |  ]) \ } } t  | ˆ  ƒ t  | ˆ  ƒ f Vq d  S(   N(   R    (   t   .0t   kt   v(   t   encoding(    sX   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pys	   <genexpr>$   s   (   t   syst   version_infot   decodet   emailt   parsert   HeaderParsert   parsestrt   items(   t   stringR   t   majort   headers(    (   R   sX   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyt   _header_parser   s    t   BodyPartc           B   s&   e  Z d  Z d „  Z e d „  ƒ Z RS(   sŸ  

    The ``BodyPart`` object is a ``Response``-like interface to an individual
    subpart of a multipart response. It is expected that these will
    generally be created by objects of the ``MultipartDecoder`` class.

    Like ``Response``, there is a ``CaseInsensitiveDict`` object named header,
    ``content`` to access bytes, ``text`` to access unicode, and ``encoding``
    to access the unicode codec.

    c         C   sy   | |  _  i  } d | k rZ t | d ƒ \ } |  _ | d k rf t | j ƒ  | ƒ } qf n t d ƒ ‚ t | ƒ |  _ d  S(   Ns   

t    s$   content does not contain CR-LF-CR-LF(   R   R   R   R   t   lstripR   R   R   (   t   selfR   R   R   t   first(    (    sX   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyt   __init__6   s    		c         C   s   |  j  j |  j ƒ S(   s'   Content of the ``BodyPart`` in unicode.(   R   R   R   (   R   (    (    sX   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyt   textD   s    (   R	   R
   t   __doc__R!   t   propertyR"   (    (    (    sX   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyR   )   s   	t   MultipartDecoderc           B   sM   e  Z d  Z d d „ Z d „  Z e d „  ƒ Z d „  Z e d d „ ƒ Z	 RS(   sg  

    The ``MultipartDecoder`` object parses the multipart payload of
    a bytestring into a tuple of ``Response``-like ``BodyPart`` objects.

    The basic usage is::

        import requests
        from requests_toolbelt import MultipartDecoder

        response = request.get(url)
        decoder = MultipartDecoder.from_response(response)
        for part in decoder.parts:
            print(part.header['content-type'])

    If the multipart content is not from a response, basic usage is::

        from requests_toolbelt import MultipartDecoder

        decoder = MultipartDecoder(content, content_type)
        for part in decoder.parts:
            print(part.header['content-type'])

    For both these usages, there is an optional ``encoding`` parameter. This is
    a string, which is the name of the unicode codec to use (default is
    ``'utf-8'``).

    s   utf-8c         C   s?   | |  _  | |  _ | |  _ t ƒ  |  _ |  j ƒ  |  j ƒ  d  S(   N(   R   t   content_typeR   t   tuplet   partst   _find_boundaryt   _parse_body(   R   R   R&   R   (    (    sX   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyR!   g   s    			
c         C   s¾   t  d „  |  j j d ƒ Dƒ ƒ } | d } | j d ƒ d d k r] t d j | ƒ ƒ ‚ n  xZ | d D]N } t | d ƒ \ } } | j ƒ  d	 k rh t | j d
 ƒ |  j	 ƒ |  _
 qh qh Wd  S(   Nc         s   s   |  ] } | j  ƒ  Vq d  S(   N(   t   strip(   R   t   x(    (    sX   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pys	   <genexpr>t   s    t   ;i    t   /t	   multiparts*   Unexpected mimetype in content-type: '{0}'i   t   =t   boundaryt   "(   R'   R&   t   splitR   t   formatR   t   lowerR    R+   R   R1   (   R   t   ct_infot   mimetypet   itemt   attrt   value(    (    sX   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyR)   s   s    "
c         C   s,   t  | ƒ } | |  |  k r$ |  | S|  Sd  S(   N(   R   (   t   partt   boundary_markert   bm_len(    (    sX   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyt   _fix_first_part‚   s    c            sz   d j  d ˆ j f ƒ ‰ ‡ ‡ f d †  ‰  d „  ‰ ˆ j j d j  d ˆ f ƒ ƒ } t ‡  ‡ f d †  | Dƒ ƒ ˆ _ d  S(   NR   s   --c            s"   t  j |  ˆ ƒ } t | ˆ  j ƒ S(   N(   R%   R>   R   R   (   R;   t   fixed(   R   R1   (    sX   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyt	   body_part   s    c         S   s2   |  d k o1 |  d k o1 |  d  d k o1 |  d k S(   NR   s   
i   s   --
s   --(    (   R;   (    (    sX   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyt	   test_part‘   s    s   
c         3   s'   |  ] } ˆ | ƒ r ˆ  | ƒ Vq d  S(   N(    (   R   R,   (   R@   RA   (    sX   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pys	   <genexpr>˜   s    (   t   joinR1   R   R3   R'   R(   (   R   R(   (    (   R@   R   RA   R1   sX   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyR*   Š   s
    	!c         C   s.   | j  } | j j d d  ƒ } |  | | | ƒ S(   Ns   content-type(   R   R   t   gett   None(   t   clst   responseR   R   R&   (    (    sX   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyt   from_responseš   s    	(
   R	   R
   R#   R!   R)   t   staticmethodR>   R*   t   classmethodRG   (    (    (    sX   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyR%   J   s   		(   R#   R   t   email.parserR   t   encoderR    t   requests.structuresR   R   t	   ExceptionR   R   R   t   objectR   R%   (    (    (    sX   /data/av2000/b2b/venv/lib/python2.7/site-packages/requests_toolbelt/multipart/decoder.pyt   <module>	   s   		!