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