%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core/17212/usr/lib/python3/dist-packages/requests/__pycache__/
Upload File :
Create Path :
Current File : //snap/core/17212/usr/lib/python3/dist-packages/requests/__pycache__/sessions.cpython-35.pyc



ꩈd�c�@s�dZddlZddlmZddlmZddlmZddlmZm	Z	m
Z
mZddlm
Z
mZmZmZdd	lmZmZmZdd
lmZmZddlmZmZmZddlmZmZmZm Z dd
l!m"Z"ddl#m$Z$ddl%m&Z&ddlm'Z'm(Z(m)Z)m*Z*m+Z+ddl,m-Z-ddlm.Z.dZ/e	dd�Z0e	dd�Z1Gdd�de2�Z3Gdd�de3�Z4dd�Z5dS)z�
requests.session
~~~~~~~~~~~~~~~~

This module provides a Session object to manage and persist settings across
requests (cookies, auth, proxies).

�N)�Mapping)�datetime�)�_basic_auth_str)�	cookielib�OrderedDict�urljoin�urlparse)�cookiejar_from_dict�extract_cookies_to_jar�RequestsCookieJar�
merge_cookies)�Request�PreparedRequest�DEFAULT_REDIRECT_LIMIT)�
default_hooks�
dispatch_hook)�to_key_val_list�default_headers�to_native_string)�TooManyRedirects�
InvalidSchema�ChunkedEncodingError�ContentDecodingError)�RecentlyUsedContainer)�CaseInsensitiveDict)�HTTPAdapter)�requote_uri�get_environ_proxies�get_netrc_auth�should_bypass_proxies�get_auth_from_url)�codes)�REDIRECT_STATIi�cCs�|dkr|S|dkr |St|t�o;t|t�sB|S|t|��}|jt|��dd�|j�D�}x|D]
}||=q�W|S)z�
    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`
    NcSs(g|]\}}|dkr|�qS)N�)�.0�k�vr$r$�3/usr/lib/python3/dist-packages/requests/sessions.py�
<listcomp>Cs	z!merge_setting.<locals>.<listcomp>)�
isinstancerr�update�items)Zrequest_settingZsession_setting�
dict_classZmerged_settingZ	none_keys�keyr$r$r(�
merge_setting*s
r/cCsZ|dks!|jd�gkr%|S|dksF|jd�gkrJ|St|||�S)z�
    Properly merges both requests and session hooks.

    This is necessary because when request_hooks == {'response': []}, the
    merge breaks Session hooks entirely.
    N�response)�getr/)Z
request_hooksZ
session_hooksr-r$r$r(�merge_hooksJs
!!r2c@sOeZdZdd�Zddddddd�Zdd	�Zd
d�ZdS)�SessionRedirectMixincCs�t|�}t|�}|j|jkr.dS|jdkrn|jdkrn|jdkrn|jd	krndS|j|jkp�|j|jkS)
zFDecide whether Authorization header should be removed when redirectingTZhttp�PN�https�F)r4N)r6N)r	Zhostname�schemeZport)�selfZold_url�new_urlZ
old_parsedZ
new_parsedr$r$r(�should_strip_auth[sz&SessionRedirectMixin.should_strip_authFNTcks%d}	g}
x|jr |j�}|	dkrR|
j|�t|
�}||_y|jWn.tttfk
r�|j	j
dd�YnX|	|jkr�td|j��|j
�|jd}
|j}|
jd�rt|j�}d|j|
f}
t|
�}|j�}
|js=t|jt|
��}
nt|
�}
t|
�|_|jr�|j|jkr�|j|j|j<|jtjkr�|dkr�d	}|jtjkr�|dkr�d	}|jtjkr�|d
kr�d	}||_|jtj tj!fkr8d|jkr/|jd=d|_"|j}y|d
=Wnt#k
r`YnXt$|j%||j	�|j%j&|j'�|j(|j%�|j)||�}|j*||�|}|j+|d|d|d|d|d|dd|�}t$|j'||j	�|	d7}	|VqWdS)z6Receives a Response. Returns a generator of Responses.rZdecode_contentFzExceeded %s redirects.�locationz//z%s:%s�HEAD�GET�POSTzContent-LengthNZCookie�stream�timeout�verify�cert�proxies�allow_redirectsr),Zis_redirect�copy�append�list�history�contentrr�RuntimeError�raw�read�
max_redirectsr�close�headers�method�
startswithr	�urlr7ZgeturlZnetlocrrrZis_permanent_redirect�redirect_cacheZstatus_coder"Z	see_other�foundZmovedZtemporary_redirectZpermanent_redirectZbody�KeyErrorrZ_cookiesr+�cookiesZprepare_cookies�rebuild_proxies�rebuild_auth�send)r8�resp�reqr?r@rArBrCZadapter_kwargs�iZhist�prepared_requestZnew_histrRrPZparsed_rurlZparsedrOr$r$r(�resolve_redirectsks~
	

			
		
	
z&SessionRedirectMixin.resolve_redirectscCsu|j}|j}d|kr=|j|jj|�r=|d=|jrRt|�nd}|dk	rq|j|�dS)z�
        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.
        Z
AuthorizationN)rOrRr:�request�	trust_envrZprepare_auth)r8r]r0rOrRZnew_authr$r$r(rX�s		$
z!SessionRedirectMixin.rebuild_authcCs|j}|j}t|�j}|dk	r9|j�ni}|jr�t|�r�t|�}|j|�}|r�|j	|||�d|kr�|d=yt
||�\}	}
Wntk
r�d\}	}
YnX|jd�r|	r|
rt
|	|
�|d<|S)a�
        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.
        NzProxy-Authorizationr5)NN)rOrRr	r7rEr`r rr1�
setdefaultr!rUrQr)r8r]rCrOrRr7Znew_proxiesZenviron_proxies�proxyZusernameZpasswordr$r$r(rW�s$		
z$SessionRedirectMixin.rebuild_proxies)�__name__�
__module__�__qualname__r:r^rXrWr$r$r$r(r3Zs
or3c@s]eZdZdZdddddddd	d
ddd
dg
Zdd�Zdd�Zdd�Zdd�Zdddddddddddddddd�Z	dd�Z
dd�Zdd �Zddd!d"�Z
dd#d$�Zdd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�ZdS)7�Sessiona~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]>
    rOrV�authrC�hooks�paramsrArBZprefetch�adaptersr?r`rMcCs�t�|_d|_i|_t�|_i|_d|_d|_d|_	t
|_d|_t
i�|_t�|_|jdt��|jdt��tt�|_dS)NFTzhttps://zhttp://)rrOrgrCrrhrir?rArBrrMr`r
rVrrj�mountrr�REDIRECT_CACHE_SIZErS)r8r$r$r(�__init__1s								zSession.__init__cCs|S)Nr$)r8r$r$r(�	__enter__hszSession.__enter__cGs|j�dS)N)rN)r8�argsr$r$r(�__exit__kszSession.__exit__cCs$|jpi}t|tj�s-t|�}ttt�|j�|�}|j}|jr}|r}|jr}t	|j
�}t�}|jd|j
j�d|j
d|jd|jd|jdt|j|jdt�dt|j|j�d	t||j�d
|dt|j|j��
|S)abConstructs 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.
        rPrR�files�data�jsonrOr-rirgrVrh)rVr*rZ	CookieJarr
r
rrgr`rrRrZpreparerP�upperrqrrrsr/rOrrir2rh)r8r_rVZmerged_cookiesrg�pr$r$r(�prepare_requestns*								zSession.prepare_requestNTcCs�td|j�d|d|d|d|p-id|d|p?id|d	|d
|�
}|j|�}|poi}|j|j||
||�}d|	d|
i}|j|�|j||�}|S)
aqConstructs 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) whether the SSL cert will be verified.
            A CA_BUNDLE path can also be provided. Defaults to ``True``.
        :param cert: (optional) if String, path to ssl client cert file (.pem).
            If Tuple, ('cert', 'key') pair.
        rPrRrOrqrrrsrirgrVrhr@rD)rrtrv�merge_environment_settingsrRr+rY)r8rPrRrirrrOrVrqrgr@rDrCrhr?rArBrsr[ZprepZsettingsZsend_kwargsrZr$r$r(r_�s(2	
zSession.requestcKs#|jdd�|jd||�S)z�Sends a GET request. Returns :class:`Response` object.

        :param url: URL for the new :class:`Request` object.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        rDTr=)rar_)r8rR�kwargsr$r$r(r1�szSession.getcKs#|jdd�|jd||�S)z�Sends a OPTIONS request. Returns :class:`Response` object.

        :param url: URL for the new :class:`Request` object.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        rDTZOPTIONS)rar_)r8rRrxr$r$r(�options�szSession.optionscKs#|jdd�|jd||�S)z�Sends a HEAD request. Returns :class:`Response` object.

        :param url: URL for the new :class:`Request` object.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        rDFr<)rar_)r8rRrxr$r$r(�head�szSession.headcKs|jd|d|d||�S)a�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.
        r>rrrs)r_)r8rRrrrsrxr$r$r(�posts	zSession.postcKs|jd|d||�S)a7Sends 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.
        ZPUTrr)r_)r8rRrrrxr$r$r(�putszSession.putcKs|jd|d||�S)a9Sends 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.
        ZPATCHrr)r_)r8rRrrrxr$r$r(�patchsz
Session.patchcKs|jd||�S)z�Sends a DELETE request. Returns :class:`Response` object.

        :param url: URL for the new :class:`Request` object.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        ZDELETE)r_)r8rRrxr$r$r(�delete#szSession.deletecKs|jd|j�|jd|j�|jd|j�|jd|j�t|t�sgtd��t�}xQ|j	|j
kr�|j|j	�|j
j|j	�}||kr�P||_	qsW|j
dd�}|jd�}|j}|jd|j	�}tj�}	|j||�}
tj�|	|
_td	||
|�}
|
jrx*|
jD]}t|j|j|j�q\Wt|j||
j�|j|
||�}|r�d
d�|D�ng}
|
r�|
jd|
�|
j
�}
|
|
_|s|
j|
S)
zSend a given PreparedRequest.r?rArBrCz#You can only send PreparedRequests.rDTrRr0cSsg|]}|�qSr$r$)r%rZr$r$r(r)cs	z Session.send.<locals>.<listcomp>r)rar?rArBrCr*r�
ValueError�setrRrS�addr1�poprh�get_adapterrZutcnowrY�elapsedrrHrrVr_rKr^�insertrI)r8r_rxZchecked_urlsr9rDr?rh�adapter�start�rrZ�genrHr$r$r(rY,sD	
			zSession.sendc	Cs�|jr�t|�pi}x*|j�D]\}}|j||�q(W|dks`|dkr�tjjd�p�tjjd�}t||j�}t||j	�}t||j
�}t||j�}d|d|d|d|iS)	z6Check the environment and merge it with some settings.TNZREQUESTS_CA_BUNDLEZCURL_CA_BUNDLErArCr?rB)r`rr,ra�os�environr1r/rCr?rArB)	r8rRrCr?rArBZenv_proxiesr&r'r$r$r(rwrs	z"Session.merge_environment_settingscCsMx6|jj�D]%\}}|j�j|�r|SqWtd|��dS)z=Returns the appropriate connection adapter for the given URL.z*No connection adapters were found for '%s'N)rjr,�lowerrQr)r8rR�prefixr�r$r$r(r��szSession.get_adaptercCs(x!|jj�D]}|j�qWdS)z+Closes all adapters and as such the sessionN)rj�valuesrN)r8r'r$r$r(rN�sz
Session.closecsW||j�<�fdd�|jD�}x'|D]}|jj|�|j|<q0WdS)zkRegisters a connection adapter to a prefix.

        Adapters are sorted in descending order by key length.cs.g|]$}t|�t��kr|�qSr$)�len)r%r&)r�r$r(r)�s	z!Session.mount.<locals>.<listcomp>N)rjr�)r8r�r�Zkeys_to_mover.r$)r�r(rk�s

z
Session.mountcs9t�fdd��jD��}t�j�|d<|S)Nc3s'|]}|t�|d�fVqdS)N)�getattr)r%�attr)r8r$r(�	<genexpr>�sz'Session.__getstate__.<locals>.<genexpr>rS)�dict�	__attrs__rS)r8�stater$)r8r(�__getstate__�s"zSession.__getstate__cCs||jdi�}x*|j�D]\}}t|||�qWtt�|_x'|j�D]\}}||j|<q[WdS)NrS)r�r,�setattrrrlrS)r8r�rSr��valueZredirectZtor$r$r(�__setstate__�szSession.__setstate__)rcrdre�__doc__r�rmrnrprvr_r1ryrzr{r|r}r~rYrwr�rNrkr�r�r$r$r$r(rfsH	7)B




	F
rfcCst�S)z2Returns a :class:`Session` for context-management.)rfr$r$r$r(�session�sr�)6r�r��collectionsrrrgr�compatrrrr	rVr
rrr
ZmodelsrrrrhrrZutilsrrr�
exceptionsrrrrZpackages.urllib3._collectionsrZ
structuresrrjrrrrr r!Zstatus_codesr"r#rlr/r2�objectr3rfr�r$r$r$r(�<module>
s."""( ���

Zerion Mini Shell 1.0