ó
¨9Vc           @   sW   d  d l  Z d  d l Z d d l m Z d d „ Z d „  Z d e f d „  ƒ  YZ d S(	   iÿÿÿÿNi   (   t   sixs   application/octet-streamc         C   s!   |  r t  j |  ƒ d p | S| S(   sæ   
    Guess the "Content-Type" of a file.

    :param filename:
        The filename to guess the "Content-Type" of using :mod:`mimetypes`.
    :param default:
        If no "Content-Type" can be guessed, default to `default`.
    i    (   t	   mimetypest
   guess_type(   t   filenamet   default(    (    sI   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/fields.pyt   guess_content_type   s    	c            sœ   t  ‡  f d †  d Dƒ ƒ sX d |  ˆ  f } y | j d ƒ Wn t k
 rP qX X| Sn  t j ss ˆ  j d ƒ ‰  n  t j j ˆ  d ƒ ‰  d |  ˆ  f ‰  ˆ  S(   s   
    Helper function to format and quote a single header parameter.

    Particularly useful for header parameters which might contain
    non-ASCII values, like file names. This follows RFC 2231, as
    suggested by RFC 2388 Section 4.4.

    :param name:
        The name of the parameter, a string expected to be ASCII only.
    :param value:
        The value of the parameter, provided as a unicode string.
    c         3   s   |  ] } | ˆ  k Vq d  S(   N(    (   t   .0t   ch(   t   value(    sI   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/fields.pys	   <genexpr>"   s    s   "\
s   %s="%s"t   asciis   utf-8s   %s*=%s(   t   anyt   encodet   UnicodeEncodeErrorR    t   PY3t   emailt   utilst   encode_rfc2231(   t   nameR   t   result(    (   R   sI   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/fields.pyt   format_header_param   s    	t   RequestFieldc           B   sY   e  Z d  Z d d d „ Z e d „  ƒ Z d „  Z d „  Z d „  Z	 d d d d „ Z
 RS(   sK  
    A data container for request body parameters.

    :param name:
        The name of this request field.
    :param data:
        The data/value body.
    :param filename:
        An optional filename of the request field.
    :param headers:
        An optional dict-like object of headers to initially use for the field.
    c         C   s@   | |  _  | |  _ | |  _ i  |  _ | r< t | ƒ |  _ n  d  S(   N(   t   _namet	   _filenamet   datat   headerst   dict(   t   selfR   R   R   R   (    (    sI   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/fields.pyt   __init__>   s    				c         C   s‰   t  | t ƒ rN t | ƒ d k r3 | \ } } } q` | \ } } t | ƒ } n d } d } | } |  | | d | ƒ} | j d | ƒ | S(   s³  
        A :class:`~urllib3.fields.RequestField` factory from old-style tuple parameters.

        Supports constructing :class:`~urllib3.fields.RequestField` from
        parameter of key/value strings AND key/filetuple. A filetuple is a
        (filename, data, MIME type) tuple where the MIME type is optional.
        For example::

            'foo': 'bar',
            'fakefile': ('foofile.txt', 'contents of foofile'),
            'realfile': ('barfile.txt', open('realfile').read()),
            'typedfile': ('bazfile.bin', open('bazfile').read(), 'image/jpeg'),
            'nonamefile': 'contents of nonamefile field',

        Field names and filenames must be unicode.
        i   R   t   content_typeN(   t
   isinstancet   tuplet   lenR   t   Nonet   make_multipart(   t   clst	   fieldnameR   R   R   R   t   request_param(    (    sI   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/fields.pyt   from_tuplesF   s    c         C   s   t  | | ƒ S(   s  
        Overridable helper function to format a single header parameter.

        :param name:
            The name of the parameter, a string expected to be ASCII only.
        :param value:
            The value of the parameter, provided as a unicode string.
        (   R   (   R   R   R   (    (    sI   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/fields.pyt   _render_parth   s    	c         C   sp   g  } | } t  | t ƒ r* | j ƒ  } n  x6 | D]. \ } } | r1 | j |  j | | ƒ ƒ q1 q1 Wd j | ƒ S(   sO  
        Helper function to format and quote a single header.

        Useful for single headers that are composed of multiple items. E.g.,
        'Content-Disposition' fields.

        :param header_parts:
            A sequence of (k, v) typles or a :class:`dict` of (k, v) to format
            as `k1="v1"; k2="v2"; ...`.
        s   ; (   R   R   t   itemst   appendR&   t   join(   R   t   header_partst   partst   iterableR   R   (    (    sI   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/fields.pyt   _render_partss   s     c         C   sÅ   g  } d d d g } xD | D]< } |  j  j | t ƒ r | j d | |  j  | f ƒ q q WxL |  j  j ƒ  D]; \ } } | | k rl | r§ | j d | | f ƒ q§ ql ql W| j d ƒ d j | ƒ S(   s=   
        Renders the headers for this request field.
        s   Content-Dispositions   Content-Types   Content-Locations   %s: %ss   
(   R   t   gett   FalseR(   R'   R)   (   R   t   linest	   sort_keyst   sort_keyt   header_namet   header_value(    (    sI   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/fields.pyt   render_headers‰   s    %!c      
   C   st   | p	 d |  j  d <|  j  d c d j d |  j d |  j f d |  j f f ƒ g ƒ 7<| |  j  d <| |  j  d <d	 S(
   s|  
        Makes this request field into a multipart request field.

        This method overrides "Content-Disposition", "Content-Type" and
        "Content-Location" headers to the request parameter.

        :param content_type:
            The 'Content-Type' of the request body.
        :param content_location:
            The 'Content-Location' of the request body.

        s	   form-datas   Content-Dispositions   ; t    R   R   s   Content-Types   Content-LocationN(   R   R)   R-   R   R   (   R   t   content_dispositionR   t   content_location(    (    sI   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/fields.pyR!   œ   s    	'N(   t   __name__t
   __module__t   __doc__R    R   t   classmethodR%   R&   R-   R5   R!   (    (    (    sI   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/fields.pyR   1   s   "			(	   t   email.utilsR   R   t   packagesR    R   R   t   objectR   (    (    (    sI   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/fields.pyt   <module>   s
   	