ó
Ç1@]c           @   s  d  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	 m
 Z
 m Z m Z m Z m Z d d l m Z m Z m Z m Z d d l m Z m Z m Z d d	 l m Z m Z d d
 l m Z d d l m Z m Z m  Z  d d l! 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- m. Z. m/ Z/ d d l0 m1 Z1 d d l m2 Z2 e j3 d k rÄy e j4 Z5 Wn e6 k
 rÀe j7 Z5 n Xn	 e j Z5 e d „ Z8 e d „ Z9 d e: f d „  ƒ  YZ; d e; f d „  ƒ  YZ< d „  Z= d S(   s“   
requests.session
~~~~~~~~~~~~~~~~

This module provides a Session object to manage and persist settings across
requests (cookies, auth, proxies).
iÿÿÿÿN(   t	   timedeltai   (   t   _basic_auth_str(   t	   cookielibt   is_py3t   OrderedDictt   urljoint   urlparset   Mapping(   t   cookiejar_from_dictt   extract_cookies_to_jart   RequestsCookieJart   merge_cookies(   t   Requestt   PreparedRequestt   DEFAULT_REDIRECT_LIMIT(   t   default_hookst   dispatch_hook(   t   to_native_string(   t   to_key_val_listt   default_headerst   DEFAULT_PORTS(   t   TooManyRedirectst   InvalidSchemat   ChunkedEncodingErrort   ContentDecodingError(   t   CaseInsensitiveDict(   t   HTTPAdapter(   t   requote_urit   get_environ_proxiest   get_netrc_autht   should_bypass_proxiest   get_auth_from_urlt   rewind_body(   t   codes(   t   REDIRECT_STATIt   win32c         C   s´   | d k r |  S|  d k r  | St | t ƒ o; t |  t ƒ sB |  S| t | ƒ ƒ } | j t |  ƒ ƒ g  | j ƒ  D] \ } } | d k rt | ^ qt } x | D] } | | =qŸ W| S(   sè   Determines appropriate setting for a given request, taking into account
    the explicit setting on that request, and the setting in the session. If a
    setting is a dictionary, they will be merged together using `dict_class`
    N(   t   Nonet
   isinstanceR   R   t   updatet   items(   t   request_settingt   session_settingt
   dict_classt   merged_settingt   kt   vt	   none_keyst   key(    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt   merge_setting1   s    1c         C   sZ   | d k s! | j d ƒ g  k r% |  S|  d k sF |  j d ƒ g  k rJ | St |  | | ƒ S(   s©   Properly merges both requests and session hooks.

    This is necessary because when request_hooks == {'response': []}, the
    merge breaks Session hooks entirely.
    t   responseN(   R$   t   getR0   (   t   request_hookst   session_hooksR*   (    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt   merge_hooksP   s
    !!t   SessionRedirectMixinc           B   sP   e  Z d  „  Z d „  Z e d e d d e d „ Z d „  Z d „  Z	 d „  Z
 RS(   c         C   s?   | j  r; | j d } t r. | j d ƒ } n  t | d ƒ Sd S(   s7   Receives a Response. Returns a redirect URI or ``None``t   locationt   latin1t   utf8N(   t   is_redirectt   headersR   t   encodeR   R$   (   t   selft   respR7   (    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt   get_redirect_targeta   s    	c         C   sà   t  | ƒ } t  | ƒ } | j | j k r. t S| j d k rn | j d k rn | j d k rn | j d k rn t S| j | j k } | j | j k } t j | j d ƒ d f } | rÖ | j | k rÖ | j | k rÖ t S| pß | S(   sF   Decide whether Authorization header should be removed when redirectingt   httpiP   t   httpsi»  N(   iP   N(   i»  N(	   R   t   hostnamet   Truet   schemet   portR$   t   FalseR   R2   (   R=   t   old_urlt   new_urlt
   old_parsedt
   new_parsedt   changed_portt   changed_schemet   default_port(    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt   should_strip_authv   s    c	         k   s9  g  }
 |  j  | ƒ } t | j ƒ j } x| r4| j ƒ  } |
 j | ƒ |
 d | _ y | j Wn- t t	 t
 f k
 r | j j d t ƒ n Xt | j ƒ |  j k rÅ t d |  j d | ƒ‚ n  | j ƒ  | j d ƒ r	t | j ƒ } d t | j ƒ | f } n  t | ƒ } | j d k r?| r?| j d | ƒ } n | j rT| j } n  | j ƒ  } | j s„t | j t | ƒ ƒ } n t | ƒ } t | ƒ | _ |  j | | ƒ | j t j t j f k r d } x! | D] } | j j  | d ƒ q×Wd | _" n  | j } y | d =Wn t# k
 r'n Xt$ | j% | | j ƒ t& | j% |  j' ƒ | j( | j% ƒ |  j) | | ƒ } |  j* | | ƒ | j+ d k	 o§d	 | k p§d | k } | r½t, | ƒ n  | } | rÑ| Vq* |  j- | d | d | d | d | d | d t |	 } t$ |  j' | | j ƒ |  j  | ƒ } | Vq* Wd S(   sB   Receives a Response. Returns a generator of Responses or Requests.i   t   decode_contents   Exceeded %s redirects.R1   s   //s   %s:%st    t   fragments   Content-Lengths   Content-Types   Transfer-Encodingt   Cookiet   streamt   timeoutt   verifyt   certt   proxiest   allow_redirectsN(   s   Content-Lengths   Content-Types   Transfer-Encoding(.   R?   R   t   urlRQ   t   copyt   appendt   historyt   contentR   R   t   RuntimeErrort   rawt   readRF   t   lent   max_redirectsR   t   closet
   startswithR   RD   t   _replacet   geturlt   netlocR   R   t   rebuild_methodt   status_codeR!   t   temporary_redirectt   permanent_redirectR;   t   popR$   t   bodyt   KeyErrorR	   t   _cookiesR   t   cookiest   prepare_cookiest   rebuild_proxiest   rebuild_autht   _body_positionR    t   send(   R=   R>   t   reqRS   RT   RU   RV   RW   t   yield_requestst   adapter_kwargst   histRY   t   previous_fragmentt   prepared_requestt   parsed_rurlt   parsedt   purged_headerst   headerR;   t
   rewindable(    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt   resolve_redirects   s|    	
				c         C   s{   | j  } | j } d | k r@ |  j | j j | ƒ r@ | d =n  |  j rU t | ƒ n d } | d k	 rw | j | ƒ n  d S(   sé   When being redirected we may want to strip authentication from the
        request to avoid leaking credentials. This method intelligently removes
        and reapplies authentication where possible to avoid credential loss.
        t   AuthorizationN(   R;   RY   RN   t   requestt	   trust_envR   R$   t   prepare_auth(   R=   R{   R1   R;   RY   t   new_auth(    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyRs      s    		$
c         C   s5  | d k	 r | n i  } | j } | j } t | ƒ j } | j ƒ  } | j d ƒ } t | d | ƒ} |  j r¿ | r¿ t	 | d | ƒ}	 |	 j | |	 j d ƒ ƒ }
 |
 r¿ | j
 | |
 ƒ q¿ n  d | k rÕ | d =n  y t | | ƒ \ } } Wn t k
 rd \ } } n X| r1| r1t | | ƒ | d <n  | S(   s°  This method re-evaluates the proxy configuration by considering the
        environment variables. If we are redirected to a URL covered by
        NO_PROXY, we strip the proxy configuration. Otherwise, we set missing
        proxy keys for this URL (in case they were stripped by a previous
        redirect).

        This method also replaces the Proxy-Authorization header where
        necessary.

        :rtype: dict
        t   no_proxyt   alls   Proxy-AuthorizationN(   NN(   R$   R;   RY   R   RD   RZ   R2   R   R„   R   t
   setdefaultR   Rn   R   (   R=   R{   RW   R;   RY   RD   t   new_proxiesR‡   t   bypass_proxyt   environ_proxiest   proxyt   usernamet   password(    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyRr     s*    		
c         C   s‹   | j  } | j t j k r0 | d k r0 d } n  | j t j k rW | d k rW d } n  | j t j k r~ | d k r~ d } n  | | _  d S(   s‚   When being redirected we may want to change the method of the request
        based on certain specs or browser behavior.
        t   HEADt   GETt   POSTN(   t   methodRi   R!   t	   see_othert   foundt   moved(   R=   R{   R1   R“   (    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyRh   =  s    				N(   t   __name__t
   __module__R?   RN   RF   R$   RC   R   Rs   Rr   Rh   (    (    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyR6   _   s   		p		)t   Sessionc           B   s  e  Z d  Z d d d d d d d d d	 d
 d d d g Z d „  Z d „  Z d „  Z d „  Z d! d! d! d! d! d! d! e	 d! d! d! d! d! d! d „ Z
 d „  Z d „  Z d „  Z d! d! d „ Z d! d „ Z d! d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d  „  Z RS("   s€  A Requests session.

    Provides cookie persistence, connection-pooling, and configuration.

    Basic Usage::

      >>> import requests
      >>> s = requests.Session()
      >>> s.get('https://httpbin.org/get')
      <Response [200]>

    Or as a context manager::

      >>> with requests.Session() as s:
      >>>     s.get('https://httpbin.org/get')
      <Response [200]>
    R;   Rp   t   authRW   t   hookst   paramsRU   RV   t   prefetcht   adaptersRS   R„   Rb   c         C   s¥   t  ƒ  |  _ d  |  _ i  |  _ t ƒ  |  _ i  |  _ t |  _	 t
 |  _ d  |  _ t |  _ t
 |  _ t i  ƒ |  _ t ƒ  |  _ |  j d t ƒ  ƒ |  j d t ƒ  ƒ d  S(   Ns   https://s   http://(   R   R;   R$   Rš   RW   R   R›   Rœ   RF   RS   RC   RU   RV   R   Rb   R„   R   Rp   R   Rž   t   mountR   (   R=   (    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt   __init__m  s    								c         C   s   |  S(   N(    (   R=   (    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt	   __enter__¤  s    c         G   s   |  j  ƒ  d  S(   N(   Rc   (   R=   t   args(    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt   __exit__§  s    c         C   s*  | j  p i  } t | t j ƒ s0 t | ƒ } n  t t t ƒ  |  j  ƒ | ƒ } | j } |  j rƒ | rƒ |  j rƒ t	 | j
 ƒ } n  t ƒ  } | j d | j j ƒ  d | j
 d | j d | j d | j d t | j |  j d t ƒd t | j |  j ƒ d	 t | |  j ƒ d
 | d t | j |  j ƒ ƒ 
| S(   s‹  Constructs a :class:`PreparedRequest <PreparedRequest>` for
        transmission and returns it. The :class:`PreparedRequest` has settings
        merged from the :class:`Request <Request>` instance and those of the
        :class:`Session`.

        :param request: :class:`Request` instance to prepare with this
            session's settings.
        :rtype: requests.PreparedRequest
        R“   RY   t   filest   datat   jsonR;   R*   Rœ   Rš   Rp   R›   (   Rp   R%   R   t	   CookieJarR   R   R
   Rš   R„   R   RY   R   t   prepareR“   t   upperR¤   R¥   R¦   R0   R;   R   Rœ   R5   R›   (   R=   Rƒ   Rp   t   merged_cookiesRš   t   p(    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt   prepare_requestª  s*    
							c         C   sÇ   t  d | j ƒ  d | d | d | d | p- i  d | d | p? i  d | d	 | d
 | ƒ 
} |  j | ƒ } | po i  } |  j | j | | | | ƒ } i |	 d 6|
 d 6} | j | ƒ |  j | |  } | S(   s  Constructs a :class:`Request <Request>`, prepares it and sends it.
        Returns :class:`Response <Response>` object.

        :param method: method for the new :class:`Request` object.
        :param url: URL for the new :class:`Request` object.
        :param params: (optional) Dictionary or bytes to be sent in the query
            string for the :class:`Request`.
        :param data: (optional) Dictionary, list of tuples, bytes, or file-like
            object to send in the body of the :class:`Request`.
        :param json: (optional) json to send in the body of the
            :class:`Request`.
        :param headers: (optional) Dictionary of HTTP Headers to send with the
            :class:`Request`.
        :param cookies: (optional) Dict or CookieJar object to send with the
            :class:`Request`.
        :param files: (optional) Dictionary of ``'filename': file-like-objects``
            for multipart encoding upload.
        :param auth: (optional) Auth tuple or callable to enable
            Basic/Digest/Custom HTTP Auth.
        :param timeout: (optional) How long to wait for the server to send
            data before giving up, as a float, or a :ref:`(connect timeout,
            read timeout) <timeouts>` tuple.
        :type timeout: float or tuple
        :param allow_redirects: (optional) Set to True by default.
        :type allow_redirects: bool
        :param proxies: (optional) Dictionary mapping protocol or protocol and
            hostname to the URL of the proxy.
        :param stream: (optional) whether to immediately download the response
            content. Defaults to ``False``.
        :param verify: (optional) Either a boolean, in which case it controls whether we verify
            the server's TLS certificate, or a string, in which case it must be a path
            to a CA bundle to use. Defaults to ``True``.
        :param cert: (optional) if String, path to ssl client cert file (.pem).
            If Tuple, ('cert', 'key') pair.
        :rtype: requests.Response
        R“   RY   R;   R¤   R¥   R¦   Rœ   Rš   Rp   R›   RT   RX   (   R   R©   R¬   t   merge_environment_settingsRY   R&   Ru   (   R=   R“   RY   Rœ   R¥   R;   Rp   R¤   Rš   RT   RX   RW   R›   RS   RU   RV   R¦   Rv   t   prept   settingst   send_kwargsR>   (    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyRƒ   Ò  s*    )	
c         K   s#   | j  d t ƒ |  j d | |  S(   så   Sends a GET request. Returns :class:`Response` object.

        :param url: URL for the new :class:`Request` object.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        RX   R‘   (   R‰   RC   Rƒ   (   R=   RY   t   kwargs(    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyR2     s    c         K   s#   | j  d t ƒ |  j d | |  S(   sé   Sends a OPTIONS request. Returns :class:`Response` object.

        :param url: URL for the new :class:`Request` object.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        RX   t   OPTIONS(   R‰   RC   Rƒ   (   R=   RY   R±   (    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt   options$  s    c         K   s#   | j  d t ƒ |  j d | |  S(   sæ   Sends a HEAD request. Returns :class:`Response` object.

        :param url: URL for the new :class:`Request` object.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        RX   R   (   R‰   RF   Rƒ   (   R=   RY   R±   (    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt   head/  s    c         K   s   |  j  d | d | d | | S(   sÈ  Sends a POST request. Returns :class:`Response` object.

        :param url: URL for the new :class:`Request` object.
        :param data: (optional) Dictionary, list of tuples, bytes, or file-like
            object to send in the body of the :class:`Request`.
        :param json: (optional) json to send in the body of the :class:`Request`.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        R’   R¥   R¦   (   Rƒ   (   R=   RY   R¥   R¦   R±   (    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt   post:  s    c         K   s   |  j  d | d | | S(   su  Sends a PUT request. Returns :class:`Response` object.

        :param url: URL for the new :class:`Request` object.
        :param data: (optional) Dictionary, list of tuples, bytes, or file-like
            object to send in the body of the :class:`Request`.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        t   PUTR¥   (   Rƒ   (   R=   RY   R¥   R±   (    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt   putG  s    
c         K   s   |  j  d | d | | S(   sw  Sends a PATCH request. Returns :class:`Response` object.

        :param url: URL for the new :class:`Request` object.
        :param data: (optional) Dictionary, list of tuples, bytes, or file-like
            object to send in the body of the :class:`Request`.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        t   PATCHR¥   (   Rƒ   (   R=   RY   R¥   R±   (    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt   patchS  s    
c         K   s   |  j  d | |  S(   sè   Sends a DELETE request. Returns :class:`Response` object.

        :param url: URL for the new :class:`Request` object.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        t   DELETE(   Rƒ   (   R=   RY   R±   (    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt   delete_  s    c         K   s  | j  d |  j ƒ | j  d |  j ƒ | j  d |  j ƒ | j  d |  j ƒ t | t ƒ rj t d ƒ ‚ n  | j d t	 ƒ } | j
 d ƒ } | j } |  j d | j ƒ } t ƒ  } | j | |  } t ƒ  | }	 t d |	 ƒ | _ t d	 | | |  } | j r1x- | j D] }
 t |  j |
 j |
 j ƒ qWn  t |  j | | j ƒ |  j | | |  } | r{g  | D] }
 |
 ^ qin g  } | r¯| j d
 | ƒ | j ƒ  } | | _ n  | sôy( t |  j | | d t	 | ƒ | _ Wqôt k
 rðqôXn  | s| j n  | S(   sI   Send a given PreparedRequest.

        :rtype: requests.Response
        RS   RU   RV   RW   s#   You can only send PreparedRequests.RX   RY   t   secondsR1   i    Rw   (   R‰   RS   RU   RV   RW   R%   R   t
   ValueErrorRl   RC   R2   R›   t   get_adapterRY   t   preferred_clockRu   R    t   elapsedR   R\   R	   Rp   Rƒ   R_   R   t   insertt   nextt   _nextt   StopIterationR]   (   R=   Rƒ   R±   RX   RS   R›   t   adaptert   startt   rRÀ   R>   t   genR\   (    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyRu   i  sB    			 %(
c   
      C   s  |  j  r« | d k	 r$ | j d ƒ n d } t | d | ƒ} x* | j ƒ  D] \ } }	 | j | |	 ƒ qI W| t k s | d k r« t j j d ƒ p¢ t j j d ƒ } q« n  t	 | |  j
 ƒ } t	 | |  j ƒ } t	 | |  j ƒ } t	 | |  j ƒ } i | d 6| d 6| d 6| d 6S(	   s^   
        Check the environment and merge it with some settings.

        :rtype: dict
        R‡   t   REQUESTS_CA_BUNDLEt   CURL_CA_BUNDLERU   RW   RS   RV   N(   R„   R$   R2   R   R'   R‰   RC   t   ost   environR0   RW   RS   RU   RV   (
   R=   RY   RW   RS   RU   RV   R‡   t   env_proxiesR,   R-   (    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyR­   ²  s    	!c         C   sS   x< |  j  j ƒ  D]+ \ } } | j ƒ  j | j ƒ  ƒ r | Sq Wt d | ƒ ‚ d S(   s~   
        Returns the appropriate connection adapter for the given URL.

        :rtype: requests.adapters.BaseAdapter
        s*   No connection adapters were found for '%s'N(   Rž   R'   t   lowerRd   R   (   R=   RY   t   prefixRÅ   (    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyR¾   Ï  s    c         C   s(   x! |  j  j ƒ  D] } | j ƒ  q Wd S(   s+   Closes all adapters and as such the sessionN(   Rž   t   valuesRc   (   R=   R-   (    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyRc   Ý  s    c         C   so   | |  j  | <g  |  j  D]$ } t | ƒ t | ƒ k  r | ^ q } x' | D] } |  j  j | ƒ |  j  | <qH Wd S(   sw   Registers a connection adapter to a prefix.

        Adapters are sorted in descending order by prefix length.
        N(   Rž   Ra   Rl   (   R=   RÏ   RÅ   R,   t   keys_to_moveR/   (    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyRŸ   â  s    4c            s   ‡  f d †  ˆ  j  Dƒ } | S(   Nc            s%   i  |  ] } t  ˆ  | d  ƒ | “ q S(   N(   t   getattrR$   (   t   .0t   attr(   R=   (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pys
   <dictcomp>î  s   	 (   t	   __attrs__(   R=   t   state(    (   R=   s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt   __getstate__í  s    c         C   s1   x* | j  ƒ  D] \ } } t |  | | ƒ q Wd  S(   N(   R'   t   setattr(   R=   RÖ   RÔ   t   value(    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt   __setstate__ñ  s    N(   R—   R˜   t   __doc__RÕ   R    R¡   R£   R¬   R$   RC   Rƒ   R2   R³   R´   Rµ   R·   R¹   R»   Ru   R­   R¾   Rc   RŸ   R×   RÚ   (    (    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyR™   T  s2   		7			)D				
	I					c           C   s   t  ƒ  S(   sZ  
    Returns a :class:`Session` for context-management.

    .. deprecated:: 1.0.0

        This method has been deprecated since version 1.0.0 and is only kept for
        backwards compatibility. New code should use :class:`~requests.sessions.Session`
        to create a session. This may be removed at a future date.

    :rtype: Session
    (   R™   (    (    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt   sessionö  s    (>   RÛ   RË   t   syst   timet   datetimeR    Rš   R   t   compatR   R   R   R   R   R   Rp   R   R	   R
   R   t   modelsR   R   R   R›   R   R   t   _internal_utilsR   t   utilsR   R   R   t
   exceptionsR   R   R   R   t
   structuresR   Rž   R   R   R   R   R   R   R    t   status_codesR!   R"   t   platformt   perf_counterR¿   t   AttributeErrort   clockR0   R5   t   objectR6   R™   RÜ   (    (    (    s<   lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt   <module>	   s:   ."".	õÿ £