U o‰^@;ã @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úk/private/var/folders/sd/whlwsn6x1_qgglc0mjv25_695qk2gl/T/pip-install-4zq3fp6i/urllib3/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) rÚPY2Ú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)r0)r,Úvaluerrrr2…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%rÚcreate_connectionr0ÚportrÚ SocketTimeoutrr2Ú SocketErrorr)r,Úextra_kwÚconnÚerrrÚ _new_conn�s2   ÿÿ ÿþÿzHTTPConnection._new_conncCs$||_t|ddƒr | ¡d|_dS)NÚ _tunnel_hostr)ÚsockÚgetattrÚ_tunnelÚ auto_open©r,r9rrrÚ _prepare_conn®s zHTTPConnection._prepare_conncCs| ¡}| |¡dS)N)r;rBrArrrÚ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-encodingr2)Úskip_accept_encodingÚ skip_hostztransfer-encodingzTransfer-EncodingÚchunkedÚutf8ézutf-8s s0 ) rÚ putrequestÚitemsÚ putheaderÚ endheadersrÚ string_typesÚbytesÚ isinstanceÚencodeÚhexÚlenÚsend) r,ÚmethodÚurlÚbodyÚheadersrDrEÚheaderr3Ústringish_typesÚchunkÚlen_strrrrÚrequest_chunked»s:ÿ        zHTTPConnection.request_chunked)NN)r r r r"Úport_by_schemeÚ default_portÚsocketÚ IPPROTO_TCPÚ TCP_NODELAYr)Ú is_verifiedr+Úpropertyr2Úsetterr;rBrCr\rrrrrDs    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_hostnameÚ _protocol) r,r2r5rfrgrhr#rrirjr.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Úcertfilerhrirj)r;rBrirrrmrrnÚca_certsÚ ca_cert_dirÚhasattrrorrfrgrhrjr=)r,r9Údefault_ssl_contextÚcontextrrrrCþs6  þÿþýüúzHTTPSConnection.connect) r r r r]r^rmr_Ú_GLOBAL_DEFAULT_TIMEOUTr+rCrrrrreßsö rec@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)riÚ verify_moderrfrgrnrhÚassert_hostnamerÚosÚpathÚ expanduserrrrs) r,rfrgrnrhrrrzrrsrrrÚ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)Nr<rzWSystem time is way off (before {0}). This will probably lead to SSL verification errorsFTrlro)r=rprqrhrrrsrjri)Ú binary_formÚcheck_hostnameÚsubjectAltNamerzë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.)))r;r2r>r=r?r@r<rjÚdatetimeÚdateÚtodayÚ RECENT_DATEÚwarningsÚwarnÚformatrrirrrmrrnryrrrsrtrorrfrgrhrÚ getpeercertÚsslÚ CERT_NONErzr(rÚ_match_hostnameÚ CERT_REQUIREDrb)r,r9ÚhostnamerjÚ is_time_offrurvÚcertrrrrCLsŠ  þû  þ ÿþýüø  ÿ ÿ þý ýù þzVerifiedHTTPSConnection.connect)NNNNNNNN) r r r r"rnrrrsrmrr~rCrrrrrx!s ÷ rxc CsLzt||ƒWn8tk rF}zt d||¡||_‚W5d}~XYnXdS)Nz@Certificate did not match expected hostname: %s. Certificate: %s)rrÚlogÚwarningÚ _peer_cert)r�Úasserted_hostnamer:rrrrŒ¬sýrŒ)8Ú __future__rr‚Úloggingr{r_rr7rr6r†ÚpackagesrZpackages.six.moves.http_clientrr*rrŠÚSSLErrorr Ú ImportErrorÚAttributeErrorÚ BaseExceptionrÚ NameErrorÚ ExceptionÚ exceptionsrrrrZpackages.ssl_match_hostnamerrZ util.ssl_rrrrrÚutilrÚ _collectionsrÚ getLoggerr r‘r]rƒr…Úobjectr!rerxrŒÚUnverifiedHTTPSConnectionrrrrÚsL         B