a Y2 @sddlmZddlZddlZddlZddlZddlZddlmZm Z ddl Z ddl m Z ddlmZddlmZzddlZejZWn*eefydZGdd d eZYn0zeZWn"eyGd d d eZYn0dd 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/dddZ0e1dddZ2Gddde3Z4Gdddee3ZGdddeZ5Gddde5Z6ddZ7ere5Z8e6Z5ne4Z5dS))absolute_importN)errortimeout)six)HTTPConnection) HTTPExceptionc@s eZdZdS) BaseSSLErrorN__name__ __module__ __qualname__rrK/Users/ymaher/Downloads/lambdas_org/requests/packages/urllib3/connection.pyr sr c@s eZdZdS)ConnectionErrorNr rrrrrsr)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__rrrrr!Asr!c@sVeZdZdZedZejejdfgZ dZ ddZ ddZ d d Z d d ZdddZd S)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. .. note:: This is ignored for Python 2.6. It is only applied for 2.7 and 3.x - ``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., ``[]``). rrFcOs`tjr|dd|d|_tjdkr4|dd|d|j|_t j |g|Ri|dS)Nstrictsource_address)socket_options) rPY3popgetr$sys version_infodefault_socket_optionsr'_HTTPConnection__init__)selfargskwrrrr/js    zHTTPConnection.__init__c Csi}|jr|j|d<|jr$|j|d<z"tj|j|jf|jfi|}Wnjty}z"t|d|j|jfWYd}~n:d}~0t y}zt |d|WYd}~n d}~00|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_connectionhostportr SocketTimeoutr SocketErrorr)r0extra_kwconnerrr _new_conns,    zHTTPConnection._new_conncCs$||_t|ddr |d|_dS)N _tunnel_hostr)sockgetattr_tunnel auto_openr0r9rrr _prepare_conns zHTTPConnection._prepare_conncCs|}||dS)N)r;rBrArrrconnectszHTTPConnection.connectNc Cs t|dur|ni}d|v}d|v}|j||||d|D]\}}|||q>d|vrh|dd||durtjtjf} t|| r|f}|D]b} | sqt| tjs| 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-encodingr4)skip_accept_encoding skip_hostztransfer-encodingzTransfer-Encodingchunkedutf8r%zutf-8s s0 ) r putrequestitems putheader endheadersr string_types binary_type isinstanceencodehexlensend) r0methodurlbodyheadersrDrEheadervaluestringish_typeschunklen_strrrrrequest_chunkeds:       zHTTPConnection.request_chunked)NN)r r r r"port_by_scheme default_portsocket IPPROTO_TCP TCP_NODELAYr- is_verifiedr/r;rBrCr\rrrrrFs rc@s8eZdZedZdZddddejdfddZddZ dS)HTTPSConnectionr Nc Ks8tj|||f||d|||_||_||_d|_dS)N)r#rr )rr/key_file cert_file ssl_context _protocol) r0r4r5rdrer#rrfr2rrrr/szHTTPSConnection.__init__cCsN|}|||jdur2ttdtdd|_t||j|j|jd|_ dS)N ssl_version cert_reqs)r=keyfilecertfilerf) r;rBrfrrrrrdrer=rArrrrCs  zHTTPSConnection.connect) r r r r]r^rir__GLOBAL_DEFAULT_TIMEOUTr/rCrrrrrcs rcc@s6eZdZdZdZdZdZdZdZdddZ ddZ dS)VerifiedHTTPSConnectionz[ Based on httplib.HTTPSConnection but wraps the socket with SSL certification. NcCsn|dur(|s|rd}n|jdur(|jj}||_||_||_||_||_|oTtj ||_ |oftj ||_ dS)zX This method should only be called once, before the connection is used. N CERT_REQUIRED) rf verify_moderdrerjassert_hostnamerospath expanduserca_certs ca_cert_dir)r0rdrerjrurqrrvrrrset_certs  z VerifiedHTTPSConnection.set_certc CsN|}|j}t|ddr4||_|d|_|j}tj t k}|rXt d t t|jdur|tt|jt|jd|_|j}t|j|_t||j|j|j|j||d|_|jrt|jjdd|jnd|jtjkr0t|dd s0|jd ur0|j}| d d st d |t!t"||jp,||jtj#kpF|jdu|_$dS) Nr<rzWSystem time is way off (before {0}). This will probably lead to SSL verification errorsrh)r=rkrlrurvserver_hostnamerfT) binary_formcheck_hostnameFsubjectAltNamerzCertificate 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;r4r>r=r?r@r<datetimedatetoday RECENT_DATEwarningswarnformatrrfrrrirrjrprrdrerurvr getpeercertssl CERT_NONErqr*r_match_hostnamerorb)r0r9hostname is_time_offcontextcertrrrrCsj      zVerifiedHTTPSConnection.connect)NNNNNNN) r r r r"rjrurvrirrwrCrrrrrns rnc CsNzt||Wn:tyH}z"td||||_WYd}~n d}~00dS)Nz@Certificate did not match expected hostname: %s. Certificate: %s)rrlogr _peer_cert)rasserted_hostnamer:rrrrbsr)9 __future__rr|loggingrrr+r_rr7rr6rpackagesrZpackages.six.moves.http_clientrr.rrSSLErrorr ImportErrorAttributeError BaseExceptionr NameError Exception exceptionsrrrrpackages.ssl_match_hostnamerrZ util.ssl_rrrrrutilr _collectionsr getLoggerr rr]r}robjectr!rcrnrZUnverifiedHTTPSConnectionrrrrsP          &l