관리-도구
편집 파일: adapters.cpython-39.pyc
a �������g7q����������������������@���sN��d�Z�ddlZddlZddlZddlmZmZ�ddlm Z �ddl mZ�ddl mZ �ddlmZ�ddlmZ�dd lmZ�dd lmZ�ddlmZ�ddlmZ�dd lmZ�ddlmZ�ddlmZ�ddlmZ�ddlmZ�ddlmZ�ddlm Z �ddl!m"Z"�ddl#m$Z$m%Z%�ddl&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-�ddl.m/Z/�ddl0m1Z1�ddl2m3Z3m4Z4m5Z5mZmZm6Z6m7Z7m8Z8m9Z9�ddl:m;Z;�zddl<m=Z=�W�n�e>�y����dd��Z=Y�n0�dZ?d Z@dZAdZBz ddlCZCe��ZDeD�Ee(e'���W�n�e>�y����dZDY�n0�d!d"ejFeGejHf�eId#�d$d%�ZJd&d!d"d'd(d)�d*d+�ZKG�d,d-��d-eL�ZMG�d.d/��d/eM�ZNdS�)0z� requests.adapters ~~~~~~~~~~~~~~~~~ This module contains the transport adapters that Requests uses to define and maintain connections. �����N)�PoolManager�proxy_from_url)�HTTPResponse)� parse_url)�Timeout)�Retry)�create_urllib3_context)�ClosedPoolError)�ConnectTimeoutError)� HTTPError)� MaxRetryError)�NewConnectionError)� ProxyError)� ProtocolError)�ReadTimeoutError)�SSLError)� ResponseError)�LocationValueError����)�Response)�urlparse� basestring)�DEFAULT_CA_BUNDLE_PATH�extract_zipped_paths�get_encoding_from_headers�prepend_scheme_if_needed�get_auth_from_url� urldefragauth�select_proxy)�CaseInsensitiveDict)�extract_cookies_to_jar) �ConnectionError�ConnectTimeout�ReadTimeoutr���r���� RetryError� InvalidSchema�InvalidProxyURL� InvalidURL)�_basic_auth_str)�SOCKSProxyManagerc������������������O���s���t�d��d�S�)Nz'Missing dependencies for SOCKS support.)r%���)�args�kwargs��r,����5/usr/lib/python3.9/site-packages/requests/adapters.pyr)���0���s����r)���F� ���zbool | str | Nonez#typing.Tuple[str, str] | str | None)�verify�client_cert�poolmanager_kwargs�returnc�����������������C���s,���|��d�}|�du�o&td�uo&|�o&|d�u�}|S�)N�ssl_contextT)�get�_preloaded_ssl_context)r/���r0���r1���Zhas_poolmanager_ssl_contextZshould_use_default_ssl_contextr,���r,���r-����_should_use_default_contextE���s���� ���r6���ZPreparedRequestr���z<(typing.Dict[str, typing.Any], typing.Dict[str, typing.Any]))�requestr/���r0����poolmanagerr2���c�����������������C���s����i�}i�}t�|�j�}|j���}|j}t|di��} d} d�}|du�rDd} n6t||| �rZt|d<�n |du�rltt �}nt |t�rz|}|d�ur�tj �|�s�||d<�n||d<�| |d <�|d�ur�t |t�r�t|�d kr�|d�|d<�|d �|d<�n||d<�||j|d�}||fS�)NZconnection_pool_kw� CERT_REQUIREDF� CERT_NONEr3���T�ca_certs�ca_cert_dir� cert_reqs����r���� cert_filer����key_file)�scheme�host�port)r����urlrA����lowerrC����getattrr6���r5���r���r���� isinstance�str�os�path�isdir�tuple�len�hostname)r7���r/���r0���r8����host_params�pool_kwargsZparsed_request_urlrA���rC���r1���r=����cert_locr,���r,���r-����_urllib3_request_contextV���s>���� �rR���c�����������������������s2���e�Zd�ZdZ��fdd�Zddd�Zd d ��Z���ZS�)�BaseAdapterzThe Base Transport Adapterc��������������������s���t�t|������d�S��N)�superrS����__init__��self�� __class__r,���r-���rV�������s����zBaseAdapter.__init__FNTc�����������������C���s���t��dS�)aC��Sends PreparedRequest object. Returns Response object. :param request: The :class:`PreparedRequest <PreparedRequest>` being sent. :param stream: (optional) Whether to stream the request content. :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 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 :param cert: (optional) Any user-provided SSL certificate to be trusted. :param proxies: (optional) The proxies dictionary to apply to the request. N��NotImplementedError)rX���r7����stream�timeoutr/����cert�proxiesr,���r,���r-����send����s����zBaseAdapter.sendc�����������������C���s���t��dS�)z!Cleans up adapter specific items.Nr[���rW���r,���r,���r-����close����s����zBaseAdapter.close)FNTNN)�__name__� __module__�__qualname__�__doc__rV���ra���rb���� __classcell__r,���r,���rY���r-���rS�������s������ rS���c�����������������������s����e�Zd�ZdZg�d�Zeeeef��fdd� Zdd��Z dd��Z efd d �Zdd��Zd d��Z dd��Zd$dd�Zd%dd�Zd&dd�Zdd��Zdd��Zdd��Zdd��Zd'd"d#�Z���ZS�)(�HTTPAdaptera���The built-in HTTP Adapter for urllib3. Provides a general-case interface for Requests sessions to contact HTTP and HTTPS urls by implementing the Transport Adapter interface. This class will usually be created by the :class:`Session <Session>` class under the covers. :param pool_connections: The number of urllib3 connection pools to cache. :param pool_maxsize: The maximum number of connections to save in the pool. :param max_retries: The maximum number of retries each connection should attempt. Note, this applies only to failed DNS lookups, socket connections and connection timeouts, never to requests where data has made it to the server. By default, Requests does not retry failed connections. If you need granular control over the conditions under which we retry a request, import urllib3's ``Retry`` class and pass that instead. :param pool_block: Whether the connection pool should block for connections. Usage:: >>> import requests >>> s = requests.Session() >>> a = requests.adapters.HTTPAdapter(max_retries=3) >>> s.mount('http://', a) )�max_retries�config�_pool_connections� _pool_maxsize�_pool_blockc��������������������sd���|t�krtddd�|�_nt�|�|�_i�|�_i�|�_tt|������||�_ ||�_ ||�_|�j|||d��d�S�)Nr���F)�read��block) �DEFAULT_RETRIESr���ri���Zfrom_intrj���� proxy_managerrU���rh���rV���rk���rl���rm����init_poolmanager)rX���Zpool_connectionsZpool_maxsizeri���Z pool_blockrY���r,���r-���rV�������s����zHTTPAdapter.__init__c��������������������s�����fdd���j�D��S�)Nc��������������������s���i�|�]}|t���|d���qS�rT���)rF���)�.0�attrrW���r,���r-���� <dictcomp>���������z,HTTPAdapter.__getstate__.<locals>.<dictcomp>)� __attrs__rW���r,���rW���r-����__getstate__����s����zHTTPAdapter.__getstate__c�����������������C���sD���i�|�_�i�|�_|���D�]\}}t|�||��q|�j|�j|�j|�jd��d�S�)Nro���)rr���rj����items�setattrrs���rk���rl���rm���)rX����stateru����valuer,���r,���r-����__setstate__����s�����zHTTPAdapter.__setstate__c�����������������K���s0���||�_�||�_||�_tf�|||dd�|��|�_dS�)a��Initializes a urllib3 PoolManager. This method should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`. :param connections: The number of urllib3 connection pools to cache. :param maxsize: The maximum number of connections to save in the pool. :param block: Block when no free connections are available. :param pool_kwargs: Extra keyword arguments used to initialize the Pool Manager. T)� num_pools�maxsizerp����strictN)rk���rl���rm���r���r8���)rX���Zconnectionsr����rp���rP���r,���r,���r-���rs�������s���� ��zHTTPAdapter.init_poolmanagerc�����������������K���s����||�j�v�r|�j�|�}n||����d�r^t|�\}}t|f|||�j|�j|�jd�|���}|�j�|<�n4|��|�}t |f||�j|�j|�jd�|���}|�j�|<�|S�)a���Return urllib3 ProxyManager for the given proxy. This method should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`. :param proxy: The proxy to return a urllib3 ProxyManager for. :param proxy_kwargs: Extra keyword arguments used to configure the Proxy Manager. :returns: ProxyManager :rtype: urllib3.ProxyManager �socks)�username�passwordr���r����rp���)� proxy_headersr���r����rp���) rr���rE���� startswithr���r)���rk���rl���rm���r����r���)rX����proxyZproxy_kwargsZmanagerr����r����r����r,���r,���r-����proxy_manager_for����s6���� ��� ���zHTTPAdapter.proxy_manager_forc�����������������C���s����|�����d�rZ|rZd|_|durl|}tj�|�s>td|�����tj�|�sR||_ql||_ nd|_d|_d|_ |r�t |t�s�|d�|_|d�|_ n||_d|_ |jr�tj�|j�s�td �|j���|j r�tj�|j �s�td �|j ���dS�)aA��Verify a SSL certificate. This method should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`. :param conn: The urllib3 connection object associated with the cert. :param url: The requested URL. :param verify: 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 :param cert: The SSL certificate to verify. �httpsr9���TzCCould not find a suitable TLS CA certificate bundle, invalid path: r:���Nr���r���z9Could not find the TLS certificate file, invalid path: {}z1Could not find the TLS key file, invalid path: {})rE���r����r=���rI���rJ����exists�OSErrorrK���r;���r<���rG���r���r?���r@����IOError�format)rX����connrD���r/���r_���rQ���r,���r,���r-����cert_verify��s<������ ��zHTTPAdapter.cert_verifyc�����������������C���s����t���}t|dd�|_tt|di���|_t|j�|_||_|jj|_t |j t�r^|j �d�|_ n|j |_ t |j||��||_|�|_|S�)a���Builds a :class:`Response <requests.Response>` object from a urllib3 response. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>` :param req: The :class:`PreparedRequest <PreparedRequest>` used to generate the response. :param resp: The urllib3 response object. :rtype: requests.Response �statusN�headers�utf-8)r���rF���Zstatus_coder���r����r����encoding�raw�reasonrG���rD����bytes�decoder ����cookiesr7���� connection)rX���Zreq�respZresponser,���r,���r-����build_responseL��s���� zHTTPAdapter.build_responseNc�����������������C���s���t�||||�j�S�)a� ��Build the PoolKey attributes used by urllib3 to return a connection. This looks at the PreparedRequest, the user-specified verify value, and the value of the cert parameter to determine what PoolKey values to use to select a connection from a given urllib3 Connection Pool. The SSL related pool key arguments are not consistently set. As of this writing, use the following to determine what keys may be in that dictionary: * If ``verify`` is ``True``, ``"ssl_context"`` will be set and will be the default Requests SSL Context * If ``verify`` is ``False``, ``"ssl_context"`` will not be set but ``"cert_reqs"`` will be set * If ``verify`` is a string, (i.e., it is a user-specified trust bundle) ``"ca_certs"`` will be set if the string is not a directory recognized by :py:func:`os.path.isdir`, otherwise ``"ca_certs_dir"`` will be set. * If ``"cert"`` is specified, ``"cert_file"`` will always be set. If ``"cert"`` is a tuple with a second item, ``"key_file"`` will also be present To override these settings, one may subclass this class, call this method and use the above logic to change parameters as desired. For example, if one wishes to use a custom :py:class:`ssl.SSLContext` one must both set ``"ssl_context"`` and based on what else they require, alter the other keys to ensure the desired behaviour. :param request: The PreparedReqest being sent over the connection. :type request: :class:`~requests.models.PreparedRequest` :param verify: 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. :param cert: (optional) Any user-provided SSL certificate for client authentication (a.k.a., mTLS). This may be a string (i.e., just the path to a file which holds both certificate and key) or a tuple of length 2 with the certificate file path and key file path. :returns: A tuple of two dictionaries. The first is the "host parameters" portion of the Pool Key including scheme, hostname, and port. The second is a dictionary of SSLContext related parameters. )rR���r8���)rX���r7���r/���r_���r,���r,���r-����$build_connection_pool_key_attributesq��s����+z0HTTPAdapter.build_connection_pool_key_attributesc�������������� ���C���s����t�|j|�}z|��|||�\}}W�n0�tyR�}�zt||d��W�Y�d}~n d}~0�0�|r�t|d�}t|�} | jsxtd��|�� |�} | j f�i�|�d|i��}n|�jj f�i�|�d|i��}|S�)ap��Returns a urllib3 connection for the given request and TLS settings. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`. :param request: The :class:`PreparedRequest <PreparedRequest>` object to be sent over the connection. :param verify: 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. :param proxies: (optional) The proxies dictionary to apply to the request. :param cert: (optional) Any user-provided SSL certificate to be used for client authentication (a.k.a., mTLS). :rtype: urllib3.ConnectionPool �r7���N�http�FPlease check proxy URL. It is malformed and could be missing the host.rP���)r���rD���r����� ValueErrorr'���r���r���rB���r&���r����Zconnection_from_hostr8���)rX���r7���r/���r`���r_���r����rO���rP����e� proxy_urlrr���r����r,���r,���r-����get_connection_with_tls_context���s8�����" � �� ��z+HTTPAdapter.get_connection_with_tls_contextc�����������������C���sd���t�||�}|rDt|d�}t|�}|js.td��|��|�}|�|�}nt|�}|���}|�j �|�}|S�)a��DEPRECATED: Users should move to `get_connection_with_tls_context` for all subclasses of HTTPAdapter using Requests>=2.32.2. Returns a urllib3 connection for the given URL. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`. :param url: The URL to connect to. :param proxies: (optional) A Requests-style dictionary of proxies used on this request. :rtype: urllib3.ConnectionPool r����r����) r���r���r���rB���r&���r����Zconnection_from_urlr����geturlr8���)rX���rD���r`���r����r����rr���r�����parsedr,���r,���r-����get_connection���s���� zHTTPAdapter.get_connectionc�����������������C���s&���|�j�����|�j���D�]}|����qdS�)z�Disposes of any internal state. Currently, this closes the PoolManager and any active ProxyManager, which closes any pooled connections. N)r8����clearrr����values)rX���r����r,���r,���r-���rb������s���� zHTTPAdapter.closec����������� ������C���s`���t�|j|�}t|j�j}|o"|dk}d}|rDt|�j���}|�d�}|j}|r\|s\t|j�}|S�)a?��Obtain the url to use when making the final request. If the message is being sent through a HTTP proxy, the full URL has to be used. Otherwise, we should only use the path portion of the URL. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`. :param request: The :class:`PreparedRequest <PreparedRequest>` being sent. :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs. :rtype: str r����Fr����)r���rD���r���rA���rE���r����Zpath_urlr���) rX���r7���r`���r����rA���Zis_proxied_http_requestZusing_socks_proxyZproxy_schemerD���r,���r,���r-����request_url���s���� zHTTPAdapter.request_urlc�����������������K���s���dS�)a"��Add any headers needed by the connection. As of v2.0 this does nothing by default, but is left for overriding by users that subclass the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`. :param request: The :class:`PreparedRequest <PreparedRequest>` to add headers to. :param kwargs: The keyword arguments from the call to send(). Nr,���)rX���r7���r+���r,���r,���r-����add_headers��s����zHTTPAdapter.add_headersc�����������������C���s&���i�}t�|�\}}|r"t||�|d<�|S�)a��Returns a dictionary of the headers to add to any request sent through a proxy. This works with urllib3 magic to ensure that they are correctly sent to the proxy, rather than in a tunnelled request if CONNECT is being used. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`. :param proxy: The url of the proxy being used for this request. :rtype: dict zProxy-Authorization)r���r(���)rX���r����r����r����r����r,���r,���r-���r������s���� �zHTTPAdapter.proxy_headersFTc�����������������C���s���z|�j�||||d�}W�n0�tyF�}�zt||d��W�Y�d}~n d}~0�0�|��||j||��|��||�} |�j||||||d��|jdu�p�d|jv��} t |t �r�z|\}}t||d�}W�n6�ty��}�zd� |�} t| ��W�Y�d}~n d}~0�0�nt |t�r�nt||d�}�zD| �s:|j|j| |j|jdddd|�j|d � }�nt|d ��rL|j}|jtd�}z�|j|j| dd ��|j���D�]\}}|�||���qv|����|jD�]D}|�tt|��dd���d���|�d��|�|��|�d���q�|�d��z|jdd�}W�n�t�y���|���}Y�n0�tj |||ddd�}W�n���|�!�����Y�n0�W��n��t"t#j$f�y��} �zt%| |d��W�Y�d} ~ �njd} ~ 0��t&�y,�}�z�t |j't(��r�t |j't)��s�t*||d��t |j't+��r�t,||d��t |j't-��r�t.||d��t |j't/��rt0||d��t%||d��W�Y�d}~n�d}~0��t1�y\�}�zt%||d��W�Y�d}~n�d}~0��t-�y��}�zt.|��W�Y�d}~nhd}~0��t/t2f�y��}�zBt |t/��r�t0||d��nt |t3��r�t4||d��n��W�Y�d}~n d}~0�0�|��5||�S�)a��Sends PreparedRequest object. Returns Response object. :param request: The :class:`PreparedRequest <PreparedRequest>` being sent. :param stream: (optional) Whether to stream the request content. :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 or urllib3 Timeout object :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 :param cert: (optional) Any user-provided SSL certificate to be trusted. :param proxies: (optional) The proxies dictionary to apply to the request. :rtype: requests.Response )r`���r_���r����N)r]���r^���r/���r_���r`���zContent-Length)�connectrn���zrInvalid timeout {}. Pass a (connect, read) timeout tuple, or a single float to set both timeouts to the same valueF) �methodrD����bodyr����ZredirectZassert_same_host�preload_content�decode_contentZretriesr^���� proxy_pool)r^���T)Zskip_accept_encodingr>���r����s��� s���0 )� buffering)Zpoolr����r����r����)6r����r���r'���r����rD���r����r����r����r����rG���rL����TimeoutSaucer����r����Zurlopenr����ri����hasattrr����Z _get_conn�DEFAULT_POOL_TIMEOUTZ putrequestrz���Z putheaderZ endheadersra����hexrM����encodeZgetresponse� TypeErrorr���Zfrom_httplibrb���r����socket�errorr!���r���r����r ���r ���r"���r���r$����_ProxyErrorr���� _SSLErrorr���r ���� _HTTPErrorr���r#���r����)rX���r7���r]���r^���r/���r_���r`���r����r����rD���Zchunkedr����rn����errr����Zlow_conn�headerr}����i�rr,���r,���r-���ra���5��s������ " � � � � " zHTTPAdapter.send)N)NN)N)FNTNN)rc���rd���re���rf���rx����DEFAULT_POOLSIZErq����DEFAULT_POOLBLOCKrV���ry���r~���rs���r����r����r����r����r����r����rb���r����r����r����ra���rg���r,���r,���rY���r-���rh�������s(����%3% - / rh���)Orf���Zos.pathrI���r�����typingZurllib3.poolmanagerr���r���Zurllib3.responser���Zurllib3.utilr���r���r����Zurllib3.util.retryr���Zurllib3.util.ssl_r���Zurllib3.exceptionsr ���r ���r���r����r���r ���r���r����r���r���r���r����r���r���Zmodelsr����compatr���r���Zutilsr���r���r���r���r���r���r���Z structuresr���r����r ���� exceptionsr!���r"���r#���r$���r%���r&���r'���Zauthr(���Zurllib3.contrib.socksr)����ImportErrorr����r����rq���r����Zsslr5���Zload_verify_locations�DictrH����Any�boolr6���rR����objectrS���rh���r,���r,���r,���r-����<module>���sp���$,� ��/