3 `=\6@sddlmZddlZddlZddlZddlZddlmZmZ ddl Z ddl m Z ddl mZddl mZyddlZejZWn,eefk rdZGdd d eZYnXyeZWn$ek rGd d d eZYnXdd lmZmZmZmZdd lm Z m!Z!ddl"m#Z#m$Z$m%Z%m&Z&m'Z'ddl(m)Z)ddl*m+Z+ej,e-Z.dddZ/ej0dddZ1Gddde2Z3Gdddee2ZGdddeZ4Gddde4Z5dd Z6ere4Z7e5Z4ne3Z4dS)!)absolute_importN)errortimeout)six)HTTPConnection) HTTPExceptionc@s eZdZdS) BaseSSLErrorN)__name__ __module__ __qualname__r r k/private/var/folders/47/550316q90kl84vt_jn5ctz8chwmm0c/T/pip-install-yoigbb1v/urllib3/urllib3/connection.pyr sr c@s eZdZdS)ConnectionErrorN)r r r r r r rrsr)NewConnectionErrorConnectTimeoutErrorSubjectAltNameWarningSystemTimeWarning)match_hostnameCertificateError)resolve_cert_reqsresolve_ssl_versionassert_fingerprintcreate_urllib3_contextssl_wrap_socket) connection)HTTPHeaderDictPi)httphttpsic@seZdZdZdS)DummyConnectionz-Used to detect a failed ConnectionCls import.N)r r r __doc__r r r rr"Asr"c@speZdZdZedZejejdfgZ dZ ddZ e ddZ e jd dZ d d Zd d ZddZdddZdS)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., ``[]``). rrFcOsDtjr|jdd|jd|_|jd|j|_tj|f||dS)Nstrictsource_addresssocket_options) rPY3popgetr%default_socket_optionsr&_HTTPConnection__init__)selfargskwr r rr,gs   zHTTPConnection.__init__cCs |jjdS)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_hostrstrip)r-r r rhosttszHTTPConnection.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)r1)r-valuer r rr3scCsi}|jr|j|d<|jr$|j|d<ytj|j|jf|jf|}Wnftk rz}zt|d|j |jfWYdd}~Xn0t k r}zt |d|WYdd}~XnX|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)Nz(Failed to establish a new connection: %s) r%r&rcreate_connectionr1portr SocketTimeoutrr3 SocketErrorr)r-extra_kwconner r r _new_conns    zHTTPConnection._new_conncCs||_|jr|jd|_dS)Nr)sock _tunnel_host_tunnel auto_open)r-r:r r r _prepare_connszHTTPConnection._prepare_conncCs|j}|j|dS)N)r<rA)r-r:r r rconnectszHTTPConnection.connectNc Cst|dk r|ni}d|k}d|k}|j||||dx |jD]\}}|j||q@Wd|krl|jdd|j|dk rtjtf} t|| r|f}xh|D]`} | sqt| ts| j d} t t | d d} |j | j d |j d |j | |j d qW|j d dS) z Alternative to the common request method, which sends the body with chunked encoding and not as one block Nzaccept-encodingr3)skip_accept_encoding skip_hostztransfer-encodingzTransfer-Encodingchunkedutf8zutf-8s s0 ) r putrequestitems putheader endheadersr string_typesbytes isinstanceencodehexlensend) r-methodurlbodyheadersrCrDheaderr4stringish_typeschunklen_strr r rrequest_chunkeds8         zHTTPConnection.request_chunked)NN)r r r r#port_by_scheme default_portsocket IPPROTO_TCP TCP_NODELAYr* is_verifiedr,propertyr3setterr<rArBr[r r r rrFs  rc@s:eZdZedZdZddddejddfddZddZ dS)HTTPSConnectionrNc Ks>tj|||f||d| ||_||_||_||_d|_dS)N)r$rr)rr,key_file cert_file ssl_contextserver_hostname _protocol) r-r3r6rerfr$rrgrhr/r r rr,szHTTPSConnection.__init__cCsR|j}|j||jdkr2ttdtdd|_t||j|j|j|j d|_ dS)N) ssl_version cert_reqs)r=keyfilecertfilergrh) r<rArgrrrrrerfrhr=)r-r:r r rrBs  zHTTPSConnection.connect) r r r r\r]rjr^_GLOBAL_DEFAULT_TIMEOUTr,rBr r r rrds rdc@s6eZdZdZdZdZdZdZdZdddZ ddZ dS)VerifiedHTTPSConnectionz[ Based on httplib.HTTPSConnection but wraps the socket with SSL certification. NcCsn|dkr(|s|rd}n|jdk r(|jj}||_||_||_||_||_|oTtjj ||_ |oftjj ||_ dS)zX This method should only be called once, before the connection is used. N CERT_REQUIRED) rg verify_modererfrkassert_hostnamerospath expanduserca_certs ca_cert_dir)r-rerfrkrvrrrrwr r rset_certs  z VerifiedHTTPSConnection.set_certc CsZ|j}|j}|jr.||_|jd|_|j}|}|jdk rB|j}tjj t k}|rft j dj t t|jdkrtt|jt|jd|_|j}t|j|_t||j|j|j|j||d|_|jrt|jjdd|jnb|jtjkot|dd o|j dk r<|jj}|j!d fs*t j d j |t"t#||j p8||jtj$kpR|jdk |_%dS) NrzWSystem time is way off (before {0}). This will probably lead to SSL verification errors)rjrk)r=rlrmrvrwrhrgT) binary_formcheck_hostnameFsubjectAltNamezCertificate 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.))&r<r3r>r=r?r@rhdatetimedatetoday RECENT_DATEwarningswarnformatrrgrrrjrrkrqrrerfrvrwr getpeercertssl CERT_NONEgetattrrrr)r_match_hostnamerpra)r-r:hostnamerh is_time_offcontextcertr r rrB+sZ        zVerifiedHTTPSConnection.connect)NNNNNNN) r r r r#rkrvrwrjrrxrBr r r rros rocCsLyt||Wn8tk rF}ztjd||||_WYdd}~XnXdS)Nz@Certificate did not match expected hostname: %s. Certificate: %s)rrlogr _peer_cert)rasserted_hostnamer;r r rrtsr)8 __future__rr|loggingrsr^rr8rr7rpackagesrZpackages.six.moves.http_clientrr+rrSSLErrorr ImportErrorAttributeError BaseExceptionr NameError Exception exceptionsrrrrZpackages.ssl_match_hostnamerrZ util.ssl_rrrrrutilr _collectionsr getLoggerr rr\r}robjectr"rdrorUnverifiedHTTPSConnectionr r r rsL        (m