
j^c           @   s{  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 Z
 d d l Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d	 l m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m  Z  m! Z! m" Z" m# Z# d d
 l$ m% Z% d d l& m' Z' d d l( m) Z) m* Z* m+ Z+ m, Z, dC Z- e j.   Z/ i d d 6d d 6Z0 e j1 d k rd   Z2 d   Z n  d   Z3 d   Z4 e5 d  Z6 d   Z7 d   Z8 d   Z9 d   Z: d   Z; d   Z< e5 d  Z= d    Z> d!   Z? d"   Z@ d#   ZA d$   ZB d%   ZC d&   ZD d'   ZE eF d( d)  ZG d*   ZH d+   ZI d,   ZJ d-   ZK d.   ZL d/   ZM e jN d0    ZO d1   ZP d d2  ZR d3   ZS d4 d5  ZT d6   ZU d7   ZV d8 jW d9  ZX eX d: ZY eX d; ZZ d<   Z[ d=   Z\ d>   Z] e j^ d?  Z_ e j^ d?  Z` d@   Za dA   Zb dB   Zc d S(D   s   
requests.utils
~~~~~~~~~~~~~~

This module provides utility functions that are used within Requests
that are also useful for external consumption.
iN(   t   OrderedDicti   (   t   __version__(   t   certs(   t   to_native_string(   t   parse_http_list(   t   quotet   urlparset   bytest   strt   unquotet
   getproxiest   proxy_bypasst
   urlunparset
   basestringt   integer_typest   is_py3t   proxy_bypass_environmentt   getproxies_environmentt   Mapping(   t   cookiejar_from_dict(   t   CaseInsensitiveDict(   t
   InvalidURLt   InvalidHeadert   FileModeWarningt   UnrewindableBodyErrors   .netrct   _netrciP   t   httpi  t   httpst   win32c         C   sA  y% t  r d d  l } n d d  l } Wn t k
 r9 t SXyK | j | j d  } t | j | d  d  } | j | d  d } Wn t	 k
 r t SX| s | r t S| j
 d  } x | D]w } | d k r d |  k r t Sn  | j d d	  } | j d
 d  } | j d d  } t j | |  t j  r t Sq Wt S(   Nis;   Software\Microsoft\Windows\CurrentVersion\Internet Settingst   ProxyEnablei    t   ProxyOverridet   ;s   <local>t   .s   \.t   *s   .*t   ?(   R   t   winregt   _winregt   ImportErrort   Falset   OpenKeyt   HKEY_CURRENT_USERt   intt   QueryValueExt   OSErrort   splitt   Truet   replacet   ret   matcht   I(   t   hostR#   t   internetSettingst   proxyEnablet   proxyOverridet   test(    (    s+   site-packages/pip/_vendor/requests/utils.pyt   proxy_bypass_registry0   s8    		c         C   s!   t    r t |   St |   Sd S(   s   Return True, if the host should be bypassed.

        Checks proxy settings gathered from the environment, if specified,
        or the registry.
        N(   R   R   R7   (   R2   (    (    s+   site-packages/pip/_vendor/requests/utils.pyR   W   s    	
c         C   s"   t  |  d  r |  j   }  n  |  S(   s/   Returns an internal sequence dictionary update.t   items(   t   hasattrR8   (   t   d(    (    s+   site-packages/pip/_vendor/requests/utils.pyt   dict_to_sequencec   s    c         C   s  d  } d } t |  d  r* t |   } n t |  d  rE |  j } nm t |  d  r y |  j   } Wn t j k
 rz q Xt j |  j } d |  j	 k r t
 j d t  q n  t |  d  rty |  j   } Wn, t t f k
 r | d  k	 rq| } qqqtXt |  d  rt| d  k rty3 |  j d d	  |  j   } |  j | pId  Wqqt t f k
 rmd } qqXqtn  | d  k rd } n  t d | |  S(
   Ni    t   __len__t   lent   filenot   bs%  Requests has determined the content-length for this request using the binary size of the file: however, the file has been opened in text mode (i.e. without the 'b' flag in the mode). This may lead to an incorrect content-length. In Requests 3.0, support will be removed for files in text mode.t   tellt   seeki   (   t   NoneR9   R=   R>   t   iot   UnsupportedOperationt   ost   fstatt   st_sizet   modet   warningst   warnR   R@   R+   t   IOErrorRA   t   max(   t   ot   total_lengtht   current_positionR>   (    (    s+   site-packages/pip/_vendor/requests/utils.pyt	   super_lenl   s@    	c         C   se  yGd d l  m  } m } d } x^ t D]V } y t j j d j |   } Wn t k
 r_ d SXt j j	 |  r& | } Pq& q& W| d k r d St
 |   } d } t |  t  r | j d  } n  | j j |  d }	 yG | |  j |	  }
 |
 r|
 d rd n d } |
 | |
 d	 f SWn# | t f k
 rE| rF  qFn XWn t t f k
 r`n Xd S(
   s;   Returns the Requests tuple auth for a given url from netrc.i(   t   netrct   NetrcParseErrors   ~/{}Nt   :t   asciii    i   i   (   RQ   RR   RB   t   NETRC_FILESRE   t   patht
   expandusert   formatt   KeyErrort   existsR   t
   isinstanceR   t   decodet   netlocR,   t   authenticatorsRK   R%   t   AttributeError(   t   urlt   raise_errorsRQ   RR   t
   netrc_patht   ft   loct   rit   splitstrR2   R   t   login_i(    (    s+   site-packages/pip/_vendor/requests/utils.pyt   get_netrc_auth   s8    c         C   s[   t  |  d d  } | rW t | t  rW | d d k rW | d d k rW t j j |  Sd S(   s0   Tries to guess the filename of the given object.t   namei    t   <it   >N(   t   getattrRB   R[   R   RE   RV   t   basename(   t   objRi   (    (    s+   site-packages/pip/_vendor/requests/utils.pyt   guess_filename   s    %c         C   s  t  j j |   r |  St  j j |   \ } } xJ | rz t  j j |  rz t  j j |  \ } } d j | | g  } q1 Wt j |  s |  St j |  } | | j   k r |  St	 j
   } t  j j | | j d   } t  j j |  s| j | d | } n  | S(   s   Replace nonexistent paths that look like they refer to a member of a zip
    archive with the location of an extracted copy of the target, or else
    just return the provided path unchanged.
    t   /RV   (   RE   RV   RZ   R,   t   joint   zipfilet
   is_zipfilet   ZipFilet   namelistt   tempfilet
   gettempdirt   extract(   RV   t   archivet   membert   prefixt   zip_filet   tmpt   extracted_path(    (    s+   site-packages/pip/_vendor/requests/utils.pyt   extract_zipped_paths   s     c         C   sD   |  d k r d St |  t t t t f  r: t d   n  t |   S(   s  Take an object and test to see if it can be represented as a
    dictionary. Unless it can not be represented as such, return an
    OrderedDict, e.g.,

    ::

        >>> from_key_val_list([('key', 'val')])
        OrderedDict([('key', 'val')])
        >>> from_key_val_list('string')
        Traceback (most recent call last):
        ...
        ValueError: cannot encode objects that are not 2-tuples
        >>> from_key_val_list({'key': 'val'})
        OrderedDict([('key', 'val')])

    :rtype: OrderedDict
    s+   cannot encode objects that are not 2-tuplesN(   RB   R[   R   R   t   boolR)   t
   ValueErrorR    (   t   value(    (    s+   site-packages/pip/_vendor/requests/utils.pyt   from_key_val_list  s
    c         C   sb   |  d k r d St |  t t t t f  r: t d   n  t |  t  rX |  j   }  n  t	 |   S(   s  Take an object and test to see if it can be represented as a
    dictionary. If it can be, return a list of tuples, e.g.,

    ::

        >>> to_key_val_list([('key', 'val')])
        [('key', 'val')]
        >>> to_key_val_list({'key': 'val'})
        [('key', 'val')]
        >>> to_key_val_list('string')
        Traceback (most recent call last):
        ...
        ValueError: cannot encode objects that are not 2-tuples

    :rtype: list
    s+   cannot encode objects that are not 2-tuplesN(
   RB   R[   R   R   R   R)   R   R   R8   t   list(   R   (    (    s+   site-packages/pip/_vendor/requests/utils.pyt   to_key_val_list  s    c         C   sh   g  } x[ t  |   D]M } | d  | d k o8 d k n rS t | d d ! } n  | j |  q W| S(   s  Parse lists as described by RFC 2068 Section 2.

    In particular, parse comma-separated lists where the elements of
    the list may include quoted-strings.  A quoted-string could
    contain a comma.  A non-quoted string could have quotes in the
    middle.  Quotes are removed automatically after parsing.

    It basically works like :func:`parse_set_header` just that items
    may appear multiple times and case sensitivity is preserved.

    The return value is a standard :class:`list`:

    >>> parse_list_header('token, "quoted value"')
    ['token', 'quoted value']

    To create a header from the :class:`list` again, use the
    :func:`dump_header` function.

    :param value: a string with a list header.
    :return: :class:`list`
    :rtype: list
    i   it   "(   t   _parse_list_headert   unquote_header_valuet   append(   R   t   resultt   item(    (    s+   site-packages/pip/_vendor/requests/utils.pyt   parse_list_header=  s    $c         C   s   i  } x t  |   D]~ } d | k r5 d | | <q n  | j d d  \ } }  |  d  |  d k ol d k n r t |  d d ! }  n  |  | | <q W| S(   s^  Parse lists of key, value pairs as described by RFC 2068 Section 2 and
    convert them into a python dict:

    >>> d = parse_dict_header('foo="is a fish", bar="as well"')
    >>> type(d) is dict
    True
    >>> sorted(d.items())
    [('bar', 'as well'), ('foo', 'is a fish')]

    If there is no value for a key it will be `None`:

    >>> parse_dict_header('key_without_value')
    {'key_without_value': None}

    To create a header from the :class:`dict` again, use the
    :func:`dump_header` function.

    :param value: a string with a dict header.
    :return: :class:`dict`
    :rtype: dict
    t   =i   iR   N(   R   RB   R,   R   (   R   R   R   Ri   (    (    s+   site-packages/pip/_vendor/requests/utils.pyt   parse_dict_header]  s    
$c         C   sq   |  rm |  d |  d k o% d k n rm |  d d !}  | sN |  d  d k rm |  j  d d  j  d d  Sn  |  S(	   s   Unquotes a header value.  (Reversal of :func:`quote_header_value`).
    This does not use the real unquoting but what browsers are actually
    using for quoting.

    :param value: the header value to unquote.
    :rtype: str
    i    iR   i   i   s   \\s   \s   \"(   R.   (   R   t   is_filename(    (    s+   site-packages/pip/_vendor/requests/utils.pyR     s
    *c         C   s+   i  } x |  D] } | j  | | j <q W| S(   s   Returns a key/value dictionary from a CookieJar.

    :param cj: CookieJar object to extract cookies from.
    :rtype: dict
    (   R   Ri   (   t   cjt   cookie_dictt   cookie(    (    s+   site-packages/pip/_vendor/requests/utils.pyt   dict_from_cookiejar  s    c         C   s   t  | |   S(   s   Returns a CookieJar from a key/value dictionary.

    :param cj: CookieJar to insert cookies into.
    :param cookie_dict: Dict of key/values to insert into CookieJar.
    :rtype: CookieJar
    (   R   (   R   R   (    (    s+   site-packages/pip/_vendor/requests/utils.pyt   add_dict_to_cookiejar  s    c         C   sv   t  j d t  t j d d t j } t j d d t j } t j d  } | j |   | j |   | j |   S(   sl   Returns encodings from given content string.

    :param content: bytestring to extract encodings from.
    s   In requests 3.0, get_encodings_from_content will be removed. For more information, please see the discussion on issue #2266. (This warning should only appear once.)s!   <meta.*?charset=["\']*(.+?)["\'>]t   flagss+   <meta.*?content=["\']*;?charset=(.+?)["\'>]s$   ^<\?xml.*?encoding=["\']*(.+?)["\'>](   RI   RJ   t   DeprecationWarningR/   t   compileR1   t   findall(   t   contentt
   charset_ret	   pragma_ret   xml_re(    (    s+   site-packages/pip/_vendor/requests/utils.pyt   get_encodings_from_content  s    c   
      C   s   |  j  d  } | d j   | d } } i  } d } x | D] } | j   } | r= | t } } | j d  }	 |	 d k r | |	  j |  } | |	 d j |  } n  | | | j   <q= q= W| | f S(   s   Returns content type and parameters from given header

    :param header: string
    :return: tuple containing content type and dictionary of
         parameters
    R   i    i   s   "' R   i(   R,   t   stripR-   t   findt   lower(
   t   headert   tokenst   content_typet   paramst   params_dictt   items_to_stript   paramt   keyR   t   index_of_equals(    (    s+   site-packages/pip/_vendor/requests/utils.pyt   _parse_content_type_header  s    c         C   s\   |  j  d  } | s d St |  \ } } d | k rH | d j d  Sd | k rX d Sd S(   s}   Returns encodings from given HTTP Header Dict.

    :param headers: dictionary to extract encoding from.
    :rtype: str
    s   content-typet   charsets   '"t   texts
   ISO-8859-1N(   t   getRB   R   R   (   t   headersR   R   (    (    s+   site-packages/pip/_vendor/requests/utils.pyt   get_encoding_from_headers  s    c         c   s   | j  d k r) x |  D] } | Vq Wd St j | j   d d  } x+ |  D]# } | j |  } | rK | VqK qK W| j d d t } | r | Vn  d S(   s   Stream decodes a iterator.Nt   errorsR.   t    t   final(   t   encodingRB   t   codecst   getincrementaldecoderR\   R-   (   t   iteratort   rR   t   decodert   chunkt   rv(    (    s+   site-packages/pip/_vendor/requests/utils.pyt   stream_decode_response_unicode  s    	c         c   sd   d } | d k s | d k r- t |   } n  x0 | t |   k  r_ |  | | | !V| | 7} q0 Wd S(   s    Iterate over slices of a string.i    N(   RB   R=   (   t   stringt   slice_lengtht   pos(    (    s+   site-packages/pip/_vendor/requests/utils.pyt   iter_slices  s    c         C   s   t  j d t  g  } t |  j  } | rc y t |  j |  SWqc t k
 r_ | j |  qc Xn  y t |  j | d d SWn t	 k
 r |  j SXd S(   s   Returns the requested content back in unicode.

    :param r: Response object to get unicode content from.

    Tried:

    1. charset from content-type
    2. fall back and replace all unicode characters

    :rtype: str
    s   In requests 3.0, get_unicode_from_response will be removed. For more information, please see the discussion on issue #2266. (This warning should only appear once.)R   R.   N(
   RI   RJ   R   R   R   R   R   t   UnicodeErrorR   t	   TypeError(   R   t   tried_encodingsR   (    (    s+   site-packages/pip/_vendor/requests/utils.pyt   get_unicode_from_response  s    t4   ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzs   0123456789-._~c         C   s   |  j  d  } x t d t |   D] } | | d d !} t |  d k r | j   r y t t | d   } Wn! t k
 r t d |   n X| t k r | | | d | | <q d | | | | <q% d | | | | <q% Wd j	 |  S(   s   Un-escape any percent-escape sequences in a URI that are unreserved
    characters. This leaves all reserved, illegal and non-ASCII bytes encoded.

    :rtype: str
    t   %i   i    i   i   s%   Invalid percent-escape sequence: '%s'R   (
   R,   t   rangeR=   t   isalnumt   chrR)   R   R   t   UNRESERVED_SETRq   (   t   urit   partst   it   ht   c(    (    s+   site-packages/pip/_vendor/requests/utils.pyt   unquote_unreserved:  s    c         C   sK   d } d } y t  t |   d | SWn t k
 rF t  |  d | SXd S(   s   Re-quote the given URI.

    This function passes the given URI through an unquote/quote cycle to
    ensure that it is fully and consistently quoted.

    :rtype: str
    s   !#$%&'()*+,/:;=?@[]~s   !#$&'()*+,/:;=?@[]~t   safeN(   R   R   R   (   R   t   safe_with_percentt   safe_without_percent(    (    s+   site-packages/pip/_vendor/requests/utils.pyt   requote_uriR  s    c         C   s   t  j d t j |    d } | j d  \ } } t  j d t j t t |     d } t  j d t j |   d | @} | | @| | @k S(   s   This function allows you to check if an IP belongs to a network subnet

    Example: returns True if ip = 192.168.1.1 and net = 192.168.1.0/24
             returns False if ip = 192.168.1.1 and net = 192.168.100.0/24

    :rtype: bool
    s   =Li    Rp   (   t   structt   unpackt   sockett	   inet_atonR,   t   dotted_netmaskR)   (   t   ipt   nett   ipaddrt   netaddrt   bitst   netmaskt   network(    (    s+   site-packages/pip/_vendor/requests/utils.pyt   address_in_networkh  s
    +#c         C   s/   d d d |  >d A} t  j t j d |   S(   s   Converts mask from /xx format to xxx.xxx.xxx.xxx

    Example: if mask is 24 function returns 255.255.255.0

    :rtype: str
    I    i   i    s   >I(   R   t	   inet_ntoaR   t   pack(   t   maskR   (    (    s+   site-packages/pip/_vendor/requests/utils.pyR   w  s    c         C   s-   y t  j |   Wn t  j k
 r( t SXt S(   s   
    :rtype: bool
    (   R   R   t   errorR&   R-   (   t	   string_ip(    (    s+   site-packages/pip/_vendor/requests/utils.pyt   is_ipv4_address  s
    c         C   s   |  j  d  d k r y t |  j d  d  } Wn t k
 rF t SX| d k  s_ | d k rc t Sy t j |  j d  d  Wq t j k
 r t SXn t St S(   sV   
    Very simple check of the cidr format in no_proxy variable.

    :rtype: bool
    Rp   i   i    i    (	   t   countR)   R,   R   R&   R   R   R   R-   (   t   string_networkR   (    (    s+   site-packages/pip/_vendor/requests/utils.pyt   is_valid_cidr  s    c         c   st   | d k	 } | r4 t j j |   } | t j |  <n  z	 d VWd | ro | d k r_ t j |  =qo | t j |  <n  Xd S(   s   Set the environment variable 'env_name' to 'value'

    Save previous value, yield, and then restore the previous value stored in
    the environment variable 'env_name'.

    If 'value' is None, do nothingN(   RB   RE   t   environR   (   t   env_nameR   t   value_changedt	   old_value(    (    s+   site-packages/pip/_vendor/requests/utils.pyt   set_environ  s    	c   	   
   C   s  d   } | } | d k r* | d  } n  t |   } | j d k rI t S| r3d   | j d d  j d  D } t | j  r x | D]> } t |  r t | j |  r t Sq | j | k r t Sq Wq3| j } | j	 r | d j
 | j	  7} n  x6 | D]+ } | j j |  s(| j |  rt SqWn  t d |  ; y t | j  } Wn  t t j f k
 rxt } n XWd QX| rt St S(	   sL   
    Returns whether we should bypass proxies or not.

    :rtype: bool
    c         S   s(   t  j j |   p' t  j j |  j    S(   N(   RE   R   R   t   upper(   t   k(    (    s+   site-packages/pip/_vendor/requests/utils.pyt   <lambda>  s    t   no_proxyc         s   s   |  ] } | r | Vq d  S(   N(    (   t   .0R2   (    (    s+   site-packages/pip/_vendor/requests/utils.pys	   <genexpr>  s    t    R   t   ,s   :{}N(   RB   R   t   hostnameR-   R.   R,   R   R   R   t   portRX   t   endswithR   R   R   R   t   gaierrorR&   (	   R`   R   t	   get_proxyt   no_proxy_argt   parsedt   proxy_ipt   host_with_portR2   t   bypass(    (    s+   site-packages/pip/_vendor/requests/utils.pyt   should_bypass_proxies  s<    	%		!c         C   s!   t  |  d | r i  St   Sd S(   sA   
    Return a dict of environment proxies.

    :rtype: dict
    R   N(   R   R
   (   R`   R   (    (    s+   site-packages/pip/_vendor/requests/utils.pyt   get_environ_proxies  s    c         C   s   | p	 i  } t  |   } | j d k rC | j | j | j d   S| j d | j | j d | j d g } d } x( | D]  } | | k rz | | } Pqz qz W| S(   s   Select a proxy for the url, if applicable.

    :param url: The url being for the request
    :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs
    t   alls   ://s   all://N(   R   R   RB   R   t   scheme(   R`   t   proxiest   urlpartst
   proxy_keyst   proxyt	   proxy_key(    (    s+   site-packages/pip/_vendor/requests/utils.pyt   select_proxy  s    
	
s   python-requestsc         C   s   d |  t  f S(   sO   
    Return a string representing the default user agent.

    :rtype: str
    s   %s/%s(   R   (   Ri   (    (    s+   site-packages/pip/_vendor/requests/utils.pyt   default_user_agent  s    c           C   s2   t  i t   d 6d j d
  d 6d d 6d d	 6 S(   s9   
    :rtype: requests.structures.CaseInsensitiveDict
    s
   User-Agents   , t   gzipt   deflates   Accept-Encodings   */*t   Accepts
   keep-alivet
   Connection(   R  R  (   R   R
  Rq   (    (    (    s+   site-packages/pip/_vendor/requests/utils.pyt   default_headers'  s
    
c   	      C   s
  g  } d } |  j  |  }  |  s% | Sx t j d |   D] } y | j d d  \ } } Wn t k
 rz | d } } n Xi | j  d  d 6} xa | j d  D]P } y | j d  \ } }  Wn t k
 r Pn X|  j  |  | | j  |  <q W| j |  q8 W| S(	   s   Return a list of parsed link headers proxies.

    i.e. Link: <http:/.../front.jpeg>; rel=front; type="image/jpeg",<http://.../back.jpeg>; rel=back;type="image/jpeg"

    :rtype: list
    s    '"s   , *<R   i   R   s   <> '"R`   R   (   R   R/   R,   R   R   (	   R   t   linkst   replace_charst   valR`   R   t   linkR   R   (    (    s+   site-packages/pip/_vendor/requests/utils.pyt   parse_header_links3  s&     s    RT   i   i   c         C   s   |  d  } | t  j t  j f k r& d S| d  t  j k r= d S| d  t  j t  j f k r] d S| j t  } | d k r| d S| d k r | d	 d	 d  t k r d
 S| d d	 d  t k r d Sn  | d k r | d  t	 k r d S| d t	 k r d Sn  d	 S(   s   
    :rtype: str
    i   s   utf-32i   s	   utf-8-sigi   s   utf-16i    s   utf-8Ns	   utf-16-bei   s	   utf-16-les	   utf-32-bes	   utf-32-le(   R   t   BOM_UTF32_LEt   BOM_UTF32_BEt   BOM_UTF8t   BOM_UTF16_LEt   BOM_UTF16_BER   t   _nullt   _null2t   _null3RB   (   t   datat   samplet	   nullcount(    (    s+   site-packages/pip/_vendor/requests/utils.pyt   guess_json_utf^  s*    
c         C   sS   t  |  |  \ } } } } } } | s7 | | } } n  t | | | | | | f  S(   s   Given a URL that may or may not have a scheme, prepend the given scheme.
    Does not replace a present scheme with the one provided as an argument.

    :rtype: str
    (   R   R   (   R`   t
   new_schemeR  R]   RV   R   t   queryt   fragment(    (    s+   site-packages/pip/_vendor/requests/utils.pyt   prepend_scheme_if_needed~  s    !c         C   sR   t  |   } y" t | j  t | j  f } Wn t t f k
 rM d } n X| S(   s{   Given a url with authentication components, extract them into a tuple of
    username,password.

    :rtype: (str,str)
    R   (   R   R   (   R   R	   t   usernamet   passwordR_   R   (   R`   R   t   auth(    (    s+   site-packages/pip/_vendor/requests/utils.pyt   get_auth_from_url  s    "
s   ^\S[^\r\n]*$|^$c         C   s   |  \ } } t  | t  r$ t } n t } y& | j |  sO t d |   n  Wn0 t k
 r t d | | t |  f   n Xd S(   s   Verifies that header value is a string which doesn't contain
    leading whitespace or return characters. This prevents unintended
    header injection.

    :param header: tuple, in the format (name, value).
    s7   Invalid return character or leading space in header: %ss>   Value for header {%s: %s} must be of type str or bytes, not %sN(   R[   R   t   _CLEAN_HEADER_REGEX_BYTEt   _CLEAN_HEADER_REGEX_STRR0   R   R   t   type(   R   Ri   R   t   pat(    (    s+   site-packages/pip/_vendor/requests/utils.pyt   check_header_validity  s    	c         C   sf   t  |   \ } } } } } } | s4 | | } } n  | j d d  d } t | | | | | d f  S(   sW   
    Given a url remove the fragment and the authentication part.

    :rtype: str
    t   @i   iR   (   R   t   rsplitR   (   R`   R  R]   RV   R   R"  R#  (    (    s+   site-packages/pip/_vendor/requests/utils.pyt   urldefragauth  s
    c         C   s}   t  |  j d d  } | d k	 rm t |  j t  rm y | |  j  Wqy t t f k
 ri t d   qy Xn t d   d S(   sf   Move file pointer back to its recorded starting position
    so it can be read again on redirect.
    RA   s;   An error occurred when rewinding request body for redirect.s+   Unable to rewind request body for redirect.N(	   Rl   t   bodyRB   R[   t   _body_positionR   RK   R+   R   (   t   prepared_requestt	   body_seek(    (    s+   site-packages/pip/_vendor/requests/utils.pyt   rewind_body  s    (   s   .netrcR   (d   t   __doc__R   t
   contextlibRC   RE   R/   R   R   t   sysRv   RI   Rr   t   collectionsR    R   R   R   t   _internal_utilsR   t   compatR   R   R   R   R   R   R	   R
   R   R   R   R   R   R   R   R   t   cookiesR   t
   structuresR   t
   exceptionsR   R   R   R   RU   t   wheret   DEFAULT_CA_BUNDLE_PATHt   DEFAULT_PORTSt   platformR7   R;   RP   R&   Rh   Ro   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t	   frozensetR   R   R   R   R   R   R   t   contextmanagerR   R   RB   R  R	  R
  R  R  t   encodeR  R  R  R   R$  R(  R   R)  R*  R-  R0  R5  (    (    (    s+   site-packages/pip/_vendor/requests/utils.pyt   <module>	   s   ^"	'			=3		 			 	#							
	%							=				&

	 				