Your IP : 52.15.71.146


Current Path : /lib/python2.7/site-packages/pip/_vendor/requests/
Upload File :
Current File : //lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyo

�
��abc@s+dZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZmZm
Z
mZmZddlmZmZmZmZdd	lmZmZmZdd
lmZmZddlmZddlmZm Z dd
l!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'ddl(m)Z)ddlm*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0ddl1m2Z2ddlm3Z3ej4�dkr�y
ej5Z6Wne7k
r�ej8Z6nXn	ejZ6e
d�Z9e
d�Z:de;fd��YZ<de<fd��YZ=d�Z>dS(s�
requests.session
~~~~~~~~~~~~~~~~

This module provides a Session object to manage and persist settings across
requests (cookies, auth, proxies).
i����N(tMapping(t	timedeltai(t_basic_auth_str(t	cookielibtis_py3tOrderedDictturljointurlparse(tcookiejar_from_dicttextract_cookies_to_jartRequestsCookieJart
merge_cookies(tRequesttPreparedRequesttDEFAULT_REDIRECT_LIMIT(t
default_hookst
dispatch_hook(tto_native_string(tto_key_val_listtdefault_headers(tTooManyRedirectst
InvalidSchematChunkedEncodingErrortContentDecodingError(tCaseInsensitiveDict(tHTTPAdapter(trequote_uritget_environ_proxiestget_netrc_authtshould_bypass_proxiestget_auth_from_urltrewind_bodyt
DEFAULT_PORTS(tcodes(tREDIRECT_STATItWindowscCs�|dkr|S|dkr |St|t�o;t|t�sB|S|t|��}|jt|��g|j�D]\}}|dkrt|^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(tNonet
isinstanceRRtupdatetitems(trequest_settingtsession_settingt
dict_classtmerged_settingtktvt	none_keystkey((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt
merge_setting2s1
cCsZ|dks!|jd�gkr%|S|dksF|jd�gkrJ|St|||�S(s�Properly merges both requests and session hooks.

    This is necessary because when request_hooks == {'response': []}, the
    merge breaks Session hooks entirely.
    tresponseN(R$tgetR0(t
request_hookst
session_hooksR*((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytmerge_hooksQs
!!tSessionRedirectMixincBsPeZd�Zd�Zededded�Zd�Zd�Z	d�Z
RS(cCs?|jr;|jd}tr.|jd�}nt|d�SdS(s7Receives a Response. Returns a redirect URI or ``None``tlocationtlatin1tutf8N(tis_redirecttheadersRtencodeRR$(tselftrespR7((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytget_redirect_targetbs	

cCs�t|�}t|�}|j|jkr.tS|jdkrn|jdkrn|jdkrn|jdkrntS|j|jk}|j|jk}tj|jd�df}|r�|j|kr�|j|kr�tS|p�|S(sFDecide whether Authorization header should be removed when redirectingthttpiPthttpsi�N(iPN(i�N(	RthostnametTruetschemetportR$tFalseR R2(R=told_urltnew_urlt
old_parsedt
new_parsedtchanged_porttchanged_schemetdefault_port((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytshould_strip_authxsc	ks�g}
|j|�}x�|r�|j�}|
j|�|
d|_y|jWn-tttfk
r~|jj	dt
�nXt|j�|jkr�t
d|jd|��n|j�|jd�r�t|j�}
dt|
j�|f}nt|�}|j�}|js3t|jt|��}nt|�}t|�|_|j||�|jtjtjfkr�d}x!|D]}|jj|d�q�Wd|_ n|j}y|d
=Wnt!k
r�nXt"|j#||j�t$|j#|j%�|j&|j#�|j'||�}|j(||�|j)dk	oVd|kpVd	|k}|rlt*|�n|}|r�|Vq|j+|d|d|d
|d|d|dt
|	�}t"|j%||j�|j|�}|VqWdS(sBReceives a Response. Returns a generator of Responses or Requests.itdecode_contentsExceeded %s redirects.R1s//s%s:%ssContent-LengthsContent-TypesTransfer-EncodingtCookietstreamttimeouttverifytcerttproxiestallow_redirectsN(sContent-LengthsContent-TypesTransfer-Encoding(,R?tcopytappendthistorytcontentRRtRuntimeErrortrawtreadRFtlent
max_redirectsRtcloset
startswithRturlRRDtgeturltnetlocRRtrebuild_methodtstatus_codeR!ttemporary_redirecttpermanent_redirectR;tpopR$tbodytKeyErrorR	t_cookiesRtcookiestprepare_cookiestrebuild_proxiestrebuild_autht_body_positionRtsend(R=R>treqRQRRRSRTRUtyield_requeststadapter_kwargsthistRbtprepared_requesttparsed_rurltparsedtpurged_headerstheaderR;t
rewindable((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytresolve_redirects�sr	


	
	

	cCs{|j}|j}d|kr@|j|jj|�r@|d=n|jrUt|�nd}|dk	rw|j|�ndS(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;RbRNtrequestt	trust_envRR$tprepare_auth(R=RwR1R;Rbtnew_auth((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyRp�s		$
c
Cs5|dk	r|ni}|j}|j}t|�j}|j�}|jd�}t|d|�}|jr�|r�t	|d|�}	|	j||	jd��}
|
r�|j
||
�q�nd|kr�|d=nyt||�\}}Wntk
rd\}}nX|r1|r1t
||�|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
        tno_proxytallsProxy-AuthorizationN(NN(R$R;RbRRDRWR2RR�Rt
setdefaultRRkR(
R=RwRUR;RbRDtnew_proxiesR�tbypass_proxytenviron_proxiestproxytusernametpassword((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyRos*		

cCs�|j}|jtjkr0|dkr0d}n|jtjkrW|dkrWd}n|jtjkr~|dkr~d}n||_dS(s�When being redirected we may want to change the method of the request
        based on certain specs or browser behavior.
        tHEADtGETtPOSTN(tmethodRfR!t	see_othertfoundtmoved(R=RwR1R�((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyRe:s				N(t__name__t
__module__R?RNRFR$RCR}RpRoRe(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyR6`s		k		)tSessioncBseZdZddddddddd	d
ddd
g
Zd�Zd�Zd�Zd�Zd!d!d!d!d!d!d!e	d!d!d!d!d!d!d�Z
d�Zd�Zd�Z
d!d!d�Zd!d�Zd!d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd �ZRS("s~A Requests session.

    Provides cookie persistence, connection-pooling, and configuration.

    Basic Usage::

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

    Or as a context manager::

      >>> with requests.Session() as s:
      >>>     s.get('http://httpbin.org/get')
      <Response [200]>
    R;RmtauthRUthookstparamsRSRTtprefetchtadaptersRQR�R_cCs�t�|_d|_i|_t�|_i|_t|_	t
|_d|_t
|_t
|_ti�|_t�|_|jdt��|jdt��dS(Nshttps://shttp://(RR;R$R�RURR�R�RFRQRCRSRTRR_R�RRmRR�tmountR(R=((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt__init__js								cCs|S(N((R=((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt	__enter__�scGs|j�dS(N(R`(R=targs((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt__exit__�scCs*|jpi}t|tj�s0t|�}nttt�|j�|�}|j}|jr�|r�|jr�t	|j
�}nt�}|jd|j
j�d|j
d|jd|jd|jdt|j|jdt�dt|j|j�d	t||j�d
|dt|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�RbtfilestdatatjsonR;R*R�R�RmR�(RmR%Rt	CookieJarRRR
R�R�RRbR
tprepareR�tupperR�R�R�R0R;RR�R5R�(R=RRmtmerged_cookiesR�tp((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytprepare_request�s*
							cCs�td|j�d|d|d|d|p-id|d|p?id|d	|d
|�
}|j|�}|poi}|j|j||
||�}i|	d6|
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, 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�RbR;R�R�R�R�R�RmR�RRRV(RR�R�tmerge_environment_settingsRbR&Rr(R=R�RbR�R�R;RmR�R�RRRVRUR�RQRSRTR�Rstpreptsettingstsend_kwargsR>((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyR�s*)	

cKs#|jdt�|jd||�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
        RVR�(R�RCR(R=Rbtkwargs((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyR2scKs#|jdt�|jd||�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
        RVtOPTIONS(R�RCR(R=RbR�((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytoptions!scKs#|jdt�|jd||�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
        RVR�(R�RFR(R=RbR�((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pythead,scKs|jd|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, 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=RbR�R�R�((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytpost7s
cKs|jd|d||�S(sYSends a PUT request. Returns :class:`Response` object.

        :param url: URL for the new :class:`Request` object.
        :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        tPUTR�(R(R=RbR�R�((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytputCs	cKs|jd|d||�S(s[Sends a PATCH request. Returns :class:`Response` object.

        :param url: URL for the new :class:`Request` object.
        :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype: requests.Response
        tPATCHR�(R(R=RbR�R�((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytpatchNs	cKs|jd||�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
        tDELETE(R(R=RbR�((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytdeleteYsc
Ks|jd|j�|jd|j�|jd|j�|jd|j�t|t�rjtd��n|jdt	�}|j
d�}|j}|jd|j
�}t�}|j||�}t�|}	td|	�|_td	|||�}|jr1x-|jD]}
t|j|
j|
j�qWnt|j||j�|j|||�}|r{g|D]}
|
^qing}|r�|jd
|�|j�}||_n|s�y(t|j||dt	|��|_Wq�tk
r�q�Xn|s|jn|S(sISend a given PreparedRequest.

        :rtype: requests.Response
        RQRSRTRUs#You can only send PreparedRequests.RVRbtsecondsR1iRt(R�RQRSRTRUR%Rt
ValueErrorRiRCR2R�tget_adapterRbtpreferred_clockRrRtelapsedRRYR	RmRR\R}tinserttnextt_nextt
StopIterationRZ(
R=RR�RVRQR�tadaptertstarttrR�R>tgenRY((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyRrcsB		
	 %(

c
Cs|jr�|dk	r$|jd�nd}t|d|�}x*|j�D]\}}	|j||	�qIW|tks�|dkr�tjjd�p�tjjd�}q�nt	||j
�}t	||j�}t	||j�}t	||j
�}i|d6|d6|d6|d6S(	s^
        Check the environment and merge it with some settings.

        :rtype: dict
        R�tREQUESTS_CA_BUNDLEtCURL_CA_BUNDLERSRURQRTN(R�R$R2RR'R�RCtostenvironR0RURQRSRT(
R=RbRURQRSRTR�tenv_proxiesR,R-((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyR��s	!cCsMx6|jj�D]%\}}|j�j|�r|SqWtd|��dS(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'tlowerRaR(R=RbtprefixR�((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyR��scCs(x!|jj�D]}|j�qWdS(s+Closes all adapters and as such the sessionN(R�tvaluesR`(R=R-((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyR`�scCso||j|<g|jD]$}t|�t|�kr|^q}x'|D]}|jj|�|j|<qHWdS(swRegisters a connection adapter to a prefix.

        Adapters are sorted in descending order by prefix length.
        N(R�R^Ri(R=R�R�R,tkeys_to_moveR/((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyR��s
4
cs#t�fd��jD��}|S(Nc3s'|]}|t�|d�fVqdS(N(tgetattrR$(t.0tattr(R=(sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pys	<genexpr>�s(tdictt	__attrs__(R=tstate((R=sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt__getstate__�scCs1x*|j�D]\}}t|||�q
WdS(N(R'tsetattr(R=R�R�tvalue((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt__setstate__�sN(R�R�t__doc__R�R�R�R�R�R$RCRR2R�R�R�R�R�R�RrR�R�R`R�R�R�(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyR�Qs2		7			)D				
	I					cCst�S(sQ
    Returns a :class:`Session` for context-management.

    :rtype: Session
    (R�(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytsession�s(?R�R�tplatformttimetcollectionsRtdatetimeRR�RtcompatRRRRRRmRR	R
RtmodelsRR
RR�RRt_internal_utilsRtutilsRRt
exceptionsRRRRt
structuresRR�RRRRRRRR tstatus_codesR!R"tsystemtperf_counterR�tAttributeErrortclockR0R5tobjectR6R�R�(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt<module>	s<(""4

	���

?>