U .Ѫ_8 @sddlmZddlZddlZddlZddlZddlZddlmZm Z ddl Z ddl m Z ddlmZddlmZzddlZejZWn,eefk rdZGdd d eZYnXzeZWn$ek rGd d d eZYnXdd lmZmZmZmZdd l m!Z!m"Z"ddl#m$Z$m%Z%m&Z&m'Z'm(Z(ddl)m*Z*ddl+m,Z,e-e.Z/dddZ0e1dddZ2e3dZ4Gddde5Z6Gdddee5ZGdddeZ7ddZ8ese6Z7e7Z9dS))absolute_importN)errortimeout)six)HTTPConnection) HTTPExceptionc@s eZdZdS) BaseSSLErrorN__name__ __module__ __qualname__rr9/Users/cjl/code/aws-vpc-ipam/lambda/urllib3/connection.pyr sr c@s eZdZdS)ConnectionErrorNr rrrrrsr)NewConnectionErrorConnectTimeoutErrorSubjectAltNameWarningSystemTimeWarning)match_hostnameCertificateError)resolve_cert_reqsresolve_ssl_versionassert_fingerprintcreate_urllib3_contextssl_wrap_socket) connection)HTTPHeaderDictPi)httphttpsiz[^-!#$%&'*+.^_`|~0-9a-zA-Z]c@seZdZdZdS)DummyConnectionz-Used to detect a failed ConnectionCls import.N)r r r __doc__rrrrr!Asr!c@sxeZdZdZedZejejdfgZ dZ ddZ e ddZ e jd dZ d d Zd d ZddZddZdddZdS)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)Nstrictsource_addresssocket_options) rPY2popgetr$default_socket_optionsr%_HTTPConnection__init__)selfargskwrrrr+hs   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_hostrstrip)r,rrrhostuszHTTPConnection.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,valuerrrr2sc 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%rcreate_connectionr0portr SocketTimeoutrr2 SocketErrorr)r,Zextra_kwconnerrr _new_conns2    zHTTPConnection._new_conncCs$||_t|ddr |d|_dS)N _tunnel_hostr)sockgetattr_tunnel auto_openr,r8rrr _prepare_conns zHTTPConnection._prepare_conncCs|}||dS)N)r:rAr@rrrconnectszHTTPConnection.connectcOs8t|}|r"td||ftj|||f||S)zSend a request to the serverzAMethod cannot contain non-token characters %r (found at least %r))_CONTAINS_CONTROL_CHAR_REsearch ValueErrorgroupr* putrequest)r,methodurlr-kwargsmatchrrrrGs  zHTTPConnection.putrequestNc Cst|dk r|ni}d|k}d|k}|j||||d|D]\}}|||q>d|krh|dd||dk rtjtf} t|| r|f}|D]`} | sqt| ts| d} t t | d d} t | } | d 7} | | 7} | d 7} | | 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-Encodingchunkedutf8s s0 )rrGitems putheader endheadersr string_typesbytes isinstanceencodehexlen bytearraysend) r,rHrIbodyheadersrLrMheaderr3Zstringish_typeschunkZlen_strZto_sendrrrrequest_chunkeds<       zHTTPConnection.request_chunked)NN)r r r r"port_by_scheme default_portsocket IPPROTO_TCP TCP_NODELAYr) is_verifiedr+propertyr2setterr:rArBrGr`rrrrrGs     rc @sZeZdZedZdZdZdZdZdZ dZ ddddde j ddfddZ d ddZddZdS) HTTPSConnectionr Nc KsDtj|||f||d| ||_||_||_||_| |_d|_dS)N)r#rr )rr+key_file cert_file key_password ssl_contextserver_hostnameZ _protocol) r,r2r5rjrkrlr#rrmrnr.rrrr+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)rm verify_moderrjrk cert_reqsrlassert_hostnamerospath expanduserca_certs ca_cert_dir ca_cert_data) r,rjrkrprlrurqrrvrwrrrset_certs  zHTTPSConnection.set_certc Cs|}|j}t|ddr4||_|d|_|j}|}|jdk rH|j}tj t k}|rlt dt td}|jdkrd}tt|jt|jd|_|j}t|j|_|js|js|js|rt|dr|t||j|j|j|j|j|j||d |_|j rt |jj!dd |j nd|jt"j#kr~t|d ds~|j$dk r~|j!}|%d d slt d |t&t'||j$pz||jt"j(kp|j dk |_)dS)Nr;rzWSystem time is way off (before {0}). This will probably lead to SSL verification errorsFT) ssl_versionrpload_default_certs) r<keyfilecertfilerlrurvrwrnrm) binary_formcheck_hostnamesubjectAltNamerzCertificate 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;rndatetimedatetoday RECENT_DATEwarningswarnformatrrmrrryrrprorurvrwhasattrrzrrjrkrlr getpeercertssl CERT_NONErqr(r_match_hostname CERT_REQUIREDrf)r,r8hostnamernZ is_time_offZdefault_ssl_contextcontextcertrrrrB3s           zHTTPSConnection.connect) NNNNNNNNN)r r r rarbrprurvrwryrrc_GLOBAL_DEFAULT_TIMEOUTr+rxrBrrrrris6  !ric CsLzt||Wn8tk rF}ztd||||_W5d}~XYnXdS)Nz@Certificate did not match expected hostname: %s. Certificate: %s)rrlogwarningZ _peer_cert)rZasserted_hostnamer9rrrrsr): __future__rrerloggingrrrcrr7rr6rpackagesrZpackages.six.moves.http_clientrr*rrSSLErrorr ImportErrorAttributeError BaseExceptionr NameError Exception exceptionsrrrrpackages.ssl_match_hostnamerrZ util.ssl_rrrrrZutilr _collectionsr getLoggerr rrarrcompilerCobjectr!rirVerifiedHTTPSConnectionrrrrsL          ((