σ
Π²Ebc           @@  sΏ   d  d l  m Z d  d l Z d  d l Z d  d l Z d d l m Z d d  Z d   Z	 i d d	 6d
 d 6Z
 e
 j d   e d  d  D  d   Z d   Z e Z d e f d     YZ d S(   i    (   t   absolute_importNi   (   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(    (    s7   /tmp/pip-build-UPPWic/pip/pip/_vendor/urllib3/fields.pyt   guess_content_type
   s    	c         @  sα   t    t j  r$   j d    n  t   f d   d D  s d |    f } y | j d  Wn t t f k
 rz q X| Sn  t j r   j d    n  t	 j
 j   d    d |    f   t j rέ   j d    n    S(   s!  
    Helper function to format and quote a single header parameter using the
    strategy defined in RFC 2231.

    Particularly useful for header parameters which might contain
    non-ASCII values, like file names. This follows
    `RFC 2388 Section 4.4 <https://tools.ietf.org/html/rfc2388#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 ``bytes`` or `str``.
    :ret:
        An RFC-2231-formatted unicode string.
    s   utf-8c         3@  s   |  ] } |   k Vq d  S(   N(    (   t   .0t   ch(   t   value(    s7   /tmp/pip-build-UPPWic/pip/pip/_vendor/urllib3/fields.pys	   <genexpr>+   s    s   "\
u   %s="%s"t   asciis   %s*=%s(   t
   isinstanceR   t   binary_typet   decodet   anyt   encodet   UnicodeEncodeErrort   UnicodeDecodeErrort   PY2t   emailt   utilst   encode_rfc2231(   t   nameR	   t   result(    (   R	   s7   /tmp/pip-build-UPPWic/pip/pip/_vendor/urllib3/fields.pyt   format_header_param_rfc2231   s     		u   %22u   "u   \\u   \c         C@  s7   i  |  ]- } | d k r d j  |  t j |   q S(   i   u   %{:02X}(   i   (   t   formatR   t   unichr(   R   t   cc(    (    s7   /tmp/pip-build-UPPWic/pip/pip/_vendor/urllib3/fields.pys
   <dictcomp>K   s   	i   c         @  s_     f d   } t  j d j g    j   D] } t  j |  ^ q(   } | j | |   } | S(   Nc         @  s     |  j  d  S(   Ni    (   t   group(   t   match(   t   needles_and_replacements(    s7   /tmp/pip-build-UPPWic/pip/pip/_vendor/urllib3/fields.pyt   replacerS   s    t   |(   t   ret   compilet   joint   keyst   escapet   sub(   R	   R   R   t   needlet   patternR   (    (   R   s7   /tmp/pip-build-UPPWic/pip/pip/_vendor/urllib3/fields.pyt   _replace_multipleR   s
    4c         C@  sA   t  | t j  r$ | j d  } n  t | t  } d |  | f S(   s±  
    Helper function to format and quote a single header parameter using the
    HTML5 strategy.

    Particularly useful for header parameters which might contain
    non-ASCII values, like file names. This follows the `HTML5 Working Draft
    Section 4.10.22.7`_ and matches the behavior of curl and modern browsers.

    .. _HTML5 Working Draft Section 4.10.22.7:
        https://w3c.github.io/html/sec-forms.html#multipart-form-data

    :param name:
        The name of the parameter, a string expected to be ASCII only.
    :param value:
        The value of the parameter, provided as ``bytes`` or `str``.
    :ret:
        A unicode string, stripped of troublesome characters.
    s   utf-8u   %s="%s"(   R   R   R   R   R)   t   _HTML5_REPLACEMENTS(   R   R	   (    (    s7   /tmp/pip-build-UPPWic/pip/pip/_vendor/urllib3/fields.pyt   format_header_param_html5_   s    t   RequestFieldc           B@  s_   e  Z d  Z d d e d  Z e e d   Z d   Z d   Z	 d   Z
 d d d d  Z RS(   s  
    A data container for request body parameters.

    :param name:
        The name of this request field. Must be unicode.
    :param data:
        The data/value body.
    :param filename:
        An optional filename of the request field. Must be unicode.
    :param headers:
        An optional dict-like object of headers to initially use for the field.
    :param header_formatter:
        An optional callable that is used to encode and format the headers. By
        default, this is :func:`format_header_param_html5`.
    c         C@  sI   | |  _  | |  _ | |  _ i  |  _ | r< t |  |  _ n  | |  _ d  S(   N(   t   _namet	   _filenamet   datat   headerst   dictt   header_formatter(   t   selfR   R/   R   R0   R2   (    (    s7   /tmp/pip-build-UPPWic/pip/pip/_vendor/urllib3/fields.pyt   __init__   s    				c         C@  s   t  | t  rN t |  d k r3 | \ } } } q` | \ } } t |  } n d } 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   R2   t   content_typeN(   R   t   tuplet   lenR   t   Nonet   make_multipart(   t   clst	   fieldnameR	   R2   R   R/   R5   t   request_param(    (    s7   /tmp/pip-build-UPPWic/pip/pip/_vendor/urllib3/fields.pyt   from_tuples   s    c         C@  s   |  j  | |  S(   sI  
        Overridable helper function to format a single header parameter. By
        default, this calls ``self.header_formatter``.

        :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.
        (   R2   (   R3   R   R	   (    (    s7   /tmp/pip-build-UPPWic/pip/pip/_vendor/urllib3/fields.pyt   _render_partΓ   s    c         C@  sv   g  } | } t  | t  r* | j   } n  x< | D]4 \ } } | d k	 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) tuples or a :class:`dict` of (k, v) to format
            as `k1="v1"; k2="v2"; ...`.
        u   ; N(   R   R1   t   itemsR8   t   appendR>   R#   (   R3   t   header_partst   partst   iterableR   R	   (    (    s7   /tmp/pip-build-UPPWic/pip/pip/_vendor/urllib3/fields.pyt   _render_partsΠ   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-Locationu   %s: %su   
(   R0   t   gett   FalseR@   R?   R#   (   R3   t   linest	   sort_keyst   sort_keyt   header_namet   header_value(    (    s7   /tmp/pip-build-UPPWic/pip/pip/_vendor/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.

        u	   form-datas   Content-Dispositionu   ; u    u   nameu   filenames   Content-Types   Content-LocationN(   R0   R#   RD   R-   R.   (   R3   t   content_dispositionR5   t   content_location(    (    s7   /tmp/pip-build-UPPWic/pip/pip/_vendor/urllib3/fields.pyR9   ω   s    'N(   t   __name__t
   __module__t   __doc__R8   R+   R4   t   classmethodR=   R>   RD   RL   R9   (    (    (    s7   /tmp/pip-build-UPPWic/pip/pip/_vendor/urllib3/fields.pyR,   ~   s   
#			i    (   t
   __future__R    t   email.utilsR   R   R!   t   packagesR   R   R   R*   t   updatet   rangeR)   R+   t   format_header_paramt   objectR,   (    (    (    s7   /tmp/pip-build-UPPWic/pip/pip/_vendor/urllib3/fields.pyt   <module>   s    	*
		