o |nhu @sddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddlm ZddlmZddlmZddlmZe jr[ddlmZdd lmZdd lmZdd lmZdd lmZdd lm Z ddl!m"Z"m#Z#m$Z$ddl%m&Z&ddl'm(Z(z ddl)Z)e)j*Z+Wne,e-fydZ)Gddde.Z+Ynwddl/m0Z0ddl/m1Z1ddl/m2Z2ddl3m4Z4ddl5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;ddlZ>m?Z?m@Z@ddlAmBZBddlmCZDddlmEZEmFZFmGZGmHZHmIZIddlJmKZKmLZLddlMmNZNeOZOePZPeQeRZSddd ZTeUd!ddZVeWd"ZXGd#d$d$eZ Gd%d&d&e ZYGd'd(d(e jZZ[d)d*d]dDdEZ\ )d^d_dLdMZ]d`dRdSZ^dadTdUZ_GdVdWdWZ`e)sVe`ZYeYZa dbdcd[d\ZbdS)d) annotationsN)HTTPConnection) HTTPException)ResponseNotReadytimeout HTTPResponse)_TYPE_PEER_CERT_RET_DICT) SSLTransport)HTTPHeaderDict)probe)assert_header_parsing)_DEFAULT_TIMEOUT _TYPE_TIMEOUTTimeout)to_str) wait_for_readc@s eZdZdS) BaseSSLErrorN)__name__ __module__ __qualname__rrJ/usr/local/bin/dhwp/env/lib/python3.10/site-packages/urllib3/connection.pyr%sr) _TYPE_BODY) ProxyConfig)_ResponseOptions __version__)ConnectTimeoutErrorHeaderParsingErrorNameResolutionErrorNewConnectionError ProxyErrorSystemTimeWarning) SKIP_HEADERSKIPPABLE_HEADERS connectionssl_)body_to_chunks)assert_fingerprint)create_urllib3_context is_ipaddressresolve_cert_reqsresolve_ssl_versionssl_wrap_socket)CertificateErrormatch_hostname)UrlPihttphttpsiz[^-!#$%&'*+.^_`|~0-9a-zA-Z]cseZdZUdZedZded<ejej dfgZ ded<dZ d ed <d Z d ed <ded<ded<ded<d ed<ded<ded<ded<ded< die d de d d ddjfd*d+Zedkd,d-Zejdld/d-Zdmd1d2Z dndofd6d7 Zejd8ksd9ejkrd:krnn"dpd=d>Zejd8krdqd?d@Znd9ejkrd:krnndqdAd@ZdqdBdCZedrdDdEZedrdFdGZedrdHdIZedrdJdKZedrdLdMZdqfdNdO Z  dsdtfdTdU ZdufdXdY Z dvddZdZdZd[dwdbdcZ! dvdxdddeZ"dyfdgdh Z#Z$S)zra 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: - ``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., ``[]``). r6ztyping.ClassVar[int] default_portrz0typing.ClassVar[connection._TYPE_SOCKET_OPTIONS]default_socket_optionsFbool is_verifiedNz bool | Noneproxy_is_verifiedint blocksizetuple[str, int] | Nonesource_addressz&connection._TYPE_SOCKET_OPTIONS | Nonesocket_options_has_connected_to_proxyz_ResponseOptions | None_response_options str | None _tunnel_host int | None _tunnel_port_tunnel_scheme@)rr@r>rAproxy proxy_confighoststrportrr&None | connection._TYPE_SOCKET_OPTIONSrJ Url | NonerKProxyConfig | NonereturnNonec sPtj||t|||d||_||_||_d|_d|_d|_ d|_ d|_ dS)N)rLrNrr@r>F) super__init__rresolve_default_timeoutrArJrKrBrCrErGrH) selfrLrNrr@r>rArJrK __class__rrrUs 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_hostrstriprWrrrrLs zHTTPConnection.hostvaluecCs ||_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[)rWr^rrrrLs  socket.socketc Csztj|j|jf|j|j|jd}WnCtjy'}zt |j |||d}~wt yA}zt |d|j d|jd|d}~wt yU}z t|d||d}~wwtd||j |j|S)zoEstablish a socket connection and set nodelay settings on it. :return: New socket connection. )r@rANzConnection to z timed out. (connect timeout=)z&Failed to establish a new connection: zhttp.client.connect)r(create_connectionr[rNrr@rAsocketgaierrorr"rL SocketTimeoutr OSErrorr#sysaudit)rWsockerrr _new_conns8   zHTTPConnection._new_connheaderstyping.Mapping[str, str] | Noneschemecs4|dvr td|dtj|||d||_dS)Nr5z$Invalid proxy scheme for tunneling: z", must be either 'http' or 'https')rNrk) ValueErrorrT set_tunnelrH)rWrLrNrkrmrXrrros   zHTTPConnection.set_tunnel) )rp )rprsrpipbytescCs$d|vr|ddkrd|dS|S)N:r[[]r)rWrtrrr _wrap_ipv6s zHTTPConnection._wrap_ipv6c Cs>tjj}d||jd|jf}|g}|jD]\}}| |d|ddq| d| d |~|j |j |jd}zU|\}}} |tjjkrb|td |d |  |j|d } t| |krwtjd | szn| dvrn|jdkrtd| qcW|dSW|dS|w)NsCONNECT %s:%d HTTP/1.0 ascii:  latin-1 methodTunnel connection failed:  Trz header line)r rrheader:)r6client_MAXLINErzrEencoderG_tunnel_headersitemsappendsendjoinresponse_classrh_method _read_status HTTPStatusOKcloserestripfpreadlinelen LineTooLong debuglevelprintdecode) rWrconnectrkheaderr^responseversioncodemessagelinerrr_tunnelsD      zHTTPConnection._tunnelc Csd||jd|jf}|g}|jD]\}}||d|ddq|d|d|~|j |j |j d}z>| \}}}t j|j|_|jd krb|jD] }td |qX|t jjkrx|td |d |W|dS|w) NsCONNECT %s:%d HTTP/1.1 idnar|r}r~rrrrrrr)rzrErrGrrrrrrrhrrr6r _read_headersr_raw_proxy_headersrrrrrrrer) rWrrkrr^rrrrrrrr"s0    cCs>||_|jrd|_|t|j|_|jrd|_dSdS)NTF)rjrhrErBrr:rJr<r]rrrrDs   zHTTPConnection.connectcCs |jduSN)rhr]rrr is_closedUs zHTTPConnection.is_closedcCs|jdurdSt|jdd S)NFgr)rhrr]rrr is_connectedYs zHTTPConnection.is_connectedcCs|jSr)rBr]rrrhas_connected_to_proxy_sz%HTTPConnection.has_connected_to_proxycCst|jo |jduS)zT Return True if a forwarding proxy is configured, else return False N)r:rJrEr]rrrproxy_is_forwardingcsz"HTTPConnection.proxy_is_forwardingcCs |jduS)zS Return True if a tunneling proxy is configured, else return False N)rEr]rrrproxy_is_tunnelingjs z!HTTPConnection.proxy_is_tunnelingcstz tWd|_d|_d|_d|_d|_d|_d|_d|_ dSd|_d|_d|_d|_d|_d|_d|_d|_ w)NF) rTrrhr;r<rBrCrErGrHr]rXrrrqs$  zHTTPConnection.closerurl skip_hostskip_accept_encodingcs<t|}|rtd|d|dtj||||dS)z+Method cannot contain non-token characters z (found at least r`)rr)_CONTAINS_CONTROL_CHAR_REsearchrngrouprT putrequest)rWrrrrmatchrXrrrs zHTTPConnection.putrequestrvaluescsftdd|Dstj|g|RdSt|tvr1dddttD}td|ddS) rcss"|] }t|to |tkVqdSr) isinstancerMr&).0vrrr s z+HTTPConnection.putheader..z', 'cSsg|]}t|qSr)rMtitle)rrrrr sz,HTTPConnection.putheader..z(urllib3.util.SKIP_HEADER only supports ''N) anyrT putheaderrlowerr'rsortedrn)rWrrskippable_headersrXrrrs zHTTPConnection.putheaderT)chunkedpreload_contentdecode_contentenforce_content_lengthbody_TYPE_BODY | NonerrrrcCs|jdur |j|jt|||||d|_|duri}tdd|D} d| v} d| v} |j||| | dt|||jd} | j } | j }|rQd| vrP| d d n)d | vrXd }n"d| vr_d }nd }|durr| durqd }| d d n| dt |d| vr| dt |D] \}}| ||q|| dur| D]"}|sqt|t r|d}|r|dt||fq||q|r|ddSdS)N)request_method request_urlrrrcss|] }t|VqdSr)rr)rkrrrrsz)HTTPConnection.request..zaccept-encodingrL)rr)rr>ztransfer-encodingzTransfer-Encodingrzcontent-lengthFTzContent-Lengthz user-agentz User-Agentzutf-8s%x %b s0 )rh settimeoutrrrC frozensetrr*r>chunkscontent_lengthrrM_get_default_user_agentr endheadersrrrr)rWrrrrkrrrr header_keysrr chunks_and_clrrrr^chunkrrrrequestsh       zHTTPConnection.requestcCs(tjdtdd|j||||dddS)z Alternative to the common request method, which sends the body with chunked encoding and not as one block zHTTPConnection.request_chunked() is deprecated and will be removed in urllib3 v2.1.0. Instead use HTTPConnection.request(..., chunked=True).category stacklevelT)rrkrN)warningswarnDeprecationWarningr)rWrrrrkrrrrequest_chunkeds  zHTTPConnection.request_chunkedr cs|jdurt|j}d|_|j|jddlm}t|jdd}t }zt |j Wn!t t fyO}ztjdt||j|ddWYd}~nd}~wwt|j }||||j|jt|dd |j|j|j||j|j|j|d }|S) a Get the response from the server. If the HTTPConnection is in the correct state, returns an instance of HTTPResponse or of whatever object is returned by the response_class variable. If a request has not been sent or if a previous response has not be handled, ResponseNotReady is raised. If the HTTP response indicates that the connection should be closed, then it will be closed before the response is returned. When the connection is closed, the underlying socket is closed. Nrr shutdownz$Failed to parse headers (url=%s): %sT)exc_info _http_vsn_strzHTTP/?) rrkstatusrversion_stringreasonrroriginal_responserrr sock_shutdown)rCrrhrrrr getattrrT getresponsermsgr! TypeErrorlogwarning_url_from_connectionrr rrrrrrrr)rW resp_optionsr _shutdownhttplib_responsehperkrrXrrrsH     zHTTPConnection.getresponser)rLrMrNrFrrr@r?r>r=rArOrJrPrKrQrRrSrRrM)r^rMrRrS)rRr_)NNr6) rLrMrNrFrkrlrmrMrRrS)rtrurRrurRrS)rRr:)FF) rrMrrMrr:rr:rRrS)rrMrrMrRrS)NN)rrMrrMrrrkrlrr:rr:rr:rr:rRrS) rrMrrMrrrkrlrRrS)rRr )%rrr__doc__port_by_schemer8__annotations__rb IPPROTO_TCP TCP_NODELAYr9r;r<rrUpropertyrLsetterrjrorf version_inforzrrrrrrrrrrrrr __classcell__rrrXrrRs        $   (  "     e rcseZdZUdZedZdZded<dZded<dZ ded<dZ d ed <dZ ded <dZ d ed <dZ d ed<dZded<dZded< d9eddejdddddddddddddddddd:fd-d.Z         d;dd7d8ZZS)?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`. r7Nint | str | None cert_reqsrDca_certs ca_cert_dirNone | str | bytes ca_cert_data ssl_versionrFssl_minimum_versionssl_maximum_versionr+z!typing.Callable[..., None] | None_connect_callbackrI)rr@r>rArJrKrassert_hostnamer+server_hostname ssl_contextrrrrrr cert_filekey_file key_passwordrLrMrNrrr@r?r>r=rArOrJrPrKrQr"None | str | typing.Literal[False]r r ssl.SSLContext | Noner r r rRrSc stj||||||||d||_||_||_| |_| |_| |_| |_||_ ||_ ||_ |o3t j ||_|orArJrK)rTrUr r r r r rr+rrrospath expanduserrrr verify_moder.rr)rWrLrNrr@r>rArJrKrrr+r r rrrrrrr r r rXrrrUgs:    zHTTPSConnection.__init__c Cstjdtdd|dur|jdur|jj}ntd}||_||_||_||_ ||_ ||_ |o3t j ||_|or=rArOrJrPrKrQrrrrr+rDr rDr rrrDrrDrrrrFrrFrrr rDr rDr rDrRrS) NNNNNNNNN)r rDr rDrrr rDrrDrrr+rDrrDrrrRrSr)r/rMrhr_rRr0)rrrrrr8rrrrrrrrr+rrrr9rUrrrrrrrXrrUs`          @ ) rc@s"eZdZUdZded<ded<dS)_WrappedAndVerifiedSocketz[ Wrapped socket and whether the connection is verified after the TLS handshake zssl.SSLSocket | SSLTransportrbr:r;N)rrrrrrrrrr1us  r1F)rrhr_rNone | str | intrrrFrr rDr r rrrrrrr+r r rrr:rRc Csld}|durd}tt|||t|d}n|}t||_| s*| s*| dus*tjs*tjs-d|_|s>| s>| s>|r>t|dr>| | durZ| d}d|vrT|d| d}t |rZ|} t |||||| | | ||d }zA| rut|jdd | n&|jtjkr|js| dur|}|rd}nt|d dpd}t|| p| |t||jtjkpt| d WSty|w) a2Logic for constructing an SSLContext from all TLS parameters, passing that down into ssl_wrap_socket, and then doing certificate verification either via hostname or fingerprint. This function exists to guarantee that both proxies and targets have the same behavior when connecting via TLS. FNT)rrrrload_default_certs[]%) rhkeyfilecertfiler rrrr r r) binary_formhostname_checks_common_name)rbr;)r,r/r.rr) IS_PYOPENSSLHAS_NEVER_CHECK_COMMON_NAMEcheck_hostnamehasattrr3rrfindr-r0_assert_fingerprint getpeercertssl CERT_NONEr_match_hostnamer1 CERT_REQUIREDr:r'r)rhrrrrr r r rrrrr+r r rdefault_ssl_contextcontext normalizedssl_sockcertr9rrrr&s       r&rI_TYPE_PEER_CERT_RET_DICT | Noneasserted_hostnamerMr9rSc CsX|d}t|r |}z t|||WdSty+}z td||||_d}~ww)Nr4z@Certificate did not match expected hostname: %s. Certificate: %s)rr-r2r1rr _peer_cert)rIrKr9stripped_hostnamerirrrrCs rCerr Exception proxy_schemer$cCs`dtdt|}d|vpd|vpd|v}d}td|r%|dkr%|nd |}||_|S) Nrz[^a-z]zwrong version numberzunknown protocolzrecord layer failurez. Your proxy appears to only use HTTP and not HTTPS, try changing your proxy URL to be HTTP. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#https-proxy-error-http-proxyzUnable to connect to proxyr7r)rresplitrMrr$ __cause__)rNrPerror_normalizedis_likely_http_proxyhttp_proxy_warningnew_errrrr_wrap_proxy_errors rXcCs dtS)Nzpython-urllib3/rrrrrr/s rc@seZdZdZdS)DummyConnectionz-Used to detect a failed ConnectionCls import.N)rrrrrrrrrY3srYconn HTTPConnection | HTTPSConnectionrcCs(t|trdnd}t||j|j|djS)zUReturns the URL from a given connection. This is mainly used for testing and logging.r7r6)rmrLrNr)rrr3rLrNr)rZrrmrrrr>sr)"rhr_rr2rr2rrFrrFr rDr rDr rDrrDrrDrrrrr+rDr rDr rrr:rRr1)F)rIrJrKrMr9r:rRrS)rNrOrPrDrRr$rr)rZr[rrDrRrM)c __future__rr" http.clientr6loggingrrQrbrfrr rr_HTTPConnectionrrrrd TYPE_CHECKINGrr util.ssl_r util.ssltransportr _collectionsr http2rr util.responser util.timeoutrrr util.utilr util.waitrrASSLErrorr ImportErrorAttributeErrorr'_base_connectionrrr_versionr exceptionsr r!r"r#r$r%utilr&r'r(r) util.requestr*r+r?r,r-r.r/r0util.ssl_match_hostnamer1r2util.urlr3ConnectionErrorBrokenPipeError getLoggerrrrr#r%compilerr NamedTupler1r&rCrXrrYVerifiedHTTPSConnectionrrrrrs                         "