관리-도구
편집 파일: sessions.cpython-39.pyc
a ����[��f�u����������������������@���s���d�Z�ddlZddlZddlZddlmZ�ddlmZ�ddlm Z �ddl mZmZm Z mZmZ�ddlmZmZmZmZ�dd lmZmZmZ�dd lmZmZ�ddlmZ�ddlmZm Z m!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/m0Z0�ddl1m2Z2�ddlm3Z3�ej4dk�rTz ej5Z6W�n�e7�yP���ej8Z6Y�n0�nejZ6efdd�Z9efdd�Z:G�dd��de;�Z<G�dd��de<�Z=dd��Z>dS�)z� requests.sessions ~~~~~~~~~~~~~~~~~ This module provides a Session object to manage and persist settings across requests (cookies, auth, proxies). �����N)� timedelta)�OrderedDict����)�_basic_auth_str)� cookielib�is_py3�urljoin�urlparse�Mapping)�cookiejar_from_dict�extract_cookies_to_jar�RequestsCookieJar� merge_cookies)�Request�PreparedRequest�DEFAULT_REDIRECT_LIMIT)� default_hooks� dispatch_hook)�to_native_string)�to_key_val_list�default_headers� DEFAULT_PORTS)�TooManyRedirects� InvalidSchema�ChunkedEncodingError�ContentDecodingError)�CaseInsensitiveDict)�HTTPAdapter)�requote_uri�get_environ_proxies�get_netrc_auth�should_bypass_proxies�get_auth_from_url�rewind_body)�codes)�REDIRECT_STATI�win32c�����������������C���sp���|du�r|�S�|�du�r|S�t�|t�r,t�|�t�s0|�S�|t|��}|�t|����dd��|���D��}|D�] }||=�q`|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` Nc�����������������S���s���g�|�]\}}|d�u�r|�qS��N��)�.0�k�vr(���r(����A/usr/lib/python3.9/site-packages/pip/_vendor/requests/sessions.py� <listcomp>J��������z!merge_setting.<locals>.<listcomp>)� isinstancer ���r����update�items)Zrequest_settingZsession_setting� dict_classZmerged_settingZ none_keys�keyr(���r(���r,���� merge_setting2���s������r4���c�����������������C���s@���|du�s|��d�g�kr|�S�|�du�s0|���d�g�kr4|S�t|�||�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)�getr4���)Z request_hooksZ session_hooksr2���r(���r(���r,����merge_hooksQ���s ����r7���c�������������������@���s>���e�Zd�Zdd��Zdd��Zddd �Zd d��Zdd ��Zdd��ZdS�)�SessionRedirectMixinc�����������������C���s,���|j�r(|jd�}tr|�d�}t|d�S�dS�)z7Receives a Response. Returns a redirect URI or ``None``�location�latin1�utf8N)Zis_redirect�headersr����encoder���)�self�respr9���r(���r(���r,����get_redirect_targetb���s���� z(SessionRedirectMixin.get_redirect_targetc�����������������C���s����t�|�}t�|�}|j|jkr dS�|jdkrL|jdv�rL|jdkrL|jdv�rLdS�|j|jk}|j|jk}t�|jd�df}|s�|j|v�r�|j|v�r�dS�|p�|S�)zFDecide whether Authorization header should be removed when redirectingT�http)�P���N�https)i���NFN)r ����hostname�scheme�portr���r6���)r>���Zold_urlZnew_urlZ old_parsedZ new_parsedZchanged_portZchanged_schemeZdefault_portr(���r(���r,����should_strip_authw���s$�������z&SessionRedirectMixin.should_strip_authFNTc �������������� ���k���sF��g�} |���|�}t|j�j}|�rB|���} | �|��| dd��|_z |j�W�n&�tt t fyp���|jjdd��Y�n0�t |j�|�jkr�td�|�j�|d��|����|�d�r�t|j�}d�t|j�|g�}t|�}|jd kr�|r�|j|d �}n|jr�|j}|���}|j�st|jt|��}nt|�}t|�| _|��| |��|jtjtjfv�rnd}|D�]}| j �!|d���qRd| _"| j }|�!dd��t#| j$||j��t%| j$|�j&��| �'| j$��|��(| |�}|��)| |��| j*du�o�d |v��p�d|v�}|�r�t+| ��| }|�r�|V��q|�j,|f|||||dd�| ��}t#|�j&| |j��|���|�}|V��qdS�)zBReceives a Response. Returns a generator of Responses or Requests.r���NF)Zdecode_contentzExceeded {} redirects.)r5���z//�:��)�fragment)�Content-LengthzContent-Type�Transfer-EncodingZCookierK���rL���)�stream�timeout�verify�cert�proxies�allow_redirects)-r@���r ����urlrJ����copy�append�history�contentr���r����RuntimeError�raw�read�len� max_redirectsr����format�close� startswith�joinr���rE����_replace�geturl�netlocr���r����rebuild_method�status_coder$���Ztemporary_redirectZpermanent_redirectr<����pop�bodyr���Z_cookiesr����cookiesZprepare_cookies�rebuild_proxies�rebuild_authZ_body_positionr#����send)r>���r?����reqrM���rN���rO���rP���rQ����yield_requestsZadapter_kwargsZhistrS���Zprevious_fragment�prepared_requestZparsed_rurl�parsedZpurged_headers�headerr<���Z rewindabler(���r(���r,����resolve_redirects����s~���� ���� z&SessionRedirectMixin.resolve_redirectsc�����������������C���sR���|j�}|j}d|v�r*|��|jj|�r*|d=�|�jr8t|�nd}|durN|�|��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)r<���rS���rG����request� trust_envr ���Zprepare_auth)r>���rn���r5���r<���rS���Znew_authr(���r(���r,���rj�������s����z!SessionRedirectMixin.rebuild_authc����������� ������C���s����|dur|ni�}|j�}|j}t|�j}|���}|�d�}t||d�}|�jr||s|t||d�} | �|| �d��} | r||� || ��d|v�r�|d=�zt ||��\}}W�n�ty����d\}}Y�n0�|r�|r�t||�|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. :rtype: dict N�no_proxy�rt����allzProxy-Authorization)NN) r<���rS���r ���rE���rT���r6���r!���rs���r���� setdefaultr"����KeyErrorr���) r>���rn���rQ���r<���rS���rE���Znew_proxiesrt���Zbypass_proxyZenviron_proxies�proxy�username�passwordr(���r(���r,���ri�����s*���� z$SessionRedirectMixin.rebuild_proxiesc�����������������C���sX���|j�}|jtjkr|dkrd}|jtjkr6|dkr6d}|jtjkrN|dkrNd}||_�dS�)z�When being redirected we may want to change the method of the request based on certain specs or browser behavior. �HEAD�GET�POSTN)�methodre���r$���Z see_other�foundZmoved)r>���rn���r5���r���r(���r(���r,���rd���:��s����z#SessionRedirectMixin.rebuild_method)FNTNNF) �__name__� __module__�__qualname__r@���rG���rq���rj���ri���rd���r(���r(���r(���r,���r8���`���s������ n)r8���c�������������������@���s����e�Zd�ZdZg�d�Zdd��Zdd��Zdd��Zd d ��Zd+d d�Z dd��Z dd��Zdd��Zd,dd�Z d-dd�Zd.dd�Zdd��Zdd��Zdd ��Zd!d"��Zd#d$��Zd%d&��Zd'd(��Zd)d*��ZdS�)/�Sessiona���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<���rh����authrQ����hooks�paramsrO���rP����adaptersrM���rs���r\���c�����������������C���sr���t���|�_d�|�_i�|�_t��|�_i�|�_d|�_d|�_d�|�_ t |�_d|�_t i��|�_t��|�_|��dt����|��dt����d�S�)NFTzhttps://zhttp://)r���r<���r����rQ���r���r����r����rM���rO���rP���r���r\���rs���r���rh���r���r�����mountr����r>���r(���r(���r,����__init__j��s���� zSession.__init__c�����������������C���s���|�S�r'���r(���r����r(���r(���r,���� __enter__���s����zSession.__enter__c�����������������G���s���|������d�S�r'���)r^���)r>����argsr(���r(���r,����__exit__���s����zSession.__exit__c�������������� ���C���s����|j�pi�}t|tj�st|�}ttt��|�j��|�}|j}|�jrR|sR|�jsRt |j �}t��}|j|j ���|j |j|j|jt|j|�jtd�t|j|�j�t||�j�|t|j|�j�d� �|S�)a���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 )r2���) r���rS����files�data�jsonr<���r����r����rh���r����)rh���r/���r���Z CookieJarr���r���r ���r����rs���r ���rS���r���Zpreparer����upperr����r����r����r4���r<���r���r����r7���r����)r>���rr���rh���Zmerged_cookiesr�����pr(���r(���r,����prepare_request���s.���� � �zSession.prepare_requestNTc�����������������C���sx���t�|���||||pi�||pi�|||d� }|��|�}|p8i�}|��|j|| ||�}| | d�}|�|��|�j|fi�|��}|S�)ax ��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``. When set to ``False``, requests will accept any TLS certificate presented by the server, and will ignore hostname mismatches and/or expired certificates, which will make your application vulnerable to man-in-the-middle (MitM) attacks. Setting verify to ``False`` may be useful during local development or testing. :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair. :rtype: requests.Response ) r���rS���r<���r����r����r����r����r����rh���r����)rN���rR���)r���r����r�����merge_environment_settingsrS���r0���rk���)r>���r���rS���r����r����r<���rh���r����r����rN���rR���rQ���r����rM���rO���rP���r����rl���ZprepZsettingsZsend_kwargsr?���r(���r(���r,���rr������s.����.� �� zSession.requestc�����������������K���s ���|��dd��|�jd|fi�|��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. :rtype: requests.Response rR���Tr}����rw���rr����r>���rS����kwargsr(���r(���r,���r6���"��s����zSession.getc�����������������K���s ���|��dd��|�jd|fi�|��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. :rtype: requests.Response rR���TZOPTIONSr����r����r(���r(���r,����options-��s����zSession.optionsc�����������������K���s ���|��dd��|�jd|fi�|��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. :rtype: requests.Response rR���Fr|���r����r����r(���r(���r,����head8��s����zSession.headc�����������������K���s���|�j�d|f||d�|��S�)a���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�����rr���)r>���rS���r����r����r����r(���r(���r,����postC��s����zSession.postc�����������������K���s���|�j�d|fd|i|��S�)au��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 ZPUTr����r�����r>���rS���r����r����r(���r(���r,����putP��s���� zSession.putc�����������������K���s���|�j�d|fd|i|��S�)aw��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 ZPATCHr����r����r����r(���r(���r,����patch\��s���� z Session.patchc�����������������K���s���|�j�d|fi�|��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. :rtype: requests.Response ZDELETEr����r����r(���r(���r,����deleteh��s����zSession.deletec����������� ������K���s���|��d|�j��|��d|�j��|��d|�j��|��d|��||�j���t|t�rRtd��|� dd�}|� d�}|j}|�j|j d�}t��}|j|fi�|��}t��|�} t| d �|_td ||fi�|��}|jr�|jD�]} t|�j| j| j��q�t|�j||j��|�r|�j||fi�|��}dd��|D��}ng�}|�r@|�d |��|� ��}||_|�s~z"t|�j||fddi|���|_W�n�t�y|���Y�n0�|�s�|j�|S�)zISend a given PreparedRequest. :rtype: requests.Response rM���rO���rP���rQ���z#You can only send PreparedRequests.rR���T)rS���)Zsecondsr5���c�����������������S���s���g�|�]}|�qS�r(���r(���)r)���r?���r(���r(���r,���r-������r.���z Session.send.<locals>.<listcomp>r���rm���)rw���rM���rO���rP���ri���rQ���r/���r���� ValueErrorrf���r6���r�����get_adapterrS����preferred_clockrk���r����elapsedr���rV���r���rh���rr���rY���rq����insert�nextZ_next� StopIterationrW���) r>���rr���r����rR���rM���r�����adapter�start�rr����r?����genrV���r(���r(���r,���rk���r��sF���� "zSession.sendc����������� ������C���s����|�j�rn|dur|�d�nd}t||d�}|���D�]\}} |�|| ��q0|du�sV|du�rntj�d�pltj�d�}t||�j�}t||�j �}t||�j �}t||�j�}||||d�S�)z^ Check the environment and merge it with some settings. :rtype: dict Nrt���ru���TZREQUESTS_CA_BUNDLEZCURL_CA_BUNDLE)rO���rQ���rM���rP���)rs���r6���r���r1���rw����os�environr4���rQ���rM���rO���rP���) r>���rS���rQ���rM���rO���rP���rt���Zenv_proxiesr*���r+���r(���r(���r,���r�������s ���� ��z"Session.merge_environment_settingsc�����������������C���s@���|�j����D�]"\}}|����|����r |��S�q td�|���dS�)z~ Returns the appropriate connection adapter for the given URL. :rtype: requests.adapters.BaseAdapter z*No connection adapters were found for {!r}N)r����r1����lowerr_���r���r]���)r>���rS����prefixr����r(���r(���r,���r�������s���� zSession.get_adapterc�����������������C���s���|�j����D�]}|����q dS�)z+Closes all adapters and as such the sessionN)r�����valuesr^���)r>���r+���r(���r(���r,���r^������s����z Session.closec��������������������s>���||�j���<���fdd�|�j�D��}|D�]}|�j��|�|�j�|<�q"dS�)zwRegisters a connection adapter to a prefix. Adapters are sorted in descending order by prefix length. c��������������������s ���g�|�]}t�|�t����k�r|�qS�r(���)r[���)r)���r*����r����r(���r,���r-������r.���z!Session.mount.<locals>.<listcomp>N)r����rf���)r>���r����r����Zkeys_to_mover3���r(���r����r,���r�������s���� z Session.mountc��������������������s�����fdd���j�D��}|S�)Nc��������������������s���i�|�]}|t���|d���qS�r'���)�getattr)r)����attrr����r(���r,���� <dictcomp>���r.���z(Session.__getstate__.<locals>.<dictcomp>)� __attrs__)r>����stater(���r����r,����__getstate__���s����zSession.__getstate__c�����������������C���s"���|����D�]\}}t|�||��qd�S�r'���)r1����setattr)r>���r����r�����valuer(���r(���r,����__setstate__���s����zSession.__setstate__)NNNNNNNTNNNNNN)NN)N)N)r����r����r�����__doc__r����r����r����r����r����rr���r6���r����r����r����r����r����r����rk���r����r����r^���r����r����r����r(���r(���r(���r,���r����Q��s0���>)���� L Kr����c�������������������C���s���t���S�)aZ�� 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����r(���r(���r(���r,����session��s����r����)?r����r�����sys�timeZdatetimer����collectionsr���r����r����compatr���r���r���r ���r ���rh���r���r���r ���r���Zmodelsr���r���r���r����r���r���Z_internal_utilsr���Zutilsr���r���r���� exceptionsr���r���r���r���Z structuresr���r����r���r���r���r ���r!���r"���r#���Zstatus_codesr$���r%����platform�perf_counterr�����AttributeErrorZclockr4���r7����objectr8���r����r����r(���r(���r(���r,����<module>���sB��� �r���3