3 ]% @sddlZddlZddlZddlmZmZddlmZddl Z ddl Z ddl m Z dZ dZyddlZejZWnek rYnXddlmZddlmZmZmZmZdd lmZd d ZGd d d eZdS)N)ReadTimeoutErrorSSLError)Retry) decodestring) Connection)ConnectionErrorImproperlyConfiguredConnectionTimeoutr) urlencodecKstjf|}|S)z A helper function around creating an SSL context https://docs.python.org/3/library/ssl.html#context-creation Accepts kwargs in the same manner as `create_default_context`. )sslcreate_default_context)kwargsctxrN/tmp/pip-build-z81i1n8o/elasticsearch/elasticsearch/connection/http_urllib3.pycreate_ssl_context"s rcs`eZdZdZddddeddddddddddddffdd Zdddfdfd d Zd d ZZS)Urllib3HttpConnectionaY Default connection class using the `urllib3` library and the http protocol. :arg host: hostname of the node (default: localhost) :arg port: port to use (integer, default: 9200) :arg url_prefix: optional url prefix for elasticsearch :arg timeout: default timeout in seconds (float, default: 10) :arg http_auth: optional http auth information as either ':' separated string or a tuple :arg use_ssl: use ssl for the connection if `True` :arg verify_certs: whether to verify SSL certificates :arg ssl_show_warn: show warning when verify certs is disabled :arg ca_certs: optional path to CA bundle. See https://urllib3.readthedocs.io/en/latest/security.html#using-certifi-with-urllib3 for instructions how to get default set :arg client_cert: path to the file containing the private key and the certificate, or cert only if using client_key :arg client_key: path to the file containing the private key if using separate cert and key files (client_cert will contain only the cert) :arg ssl_version: version of the SSL protocol to use. Choices are: SSLv23 (default) SSLv2 SSLv3 TLSv1 (see ``PROTOCOL_*`` constants in the ``ssl`` module for exact options for your environment). :arg ssl_assert_hostname: use hostname verification if not `False` :arg ssl_assert_fingerprint: verify the supplied certificate fingerprint if not `None` :arg maxsize: the number of connections which will be kept open to this host. See https://urllib3.readthedocs.io/en/1.4/pools.html#api for more information. :arg headers: any custom http headers to be add to requests :arg http_compress: Use gzip compression :arg cloud_id: The Cloud ID from ElasticCloud. Convient way to connect to cloud instances. Other host connection params will be ignored. localhosti#NFT c s|rF|jd\}}t|jdjdjd\}}}d||f}d}d}tt|jf|||d|||_tj dd|_ |dk rt |t t frdj|}|j jtj |d |rx|D]}|||j |j<qW|jdkr|j jtj dd |j jd d i|j jd d|j jd|jtj}i}|rZ|tk sP|sP|sP| sP| rZtjd|r|jrtj}|j| |dn~|jrtj}|j| | | d|tkrd}|dkrtn|}|r|std|jd||| dn|rtjd|||f||j| d||_dS)N:zutf-8$z%s.%sZ9243T)hostportuse_ssl) keep_alive) basic_auth)accept_encodingzcontent-encodinggzipz content-typezapplication/jsonz user-agentzBWhen using `ssl_context`, all other SSL related kwargs are ignored)assert_fingerprint ssl_context) ssl_versionassert_hostnamer zRoot certificates are missing for certificate validation. Either pass them in using the ca_certs parameter or install certifi to use it automatically. CERT_REQUIRED) cert_reqsca_certs cert_filekey_filez?Connecting to %s using SSL with verify_certs=False is insecure.)rtimeoutmaxsize)splitrencodedecodesuperr__init__ http_compressurllib3 make_headersheaders isinstancetuplelistjoinupdatelower setdefaultZ_get_default_user_agentHTTPConnectionPoolVERIFY_CERTS_DEFAULTwarningswarnrHTTPSConnectionPoolCA_CERTSr r)pool)selfrrZ http_authrZ verify_certsZ ssl_show_warnr& client_certZ client_keyr"Zssl_assert_hostnameZssl_assert_fingerprintr*r3r!r0Zcloud_idrZ cluster_nameurlZes_uuidZ kibana_uuidkZ pool_classkw) __class__rrr/Psz           zUrllib3HttpConnection.__init__cCs|j|}|rd|t|f}|j|}tj} yi} |rB|| d<t|tsV|jd}t|tsj|jd}|j} |r| j} | j ||j r|ryt j |}Wn t k rt jj |}YnX|jj|||ftd| d| } tj| } | jjd}Wntk r}zl|j||||tj| |dt|trJtdt||t|trftdt||tdt||WYdd}~XnXd | jkod kn r| j|kr|j||||| | j||j| j||j||||| j|| | j| j|fS) Nz%s?%sr)zutf-8F)retriesr3) exceptionzN/ATIMEOUTi,)Z url_prefixr rtimer4strr,r3copyr8r0rcompressAttributeErrorzlibrAurlopenrdatar- ExceptionZlog_request_failUrllibSSLErrorrrr r statusZ _raise_errorZlog_request_success getheaders)rBmethodrDparamsbodyr)ignorer3full_urlstartrFZrequest_headersresponsedurationZraw_dataerrrperform_requestsR           ",z%Urllib3HttpConnection.perform_requestcCs|jjdS)z. Explicitly closes connection N)rAclose)rBrrrrbszUrllib3HttpConnection.close) __name__ __module__ __qualname____doc__r<r/rarb __classcell__rr)rGrr.s( e=r)rLr r1Zurllib3.exceptionsrrrUZurllib3.util.retryrr=rbase64rr<r@certifiwhere ImportErrorbaser exceptionsr r r compatr rrrrrrs&