U `BI @sddlmZddlZddlZddlZddlZddlZddlZddlmZ ddlm Z ddl m Z ddlmZddlmZdd lmZzddlZejZWn,eefk rdZGd d d eZYnXzeZWn$ek rGd d d eZYnXzeZWn&ek r GdddeZYnXddlmZddl m!Z!ddl"m#Z#m$Z$m%Z%m&Z&ddl'm(Z(m)Z)ddl*m+Z+m,Z,m-Z-ddl.m/Z/m0Z0m1Z1m2Z2m3Z3e4e5Z6dddZ7e8dddZ9e:dZ;Gdddee<ZGdddeZ=d d!Z>d"d#Z?Gd$d%d%e<Z@es e@Z=e=ZAdS)&)absolute_importN)error)timeout)six)HTTPConnection) HTTPException)create_proxy_ssl_contextc@s eZdZdS) BaseSSLErrorN__name__ __module__ __qualname__rrC/opt/alt/python38/lib/python3.8/site-packages/urllib3/connection.pyr sr c@s eZdZdS)ConnectionErrorNr rrrrr!src@s eZdZdS)BrokenPipeErrorNr rrrrr*sr)HTTPHeaderDict __version__)ConnectTimeoutErrorNewConnectionErrorSubjectAltNameWarningSystemTimeWarning)CertificateErrormatch_hostname) SKIP_HEADERSKIPPABLE_HEADERS connection)assert_fingerprintcreate_urllib3_contextresolve_cert_reqsresolve_ssl_versionssl_wrap_socketPi)httphttpsiz[^-!#$%&'*+.^_`|~0-9a-zA-Z]cseZdZdZedZejejdfgZ dZ ddZ e ddZ e jd dZ d d Zd d ZddZddZddZddZdfdd ZdddZZS)ra5 Based on :class:`http.client.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: .. code-block:: python 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., ``[]``). r%rFcOs`tjs|dd|d|_|d|j|_|dd|_|dd|_t j |f||dS)Nstrictsource_addresssocket_optionsproxy proxy_config) rZPY2popgetr)default_socket_optionsr*r+r,_HTTPConnection__init__)selfargskwrrrr1ns  zHTTPConnection.__init__cCs |jdS)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_hostrstripr2rrrhostszHTTPConnection.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)r6)r2valuerrrr9sc Csi}|jr|j|d<|jr$|j|d<ztj|j|jf|jf|}WnXtk rlt|d|j |jfYn0t k r}zt |d|W5d}~XYnX|S)zoEstablish 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_connectionr6portr SocketTimeoutrr9 SocketErrorr)r2Zextra_kwconnerrr _new_conns2    zHTTPConnection._new_conncCs t|ddS)N _tunnel_host)getattrr8rrr_is_using_tunnelszHTTPConnection._is_using_tunnelcCs ||_|r|d|_dS)Nr)sockrC_tunnel auto_openr2r>rrr _prepare_connszHTTPConnection._prepare_conncCs|}||dSN)r@rHrGrrrconnectszHTTPConnection.connectcOs8t|}|r"td||ftj|||f||S) zAMethod cannot contain non-token characters %r (found at least %r))_CONTAINS_CONTROL_CHAR_REsearch ValueErrorgroupr0 putrequest)r2methodurlr3kwargsmatchrrrrPs  zHTTPConnection.putrequestcGs\tdd|Ds&tj||f|n2t|tkrXtddt t j t tfdS)rKcss |]}t|to|tkVqdSrI) isinstancestrr).0vrrr sz+HTTPConnection.putheader..z+urllib3.util.SKIP_HEADER only supports '%s'z', 'N) anyr0 putheaderr ensure_strlowerrrNjoinmaprVtitlesorted)r2headervaluesrrrr[szHTTPConnection.putheaderNcsN|dkri}n|}ddd|Dkr2t|d<tt|j||||ddS)N user-agentcss|]}t|VqdSrIrr\r]rWkrrrrYsz)HTTPConnection.request.. User-Agent)bodyheaders)copy_get_default_user_agentsuperrrequest)r2rQrRrirj __class__rrrns  zHTTPConnection.requestcCs&|pi}tdd|D}d|k}d|k}|j||||dd|krR|dt|D]\}} ||| qZd|kr|d d ||d k rtjtf} t || r|f}|D]`} | sqt | ts| d } t t | d d } t | } | d7} | | 7} | d7} || q|dd S)z Alternative to the common request method, which sends the body with chunked encoding and not as one block cSsg|]}t|qSrrerfrrr sz2HTTPConnection.request_chunked..zaccept-encodingr9)skip_accept_encoding skip_hostrdrhztransfer-encodingzTransfer-EncodingZchunkedNutf8s s0 )setrPr[rlitemsZ endheadersrZ string_typesbytesrUencodehexlen bytearraysend)r2rQrRrirjZ header_keysrrrsrbr:Zstringish_typeschunkZlen_strZto_sendrrrrequest_chunkedsB        zHTTPConnection.request_chunked)NN)NN)r r r__doc__port_by_scheme default_portsocketZ IPPROTO_TCPZ TCP_NODELAYr/ is_verifiedr1propertyr9setterr@rCrHrJrPr[rnr __classcell__rrrorrKs"     rc @sjeZdZdZedZdZdZdZdZ dZ dZ dZ ddddde jddfddZd ddZd d Zd d ZdS)HTTPSConnectionz Many of the parameters to this constructor are passed to the underlying SSL socket by means of :py:func:`urllib3.util.ssl_wrap_socket`. r&NFc KsDtj|||f||d| ||_||_||_||_| |_d|_dS)N)r(rr&)rr1key_file cert_file key_password ssl_contextserver_hostnameZ _protocol) r2r9r;rrrr(rrrr4rrrr1$szHTTPSConnection.__init__c Csv|dkr$|jdk r|jj}ntd}||_||_||_||_||_||_|oVt j ||_ |oht j ||_ | |_dS)zX This method should only be called once, before the connection is used. N)r verify_moder!rr cert_reqsrassert_hostnamerospath expanduserca_certs ca_cert_dir ca_cert_data) r2rrrrrrrrrrrrset_cert>s  zHTTPSConnection.set_certc Cs|}|j}d}|rJ|jr0|||}d}||_|d|_|j}|}|j dk r^|j }t j t k}|rtdt td}|jdkrd}tt|jt|jd|_|j}t|j|_|js|js|js|rt|dr|t||j|j |j!|j|j|j|||d |_|r^|jdkr^t|jdr^|j"d kr^td |j|j"ft#|j$r~t$|jj%dd |j$nd|jt&j'krt(|d ds|j)dk r|j%}|*d dstd|t+t,||j)p||jt&j-kp|j$dk |_.dS)NFTrzWSystem time is way off (before {0}). This will probably lead to SSL verification errors) ssl_versionrload_default_certs) rDZkeyfileZcertfilerrrrrr tls_in_tlsversion>TLSv1TLSv1.1zNegotiating 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')Z binary_formcheck_hostnameZsubjectAltNamerzCertificate 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.))/r@r9rCtls_in_tls_required_connect_tls_proxyrDrErFrArdatetimedateZtoday RECENT_DATEwarningswarnformatrrr r"rr!rrrrrhasattrrr#rrrrDeprecationWarningrZ getpeercertsslZ CERT_NONErBrr.r_match_hostnameZ CERT_REQUIREDr) r2r>hostnamerrZ is_time_offZdefault_ssl_contextcontextcertrrrrJ_s            zHTTPSConnection.connectcCsX|j}|j}|rt|||dSt|j|j|j|j|j}d|_ t||j|j|j||dS)zY Establish a TLS connection to the proxy using the provided SSL context. )rDrrT)rDrrrrr) r,rr#r rrrrrr)r2rr>r,rrrrrs0 z"HTTPSConnection._connect_tls_proxy) NNNNNNNNN)r r rrrrrrrrrrrrZ_GLOBAL_DEFAULT_TIMEOUTr1rrJrrrrrrs<  !xrc CsLzt||Wn8tk rF}ztd||||_W5d}~XYnXdS)Nz@Certificate did not match expected hostname: %s. Certificate: %s)rrlogZwarningZ _peer_cert)rZasserted_hostnamer?rrrrsrcCsdtS)Nzpython-urllib3/%srrrrrrl srlc@seZdZdZdS)DummyConnectionz-Used to detect a failed ConnectionCls import.N)r r rrrrrrrsr)BZ __future__rrZloggingrrerrrr=rr<ZpackagesrZpackages.six.moves.http_clientrr0rZ util.proxyr rZSSLErrorr ImportErrorAttributeError BaseExceptionr NameError Exceptionr _collectionsrZ_versionr exceptionsrrrrZpackages.ssl_match_hostnamerrutilrrrZ util.ssl_rr r!r"r#Z getLoggerr rrrrcompilerLobjectrrrlrZVerifiedHTTPSConnectionrrrrs\             Jk