ó
È1@]c           @@  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 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(    (    s9   lib/python2.7/site-packages/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 s ˆ  j d ƒ ‰  n  t	 j
 j ˆ  d ƒ ‰  d |  ˆ  f ‰  t j sÝ ˆ  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.

    :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(    s9   lib/python2.7/site-packages/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   PY3t   emailt   utilst   encode_rfc2231(   t   nameR	   t   result(    (   R	   s9   lib/python2.7/site-packages/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(    (    s9   lib/python2.7/site-packages/pip/_vendor/urllib3/fields.pys
   <dictcomp>I   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(    s9   lib/python2.7/site-packages/pip/_vendor/urllib3/fields.pyt   replacerR   s    t   |(   t   ret   compilet   joint   keyst   escapet   sub(   R	   R   R   t   needlet   patternR   (    (   R   s9   lib/python2.7/site-packages/pip/_vendor/urllib3/fields.pyt   _replace_multipleP   s    .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	   (    (    s9   lib/python2.7/site-packages/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   (    (    s9   lib/python2.7/site-packages/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(    (    s9   lib/python2.7/site-packages/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	   (    (    s9   lib/python2.7/site-packages/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	   (    (    s9   lib/python2.7/site-packages/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(    (    s9   lib/python2.7/site-packages/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(    (    s9   lib/python2.7/site-packages/pip/_vendor/urllib3/fields.pyR9   û   s    	'N(   t   __name__t
   __module__t   __doc__R8   R+   R4   t   classmethodR=   R>   RD   RL   R9   (    (    (    s9   lib/python2.7/site-packages/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,   (    (    (    s9   lib/python2.7/site-packages/pip/_vendor/urllib3/fields.pyt   <module>   s"   	)
		