/ lib / requests / adapters.pyc
adapters.pyc
  1  o

  2  ��Yc'S�@s�dZddlZddlZddlmZmZddlmZddlm	Z
  3  ddlmZmZm
Z
mZddlmZddlmZmZdd	lmZdd
  4  lmZmZddlmZddlmZdd
lmZddlmZddl m!Z!ddl"m#Z#m$Z$ddl%m&Z&ddl'm(Z(m)Z)m	Z	m*Z*m+Z+m,Z,mZm-Z-m.Z.mZddl/m0Z0ddl1m2Z2ddl3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:zddl;m<Z<Wn
e=y�dd�Z<YnwdZ>dZ?dZ@dZAGdd�d�ZBGdd�deB�ZCdS) z�
  5  requests.adapters
  6  ~~~~~~~~~~~~~~~~~
  7  
  8  This module contains the transport adapters that Requests uses to define
  9  and maintain connections.
 10  �N)�ClosedPoolError�ConnectTimeoutError)�	HTTPError)�
InvalidHeader)�LocationValueError�
MaxRetryError�NewConnectionError�
ProtocolError)�
 11  ProxyError)�ReadTimeoutError�
ResponseError)�SSLError)�PoolManager�proxy_from_url)�HTTPResponse)�Timeout)�	parse_url)�Retry�)�_basic_auth_str)�
 12  basestring�urlparse)�extract_cookies_to_jar)
 13  �ConnectionError�ConnectTimeoutr�InvalidProxyURL�
InvalidSchema�
 14  InvalidURLr
 15  �ReadTimeout�
 16  RetryErrorr
)�Response)�CaseInsensitiveDict)�DEFAULT_CA_BUNDLE_PATH�extract_zipped_paths�get_auth_from_url�get_encoding_from_headers�prepend_scheme_if_needed�select_proxy�
urldefragauth)�SOCKSProxyManagercOstd��)Nz'Missing dependencies for SOCKS support.)r)�args�kwargs�r,��C:\Users\Jacks.GUTTSPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\requests\adapters.pyr)=sr)F�
 17  cs4eZdZdZ�fdd�Z	ddd�Zd	d
 18  �Z�ZS)�BaseAdapterzThe Base Transport Adaptercst���dS�N)�super�__init__��self��	__class__r,r-r2JszBaseAdapter.__init__FNTcC�t�)aCSends PreparedRequest object. Returns Response object.
 19  
 20          :param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
 21          :param stream: (optional) Whether to stream the request content.
 22          :param timeout: (optional) How long to wait for the server to send
 23              data before giving up, as a float, or a :ref:`(connect timeout,
 24              read timeout) <timeouts>` tuple.
 25          :type timeout: float or tuple
 26          :param verify: (optional) Either a boolean, in which case it controls whether we verify
 27              the server's TLS certificate, or a string, in which case it must be a path
 28              to a CA bundle to use
 29          :param cert: (optional) Any user-provided SSL certificate to be trusted.
 30          :param proxies: (optional) The proxies dictionary to apply to the request.
 31          ��NotImplementedError)r4�request�stream�timeout�verify�cert�proxiesr,r,r-�sendMszBaseAdapter.sendcCr7)z!Cleans up adapter specific items.r8r3r,r,r-�close`szBaseAdapter.close�FNTNN)�__name__�
 32  __module__�__qualname__�__doc__r2r@rA�
__classcell__r,r,r5r-r/Gs
 33  �r/cs�eZdZdZgd�Zeeeef�fdd�	Zdd�Z	dd�Z
 34  efd	d
 35  �Zdd�Zd
d�Z
dd�Zd dd�Zdd�Zdd�Zdd�Zdd�Z	d!dd�Z�ZS)"�HTTPAdaptera�The built-in HTTP Adapter for urllib3.
 36  
 37      Provides a general-case interface for Requests sessions to contact HTTP and
 38      HTTPS urls by implementing the Transport Adapter interface. This class will
 39      usually be created by the :class:`Session <Session>` class under the
 40      covers.
 41  
 42      :param pool_connections: The number of urllib3 connection pools to cache.
 43      :param pool_maxsize: The maximum number of connections to save in the pool.
 44      :param max_retries: The maximum number of retries each connection
 45          should attempt. Note, this applies only to failed DNS lookups, socket
 46          connections and connection timeouts, never to requests where data has
 47          made it to the server. By default, Requests does not retry failed
 48          connections. If you need granular control over the conditions under
 49          which we retry a request, import urllib3's ``Retry`` class and pass
 50          that instead.
 51      :param pool_block: Whether the connection pool should block for connections.
 52  
 53      Usage::
 54  
 55        >>> import requests
 56        >>> s = requests.Session()
 57        >>> a = requests.adapters.HTTPAdapter(max_retries=3)
 58        >>> s.mount('http://', a)
 59      )�max_retries�config�_pool_connections�
_pool_maxsize�_pool_blockcs`|tkrtddd�|_nt�|�|_i|_i|_t���||_||_	||_
 60  |j|||d�dS)NrF)�read��block)�DEFAULT_RETRIESrrI�from_intrJ�
proxy_managerr1r2rKrLrM�init_poolmanager)r4Zpool_connectionsZpool_maxsizerIZ
 61  pool_blockr5r,r-r2�s
 62  zHTTPAdapter.__init__cs�fdd��jD�S)Ncsi|]	}|t�|d��qSr0)�getattr)�.0�attrr3r,r-�
 63  <dictcomp>�sz,HTTPAdapter.__getstate__.<locals>.<dictcomp>)�	__attrs__r3r,r3r-�__getstate__�szHTTPAdapter.__getstate__cCsDi|_i|_|��D]
 64  \}}t|||�q
 65  |j|j|j|jd�dS)NrO)rSrJ�items�setattrrTrKrLrM)r4�staterW�valuer,r,r-�__setstate__�s
 66  �zHTTPAdapter.__setstate__cKs0||_||_||_td|||dd�|��|_dS)aInitializes a urllib3 PoolManager.
 67  
 68          This method should not be called from user code, and is only
 69          exposed for use when subclassing the
 70          :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
 71  
 72          :param connections: The number of urllib3 connection pools to cache.
 73          :param maxsize: The maximum number of connections to save in the pool.
 74          :param block: Block when no free connections are available.
 75          :param pool_kwargs: Extra keyword arguments used to initialize the Pool Manager.
 76          T)�	num_pools�maxsizerP�strictNr,)rKrLrMr�poolmanager)r4�connectionsrarP�pool_kwargsr,r,r-rT�s��zHTTPAdapter.init_poolmanagercKs�||jvr|j|}|S|���d�r1t|�\}}t|f|||j|j|jd�|��}|j|<|S|�|�}t	|f||j|j|jd�|��}|j|<|S)a�Return urllib3 ProxyManager for the given proxy.
 77  
 78          This method should not be called from user code, and is only
 79          exposed for use when subclassing the
 80          :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
 81  
 82          :param proxy: The proxy to return a urllib3 ProxyManager for.
 83          :param proxy_kwargs: Extra keyword arguments used to configure the Proxy Manager.
 84          :returns: ProxyManager
 85          :rtype: urllib3.ProxyManager
 86          �socks)�username�passwordr`rarP)�
proxy_headersr`rarP)
 87  rS�lower�
 88  startswithr$r)rKrLrMrir)r4�proxyZproxy_kwargs�managerrgrhrir,r,r-�proxy_manager_for�s:
 89  
 90  ����
 91  ����	zHTTPAdapter.proxy_manager_forcCs|���d�r7|r7d}|dur|}|stt�}|rtj�|�s&td|����d|_tj�	|�s3||_
 92  n
||_n	d|_d|_
 93  d|_|r|t|t
�sR|d|_|d|_n||_d|_|jrjtj�|j�sjtd	|j����|jr~tj�|j�s�td
 94  |j����dSdSdS)aAVerify a SSL certificate. This method should not be called from user
 95          code, and is only exposed for use when subclassing the
 96          :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
 97  
 98          :param conn: The urllib3 connection object associated with the cert.
 99          :param url: The requested URL.
100          :param verify: Either a boolean, in which case it controls whether we verify
101              the server's TLS certificate, or a string, in which case it must be a path
102              to a CA bundle to use
103          :param cert: The SSL certificate to verify.
104          �httpsNTzCCould not find a suitable TLS CA certificate bundle, invalid path: �
CERT_REQUIRED�	CERT_NONErrz7Could not find the TLS certificate file, invalid path: z/Could not find the TLS key file, invalid path: )rjrkr#r"�os�path�exists�OSError�	cert_reqs�isdir�ca_certs�ca_cert_dir�
105  isinstancer�	cert_file�key_file)r4�conn�urlr=r>Zcert_locr,r,r-�cert_verify�sJ��
106  
107  ��
108  ��zHTTPAdapter.cert_verifycCs�t�}t|dd�|_tt|di��|_t|j�|_||_|jj|_t	|j
109  t�r/|j
110  �d�|_
111  n|j
112  |_
113  t
|j||�||_||_|S)a�Builds a :class:`Response <requests.Response>` object from a urllib3
114          response. This should not be called from user code, and is only exposed
115          for use when subclassing the
116          :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`
117  
118          :param req: The :class:`PreparedRequest <PreparedRequest>` used to generate the response.
119          :param resp: The urllib3 response object.
120          :rtype: requests.Response
121          �statusN�headers�utf-8)r rU�status_coder!r�r%�encoding�raw�reasonrzr~�bytes�decoder�cookiesr:�
122  connection)r4�req�resp�responser,r,r-�build_response(s
123  
124  zHTTPAdapter.build_responseNcCsft||�}|r#t|d�}t|�}|jstd��|�|�}|�|�}|St|�}|��}|j	�|�}|S)a�Returns a urllib3 connection for the given URL. This should not be
125          called from user code, and is only exposed for use when subclassing the
126          :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
127  
128          :param url: The URL to connect to.
129          :param proxies: (optional) A Requests-style dictionary of proxies used on this request.
130          :rtype: urllib3.ConnectionPool
131          �httpzFPlease check proxy URL. It is malformed and could be missing the host.)
132  r'r&r�hostrrn�connection_from_urlr�geturlrc)r4r~r?rl�	proxy_urlrSr}�parsedr,r,r-�get_connectionMs
133  	
134  �
135  
136  �zHTTPAdapter.get_connectioncCs&|j��|j��D]}|��q
137  dS)z�Disposes of any internal state.
138  
139          Currently, this closes the PoolManager and any active ProxyManager,
140          which closes any pooled connections.
141          N)rc�clearrS�values)r4rlr,r,r-rAjs
142  
143  �zHTTPAdapter.closec	Cs`t|j|�}t|j�j}|o|dk}d}|r"t|�j��}|�d�}|j}|r.|s.t|j�}|S)a?Obtain the url to use when making the final request.
144  
145          If the message is being sent through a HTTP proxy, the full URL has to
146          be used. Otherwise, we should only use the path portion of the URL.
147  
148          This should not be called from user code, and is only exposed for use
149          when subclassing the
150          :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
151  
152          :param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
153          :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs.
154          :rtype: str
155          roFrf)r'r~r�schemerjrk�path_urlr()	r4r:r?rlr�Zis_proxied_http_requestZusing_socks_proxyZproxy_schemer~r,r,r-�request_urlts
156  
157  zHTTPAdapter.request_urlcKsdS)a"Add any headers needed by the connection. As of v2.0 this does
158          nothing by default, but is left for overriding by users that subclass
159          the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
160  
161          This should not be called from user code, and is only exposed for use
162          when subclassing the
163          :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
164  
165          :param request: The :class:`PreparedRequest <PreparedRequest>` to add headers to.
166          :param kwargs: The keyword arguments from the call to send().
167          Nr,)r4r:r+r,r,r-�add_headers�szHTTPAdapter.add_headerscCs&i}t|�\}}|rt||�|d<|S)aReturns a dictionary of the headers to add to any request sent
168          through a proxy. This works with urllib3 magic to ensure that they are
169          correctly sent to the proxy, rather than in a tunnelled request if
170          CONNECT is being used.
171  
172          This should not be called from user code, and is only exposed for use
173          when subclassing the
174          :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
175  
176          :param proxy: The url of the proxy being used for this request.
177          :rtype: dict
178          zProxy-Authorization)r$r)r4rlr�rgrhr,r,r-ri�s
179  
zHTTPAdapter.proxy_headersFTcCsxz	|�|j|�}Wnty}zt||d��d}~ww|�||j||�|�||�}	|j||||||d�|jdup?d|jv}
180  t	|t
181  �rbz|\}}t||d�}Wntyatd|�d���wt	|t�rhnt||d�}z�|
182  s�|j
|j|	|j|jdddd|j|d	�
183  }
nxt|d
184  �r�|j}|jtd�}z]d|jv}|j|j|	d
|d�|j��D]
185  \}}|�||�q�|��|jD]!}|�tt|��dd��d��|�d�|�|�|�d�q�|�d�|��}tj|||ddd�}
Wnty�|� ��wWn�t!t"f�y}zt#||d��d}~wt$�y`}zAt	|j%t&��r/t	|j%t'��s/t(||d��t	|j%t)��r<t*||d��t	|j%t+��rIt,||d��t	|j%t-��rVt.||d��t#||d��d}~wt/�yr}zt#||d��d}~wt+�y�}zt,|��d}~wt-t0f�y�}z%t	|t-��r�t.||d��t	|t1��r�t2||d��t	|t3��r�t4||d���d}~ww|�5||
�S)aSends PreparedRequest object. Returns Response object.
186  
187          :param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
188          :param stream: (optional) Whether to stream the request content.
189          :param timeout: (optional) How long to wait for the server to send
190              data before giving up, as a float, or a :ref:`(connect timeout,
191              read timeout) <timeouts>` tuple.
192          :type timeout: float or tuple or urllib3 Timeout object
193          :param verify: (optional) Either a boolean, in which case it controls whether
194              we verify the server's TLS certificate, or a string, in which case it
195              must be a path to a CA bundle to use
196          :param cert: (optional) Any user-provided SSL certificate to be trusted.
197          :param proxies: (optional) The proxies dictionary to apply to the request.
198          :rtype: requests.Response
199          )r:N)r;r<r=r>r?zContent-Length)�connectrNzInvalid timeout za. Pass a (connect, read) timeout tuple, or a single float to set both timeouts to the same value.F)
200  �methodr~�bodyr��redirect�assert_same_host�preload_content�decode_content�retriesr<�
201  proxy_pool)r<�HostT)�skip_accept_encoding�	skip_host�r�s
202  s0
203  
204  )�poolr�r�r�)6r�r~rrrr�r�r�r�rz�tuple�TimeoutSauce�
205  ValueError�urlopenr�rI�hasattrr��	_get_conn�DEFAULT_POOL_TIMEOUT�
206  putrequestr[�	putheader�
207  endheadersr@�hex�len�encode�getresponser�from_httplib�	ExceptionrAr	rurrr�rrrrr�_ProxyErrorr
208  �	_SSLErrorr
r�
209  _HTTPErrorrr�_InvalidHeaderrr�)r4r:r;r<r=r>r?r}�er~�chunkedr�rNr�Zlow_connr��headerr^�i�r�errr,r,r-r@�s����	
210  
211  ��
212  �
213  
214  �
215   
216  
217  
218  
219  ���������zHTTPAdapter.sendr0rB)rCrDrErFrY�DEFAULT_POOLSIZErQ�DEFAULT_POOLBLOCKr2rZr_rTrnrr�r�rAr�r�rir@rGr,r,r5r-rHes,
220  �
221  �&9
222  %
223  �rH)DrF�os.pathrr�socket�urllib3.exceptionsrrrr�rr�rrrr	r
224  r�rrr
r�Zurllib3.poolmanagerrrZurllib3.responser�urllib3.utilrr�rZurllib3.util.retryr�authr�compatrrr�r�
225  exceptionsrrrrrrr�modelsr �
226  structuresr!�utilsr"r#r$r%r&r'r(�urllib3.contrib.socksr)�ImportErrorr�r�rQr�r/rHr,r,r,r-�<module>sB0$
227  �