/ lib / urllib3 / connection.pyc
connection.pyc
  1  o

  2  ��YcfN�	@sddlmZddlZddlZddlZddlZddlZddlZddlmZ	ddlm
  3  Zddlm
Z
ddlmZddlmZdd	lmZz	ddlZejZWneefy`dZGd
  4  d�de�ZYnwzeZWneyvGdd
�d
e�ZYnwzeZWney�Gdd�de�ZYnwddlmZddl m!Z!ddl"m#Z#m$Z$m%Z%m&Z&ddl'm(Z(m)Z)m*Z*ddl+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1ddl2m3Z3m4Z4e�5e6�Z7ddd�Z8e�9ddd�Z:e�;d�Z<Gdd�dee=�ZGdd�de�Z>dd �Z?d!d"�Z@Gd#d$�d$e=�ZAe�seAZ>e>ZBdS)%�)�absolute_importN)�error)�timeout�)�six)�HTTPConnection)�
HTTPException)�create_proxy_ssl_contextc@�eZdZdS)�BaseSSLErrorN��__name__�
  5  __module__�__qualname__�rr��C:\Users\Jacks.GUTTSPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\urllib3\connection.pyr�rc@r
  6  )�ConnectionErrorNrrrrrr!rrc@r
  7  )�BrokenPipeErrorNrrrrrr*rr)�HTTPHeaderDict��__version__)�ConnectTimeoutError�NewConnectionError�SubjectAltNameWarning�SystemTimeWarning)�SKIP_HEADER�SKIPPABLE_HEADERS�
  8  connection)�assert_fingerprint�create_urllib3_context�is_ipaddress�resolve_cert_reqs�resolve_ssl_version�ssl_wrap_socket)�CertificateError�match_hostname�Pi�)�http�httpsi�z[^-!#$%&'*+.^_`|~0-9a-zA-Z]cs�eZdZdZedZejejdfgZ	dZ
  9  dZdd�Ze
dd	��Zejd
 10  d	��Zdd�Zd
d�Zdd�Zdd�Zdd�Zdd�Zd�fdd�	Zddd�Z�ZS)ra5
 11      Based on :class:`http.client.HTTPConnection` but provides an extra constructor
 12      backwards-compatibility layer between older and newer Pythons.
 13  
 14      Additional keyword parameters are used to configure attributes of the connection.
 15      Accepted parameters include:
 16  
 17      - ``strict``: See the documentation on :class:`urllib3.connectionpool.HTTPConnectionPool`
 18      - ``source_address``: Set the source address for the current connection.
 19      - ``socket_options``: Set specific options on the underlying socket. If not specified, then
 20        defaults are loaded from ``HTTPConnection.default_socket_options`` which includes disabling
 21        Nagle's algorithm (sets TCP_NODELAY to 1) unless the connection is behind a proxy.
 22  
 23        For example, if you wish to enable TCP Keep Alive in addition to the defaults,
 24        you might pass:
 25  
 26        .. code-block:: python
 27  
 28           HTTPConnection.default_socket_options + [
 29               (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
 30           ]
 31  
 32        Or you may want to disable the defaults by passing an empty list (e.g., ``[]``).
 33      r(rFNcOsftjs	|�dd�|�d�|_|�d|j�|_|�dd�|_|�dd�|_t	j
 34  |g|�Ri|��dS)N�strict�source_address�socket_options�proxy�proxy_config)r�PY2�pop�getr+�default_socket_optionsr,r-r.�_HTTPConnection�__init__)�self�args�kwrrrr4sszHTTPConnection.__init__cCs|j�d�S)a�
 35          Getter method to remove any trailing dots that indicate the hostname is an FQDN.
 36  
 37          In general, SSL certificates don't include the trailing dot indicating a
 38          fully-qualified domain name, and thus, they don't validate properly when
 39          checked against a domain name that includes the dot. In addition, some
 40          servers may not expect to receive the trailing dot when provided.
 41  
 42          However, the hostname with trailing dot is critical to DNS resolution; doing a
 43          lookup with the trailing dot will properly only resolve the appropriate FQDN,
 44          whereas a lookup without a trailing dot will search the system's search domain
 45          list. Thus, it's important to keep the original host around for use only in
 46          those cases where it's appropriate (i.e., when doing DNS lookup to establish the
 47          actual TCP connection across which we're going to send HTTP requests).
 48          �.)�	_dns_host�rstrip�r5rrr�host�szHTTPConnection.hostcCs
 49  ||_dS)z�
 50          Setter for the `host` property.
 51  
 52          We assume that only urllib3 uses the _dns_host attribute; httplib itself
 53          only uses `host`, and it seems reasonable that other libraries follow suit.
 54          N)r9)r5�valuerrrr<�s
 55  c
 56  Cs�i}|jr
 57  |j|d<|jr|j|d<ztj|j|jf|jfi|��}W|Sty6t|d|j	|jf��t
 58  yH}zt|d|��d}~ww)zoEstablish a socket connection and set nodelay settings on it.
 59  
 60          :return: New socket connection.
 61          r+r,z0Connection to %s timed out. (connect timeout=%s)z(Failed to establish a new connection: %sN)r+r,r�create_connectionr9�portr�
SocketTimeoutrr<�SocketErrorr)r5�extra_kw�conn�errr�	_new_conn�s2
 62  
 63  ���
 64  �����zHTTPConnection._new_conncCst|dd�S)N�_tunnel_host)�getattrr;rrr�_is_using_tunnel�szHTTPConnection._is_using_tunnelcCs$||_|��r|��d|_dSdS)Nr)�sockrH�_tunnel�	auto_open�r5rCrrr�
_prepare_conn�s
 65  
 66  �zHTTPConnection._prepare_conncCs|��}|�|�dS�N)rErMrLrrr�connect�szHTTPConnection.connectcOs>t�|�}|rtd||��f��tj|||g|�Ri|��S)� zAMethod cannot contain non-token characters %r (found at least %r))�_CONTAINS_CONTROL_CHAR_RE�search�
 67  ValueError�groupr3�
 68  putrequest)r5�method�urlr6�kwargs�matchrrrrU�s
 69  
 70  ��zHTTPConnection.putrequestcGs`tdd�|D��stj||g|�R�dSt�|���tvr.tdd�t	t
 71  jtt���f��dS)rPcss"�|]}t|t�o|tkVqdSrN)�
 72  isinstance�strr)�.0�vrrr�	<genexpr>�s� z+HTTPConnection.putheader.<locals>.<genexpr>z+urllib3.util.SKIP_HEADER only supports '%s'z', 'N)
�anyr3�	putheaderr�
 73  ensure_str�lowerrrS�join�mapr[�title�sorted)r5�header�valuesrrrr`�s���zHTTPConnection.putheadercsN|duri}n|��}ddd�|D�vrt�|d<tt|�j||||d�dS)N�
 74  user-agentcss�|]
 75  }t�|���VqdSrN�rrarb�r\�krrrr^�s�z)HTTPConnection.request.<locals>.<genexpr>�
 76  User-Agent)�body�headers)�copy�_get_default_user_agent�superr�request)r5rVrWrnro��	__class__rrrs�s
 77  zHTTPConnection.requestcCs$|pi}tdd�|D��}d|v}d|v}|j||||d�d|vr)|�dt��|��D]
 78  \}}	|�||	�q-d|vrB|�d	d
 79  �|��|dur�tjtf}
 80  t	||
 81  �rX|f}|D]0}|s_qZt	|t�si|�
 82  d�}tt|��d
d�}t
|�
 83  ��}
|
d7}
|
|7}
|
d7}
|�|
�qZ|�d�dS)z�
 84          Alternative to the common request method, which sends the
 85          body with chunked encoding and not as one block
 86          cSsg|]	}t�|����qSrrjrkrrr�
 87  <listcomp>�sz2HTTPConnection.request_chunked.<locals>.<listcomp>zaccept-encodingr<)�skip_accept_encoding�	skip_hostrirmztransfer-encodingzTransfer-Encoding�chunkedN�utf8�s
 88  s0
 89  
 90  )�setrUr`rq�items�
 91  endheadersr�string_types�bytesrZ�encode�hex�len�	bytearray�send)r5rVrWrnroZheader_keysrwrxrgr=Zstringish_types�chunk�len_str�to_sendrrr�request_chunked�s<�
 92  
 93  
 94  zHTTPConnection.request_chunked)NN)r
rr�__doc__�port_by_scheme�default_port�socket�IPPROTO_TCP�TCP_NODELAYr2�is_verified�proxy_is_verifiedr4�propertyr<�setterrErHrMrOrUr`rsr��
__classcell__rrrtrrLs&
 95  
 96  	

 97  
 98  rc@s|eZdZdZedZdZdZdZdZ	dZ
 99  dZdZddddde
jddfdd�Z									d
dd�Zd	d
100  �Zdd�ZdS)�HTTPSConnectionz�
101      Many of the parameters to this constructor are passed to the underlying SSL
102      socket by means of :py:func:`urllib3.util.ssl_wrap_socket`.
103      r)NFc
104  KsDtj|||f||d�|
105  ��||_||_||_||_|	|_d|_dS)N)r*rr))rr4�key_file�	cert_file�key_password�ssl_context�server_hostname�	_protocol)r5r<r?r�r�r�r*rr�r�r7rrrr4)s
106  zHTTPSConnection.__init__c
107  
108  Csv|dur|jdur|jj}ntd�}||_||_||_||_||_||_|o+t	j
109  �|�|_|o4t	j
110  �|�|_
|	|_dS)zX
111          This method should only be called once, before the connection is used.
112          N)r��verify_moder"r�r��	cert_reqsr��assert_hostnamer�os�path�
113  expanduser�ca_certs�ca_cert_dir�ca_cert_data)
114  r5r�r�r�r�r�r�rr�r�rrr�set_certCs
115  
116  
117  zHTTPSConnection.set_certc	Cs�|��|_}|j}d}|��r(|jr|�||�|_}d}|��d|_|j}|}|j	dur2|j	}t
118  j��t
k}|rDt�d�t
�t�d}|jdurZd}tt|j�t|j�d�|_|j}t|j�|_|jsw|jsw|jsw|rwt|d�rw|��t||j|j |j!|j|j|j|||d�
119  |_|r�|jdur�t|jd�r�|j�"�d	vr�t�d
120  |j|j�"�ft#�|j$r�t$|jj%dd�|j$�n-|jt&j'kr�t(|dd�s�|j)dur�|j�%�}|�*d
d�s�t�d�|�t+�t,||j)p�|�|jt&j-kp�|j$du|_.dS)NFTrzWSystem time is way off (before {0}). This will probably lead to SSL verification errors)�ssl_versionr��load_default_certs)
121  rI�keyfile�certfiler�r�r�r�r�r��
122  tls_in_tls�version>zTLSv1.1�TLSv1z�Negotiating TLSv1/TLSv1.1 by default is deprecated and will be disabled in urllib3 v2.0.0. Connecting to '%s' with '%s' can be enabled by explicitly opting-in with 'ssl_version')�binary_form�check_hostname�subjectAltNamer��Certificate for {0} has no `subjectAltName`, falling back to check for a `commonName` for now. This feature is being removed by major browsers and deprecated by RFC 2818. (See https://github.com/urllib3/urllib3/issues/497 for details.))/rErIr<rH�tls_in_tls_required�_connect_tls_proxyrJrKrFr��datetime�date�today�RECENT_DATE�warnings�warn�formatrr�r r#r�r"r�r�r�r�r��hasattrr�r$r�r�r�r��DeprecationWarningr�getpeercert�ssl�	CERT_NONErGr�r1r�_match_hostname�
CERT_REQUIREDr�)	r5rC�hostnamer�r�Zis_time_offZdefault_ssl_context�context�certrrrrOds�
123  �
124  
125  ��������
126  
127  ����
128  �
129  
130  �	�zHTTPSConnection.connectcCs�|j}|j}|rt|||d�St|j|j|j|j|j�}t||j|j|j||d�}|j	t
131  jkrMt|dd�sM|�
�}|�dd�sHt�d�|�t�t||�|j	t
132  jk|_|S)zY
133          Establish a TLS connection to the proxy using the provided SSL context.
134          )rIr�r�)rIr�r�r�r�r�r�Fr�rr�)r.r�r$r	r�r�r�r�r�r�r�r�rGr�r1r�r�r�rr�r�r�)r5r�rCr.r�r�r�rrrr��sH��
135  �	��
136  	z"HTTPSConnection._connect_tls_proxy)	NNNNNNNNN)r
rrr�r�r�r�r�r�r�r�rr�r��_GLOBAL_DEFAULT_TIMEOUTr4r�rOr�rrrrr�s>
137  �
138  �!vr�c
139  CsV|�d�}t|�r|}zt||�WdSty*}zt�d||�||_�d}~ww)Nzu[]z@Certificate did not match expected hostname: %s. Certificate: %s)�stripr!r&r%�log�warningZ
140  _peer_cert)r�Zasserted_hostnameZstripped_hostnamerDrrrr�s
141  ���r�cCsdtS)Nzpython-urllib3/%srrrrrrq)srqc@seZdZdZdS)�DummyConnectionz-Used to detect a failed ConnectionCls import.N)r
rrr�rrrrr�-sr�)C�
142  __future__rr��loggingr��rer�r�rrArr@�packagesr�packages.six.moves.http_clientrr3r�
143  util.proxyr	r��SSLErrorr�ImportError�AttributeError�
BaseExceptionr�	NameError�	Exceptionr�_collectionsr�_versionr�
144  exceptionsrrrr�utilrrr�	util.ssl_rr r!r"r#r$�util.ssl_match_hostnamer%r&�	getLoggerr
r�r�r�r��compilerQ�objectr�r�rqr��VerifiedHTTPSConnectionrrrr�<module>sd
145  ��� 
146  
147  
148  N{