U ��.eB;� @s�ddlmZddlZddlZddlZddlZddlmZmZ ddl Z ddl m Z ddl mZddl mZzddlZejZWn,eefk r�dZGdd �d e�ZYnXzeZWn$ek r�Gd d �d e�ZYnXdd lmZmZmZmZdd lm Z m!Z!ddl"m#Z#m$Z$m%Z%m&Z&m'Z'ddl(m)Z)ddl*m+Z+e�,e-�Z.ddd�Z/e�0ddd�Z1Gdd�de2�Z3Gdd�dee2�ZGdd�de�Z4Gdd�de4�Z5dd�Z6e�r�e4Z7e5Z4ne3Z4dS)�)�absolute_importN)�error�timeout�)�six)�HTTPConnection)� HTTPExceptionc@s eZdZdS)� BaseSSLErrorN��__name__� __module__� __qualname__�rr�B/usr/lib/python3.8/site-packages/pip/_vendor/urllib3/connection.pyr sr c@s eZdZdS)�ConnectionErrorNr rrrrrsr)�NewConnectionError�ConnectTimeoutError�SubjectAltNameWarning�SystemTimeWarning)�match_hostname�CertificateError)�resolve_cert_reqs�resolve_ssl_version�assert_fingerprint�create_urllib3_context�ssl_wrap_socket)� connection)�HTTPHeaderDict�Pi�)�http�httpsi�c@seZdZdZdS)�DummyConnectionz-Used to detect a failed ConnectionCls import.N)r r r �__doc__rrrrr!>sr!c@speZdZdZedZejejdfgZ dZ dd�Z e dd��Z e jd d��Z d d �Zd d �Zdd�Zddd�ZdS)ra$ Based on httplib.HTTPConnection but provides an extra constructor backwards-compatibility layer between older and newer Pythons. Additional keyword parameters are used to configure attributes of the connection. Accepted parameters include: - ``strict``: See the documentation on :class:`urllib3.connectionpool.HTTPConnectionPool` - ``source_address``: Set the source address for the current connection. - ``socket_options``: Set specific options on the underlying socket. If not specified, then defaults are loaded from ``HTTPConnection.default_socket_options`` which includes disabling Nagle's algorithm (sets TCP_NODELAY to 1) unless the connection is behind a proxy. For example, if you wish to enable TCP Keep Alive in addition to the defaults, you might pass:: HTTPConnection.default_socket_options + [ (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1), ] Or you may want to disable the defaults by passing an empty list (e.g., ``[]``). rrFcOsDtjs|�dd�|�d�|_|�d|j�|_tj|f|�|�dS)N�strict�source_address�socket_options) rZPY2�pop�getr$�default_socket_optionsr%�_HTTPConnection�__init__)�self�args�kwrrrr*es   zHTTPConnection.__init__cCs |j�d�S)a� Getter method to remove any trailing dots that indicate the hostname is an FQDN. In general, SSL certificates don't include the trailing dot indicating a fully-qualified domain name, and thus, they don't validate properly when checked against a domain name that includes the dot. In addition, some servers may not expect to receive the trailing dot when provided. However, the hostname with trailing dot is critical to DNS resolution; doing a lookup with the trailing dot will properly only resolve the appropriate FQDN, whereas a lookup without a trailing dot will search the system's search domain list. Thus, it's important to keep the original host around for use only in those cases where it's appropriate (i.e., when doing DNS lookup to establish the actual TCP connection across which we're going to send HTTP requests). �.)� _dns_host�rstrip)r+rrr�hostrszHTTPConnection.hostcCs ||_dS)z� Setter for the `host` property. We assume that only urllib3 uses the _dns_host attribute; httplib itself only uses `host`, and it seems reasonable that other libraries follow suit. N)r/)r+�valuerrrr1�sc Cs�i}|jr|j|d<|jr$|j|d<ztj|j|jf|jf|�}WnXtk rlt|d|j |jf��Yn0t k r�}zt |d|��W5d}~XYnX|S)zp Establish a socket connection and set nodelay settings on it. :return: New socket connection. r$r%z0Connection to %s timed out. (connect timeout=%s)z(Failed to establish a new connection: %sN) r$r%rZcreate_connectionr/�portr� SocketTimeoutrr1� SocketErrorr)r+Zextra_kw�conn�errr� _new_conn�s2   �� ���zHTTPConnection._new_conncCs$||_t|dd�r |��d|_dS)N� _tunnel_hostr)�sock�getattr�_tunnel� auto_open�r+r6rrr� _prepare_conn�s zHTTPConnection._prepare_conncCs|��}|�|�dS)N)r8r?r>rrr�connect�szHTTPConnection.connectNc Cst|dk r|ni�}d|k}d|k}|j||||d�|��D]\}}|�||�q>d|krh|�dd�|��|dk r�tjtf} t|| �r�|f}|D]`} | s�q�t| t�s�| � d�} t t | ��d d�} |� | � d ��|� d �|� | �|� d �q�|� d �dS) z� Alternative to the common request method, which sends the body with chunked encoding and not as one block Nzaccept-encodingr1)�skip_accept_encoding� skip_hostztransfer-encodingzTransfer-EncodingZchunked�utf8�zutf-8s s0 ) rZ putrequest�itemsZ putheaderZ endheadersrZ string_types�bytes� isinstance�encode�hex�len�send) r+�methodZurlZbodyZheadersrArB�headerr2Zstringish_types�chunkZlen_strrrr�request_chunked�s:�        zHTTPConnection.request_chunked)NN)r r r r"�port_by_scheme� default_port�socketZ IPPROTO_TCPZ TCP_NODELAYr(� is_verifiedr*�propertyr1�setterr8r?r@rOrrrrrDs    rc@s<eZdZedZdZdddddejddfdd�Zdd�Z dS)�HTTPSConnectionr Nc KsDtj|||f||d�| ��||_||_||_||_| |_d|_dS)N)r#rr )rr*�key_file� cert_file� key_password� ssl_context�server_hostnameZ _protocol) r+r1r3rWrXrYr#rrZr[r-rrrr*�szHTTPSConnection.__init__cCs�|��}|�|�d}|jdkr>d}tt|j�t|j�d�|_|j}|jsf|j sf|rft |d�rf|� �t ||j |j|j|j|jd�|_dS)NFT�� ssl_version� cert_reqs�load_default_certs)r:�keyfile�certfilerYrZr[)r8r?rZrrr]rr^�ca_certs� ca_cert_dir�hasattrr_rrWrXrYr[r:)r+r6�default_ssl_context�contextrrrr@�s6  ������zHTTPSConnection.connect) r r r rPrQr]rRZ_GLOBAL_DEFAULT_TIMEOUTr*r@rrrrrV�s� rVc@s6eZdZdZdZdZdZdZdZddd�Z dd�Z dS)�VerifiedHTTPSConnectionz[ Based on httplib.HTTPSConnection but wraps the socket with SSL certification. Nc Csp|dkr$|jdk r|jj}ntd�}||_||_||_||_||_||_|oVt j � |�|_ |oht j � |�|_ dS)zX This method should only be called once, before the connection is used. N)rZ� verify_moderrWrXr^rY�assert_hostnamer�os�path� expanduserrbrc) r+rWrXr^rYrbrirrcrrr�set_cert-s  z VerifiedHTTPSConnection.set_certc Cs�|��}|j}t|dd�r4||_|��d|_|j}|}|jdk rH|j}tj � �t k}|rlt � d�t �t�d}|jdkr�d}tt|j�t|j�d�|_|j}t|j�|_|js�|js�|r�t|d�r�|��t||j|j|j|j|j||d�|_|j�rt|jj dd �|j�nd|jt!j"k�rtt|d d��st|j#dk �rt|j� �}|�$d d ��sbt � d �|�t%�t&||j#�pp|�|jt!j'k�p�|jdk |_(dS)Nr9rzWSystem time is way off (before {0}). This will probably lead to SSL verification errorsFTr\r_)r:r`rarYrbrcr[rZ)Z binary_formZcheck_hostnameZsubjectAltNamerz�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/shazow/urllib3/issues/497 for details.)))r8r1r;r:r<r=r9r[�datetime�dateZtoday� RECENT_DATE�warnings�warn�formatrrZrrr]rr^rhrbrcrdr_rrWrXrYrZ getpeercert�sslZ CERT_NONErir'r�_match_hostnameZ CERT_REQUIREDrS)r+r6Zhostnamer[Z is_time_offrerf�certrrrr@Ls�  ���  � �����  � � �� �� �zVerifiedHTTPSConnection.connect)NNNNNNNN) r r r r"r^rbrcr]rrmr@rrrrrg!s � rgc CsLzt||�Wn8tk rF}zt�d||�||_�W5d}~XYnXdS)Nz@Certificate did not match expected hostname: %s. Certificate: %s)rr�logZwarningZ _peer_cert)rvZasserted_hostnamer7rrrru�s�ru)8Z __future__rrnZloggingrjrRrr5rr4rqZpackagesrZpackages.six.moves.http_clientrr)rrtZSSLErrorr � ImportError�AttributeError� BaseExceptionr� NameError� Exception� exceptionsrrrrZpackages.ssl_match_hostnamerrZ util.ssl_rrrrr�utilr� _collectionsrZ getLoggerr rwrProrp�objectr!rVrgruZUnverifiedHTTPSConnectionrrrr�sL         B