a _b`*@sddlZddlZddlZddlZddlmZddlmZddlm Z ddl m Z m Z ddl mZmZmZmZdd lmZeZeZdZzddlZeZWneyYn0d d ZGd d d eZdS)N)ReadTimeoutError)SSLError)Retry)reraise_exceptions urlencode)ConnectionErrorConnectionTimeoutImproperlyConfiguredr) ConnectioncKstjfi|}|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)kwargsctxrK/tmp/pip-target-4jja1joz/lib/python/opensearchpy/connection/http_urllib3.pycreate_ssl_context=srcsZeZdZdZddddeedddddddddddddffdd Zd d d Zd d ZZ S)Urllib3HttpConnectiona4 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 opensearch :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. Convenient way to connect to cloud instances. Other host connection params will be ignored. :arg api_key: optional API Key authentication as either base64 encoded string or a tuple. :arg opaque_id: Send this value in the 'X-Opaque-Id' HTTP header For tracing all requests made by this transport. localhostNF c stjdd|_tt|jf||||||||d||durjt|ttfrVd |}|j tj|dtj }i}|r|t us|t us|s|s| s| rtd|r|jrtj}| | |dn|jrdtj}| | | | d|t urd}|t urd}|dur tn|}|r8|s"td | d ||| d n,d |d <|rVtd|j|sdt||jf|j|j| d||_dS)NT) keep_alive)hostportuse_sslheaders http_compresscloud_idapi_key opaque_id:) basic_authzBWhen 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_file CERT_NONEr'z?Connecting to %s using SSL with verify_certs=False is insecure.)rtimeoutmaxsize)urllib3 make_headersrsuperr__init__ isinstancetuplelistjoinupdateHTTPConnectionPoolVERIFY_CERTS_DEFAULTSSL_SHOW_WARN_DEFAULTwarningswarnrHTTPSConnectionPoolCA_CERTSr rdisable_warningshostnamerr,pool)selfrrZ http_authrZ verify_certsZ ssl_show_warnr( client_certZ client_keyr$Zssl_assert_hostnameZssl_assert_fingerprintr-rr#rrrrrZ pool_classkw __class__rrr1ns        zUrllib3HttpConnection.__init__rc Cs|j|}|rd|t|f}|j|}t} |} zi} |rF|| d<t|tsZ|d}t|tsn|d}|j} | |pd|j r|r| |}d| d<|j j |||ftd| d| } t| }| jdd }WntyYnty~}zr|j|||| t| |d t|tr>td t||t|trZtd t||td t||WYd}~n d}~00| jd d}||d| jkrdksn| j|vr||||| || j||| j|||||| | j||| j| |fS)Nz%s?%sr,zutf-8rgzipzcontent-encodingF)retriesr surrogatepass) exceptionzN/ATIMEOUTwarningi,)Z url_prefixrrtimer2strencodercopyr6rZ_gzip_compressr@urlopenrdatadecoder ExceptionZlog_request_failUrllibSSLErrorrrr rget_allZ_raise_warningsstatusZ _raise_errorZlog_request_success getheaders)rAmethodurlparamsbodyr,ignorerfull_urlstartZ orig_bodyrCZrequest_headersresponsedurationraw_dataeZwarning_headersrrrperform_requestsd             & (z%Urllib3HttpConnection.perform_requestcCs|jdS)z. Explicitly closes connection N)r@close)rArrrre"szUrllib3HttpConnection.close)NNNrN) __name__ __module__ __qualname____doc__r8r9r1rdre __classcell__rrrDrrIs0&u @r)r rMr:r.Zurllib3.exceptionsrrrUZurllib3.util.retryrcompatrr exceptionsrr r baser objectr8r9r=certifiwhere ImportErrorrrrrrrs&