a _bN@sddlZddlZzddlZdZWney6dZYn0ddlmZmZmZddl m Z m Z m Z m Z ddlmZGd d d eZdS) NTF)reraise_exceptions string_types urlencode)ConnectionErrorConnectionTimeoutImproperlyConfiguredSSLError) Connectioncs@eZdZdZdfdd Zdd d Zed d Zd dZZ S)RequestsHttpConnectiona Connection using the `requests` library. :arg http_auth: optional http auth information as either ':' separated string or a tuple. Any value will be passed into requests as `auth`. :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. By default standard requests' bundle will be used. :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 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. localhostNFTc s>ts tdt|_t|jjD]}|jj|q"tt |j f|||| | | | |d||j spd|jjd<|durt |t tfrt |}nt |trt |dd}||j_d|j|jf|_||j_| s||j_n|r|| f|j_|r|std||j_|stjj|jr:|s:|r:td|jdS) Nz6Please install requests to use RequestsHttpConnection.)hostportuse_sslheaders http_compresscloud_idapi_key opaque_idzaccept-encoding:r z%s%sz7You cannot pass CA certificates when verify SSL is off.z?Connecting to %s using SSL with verify_certs=False is insecure.)REQUESTS_AVAILABLErrequestsSessionsessionlistrpopsuperr __init__r isinstancetuplersplitauthrZ url_prefixbase_urlverifycertpackagesurllib3disable_warningsrwarningswarn)selfrrZ http_authrZ verify_certsZ ssl_show_warnca_certs client_certZ client_keyrrrrrkwargskey __class__L/tmp/pip-target-4jja1joz/lib/python/opensearchpy/connection/http_requests.pyrGsd          zRequestsHttpConnection.__init__r2c Cs|j|}|pi}|r*d|t|p"if}|}|jrJ|rJ||}d|d<t} tj||||d} |j| } |j | j iddd} d|p|j i} | | z2|jj | fi| }t| }|jdd}WntyYntyv}zz|j||| j|t| |dt|tjjr4td t||t|tjrRtd t||td t||WYd}~n d}~00d |jvr|jd fnd }||d |jkrdksn|j|vr||||jj|||j|||j|| |||jj||j|||j|j|fS)Nz%s?%sgzipzcontent-encoding)methodrurldatatimeoutzutf-8 surrogatepass) exceptionzN/ATIMEOUTwarningr2i,)!r#rrZ_gzip_compresstimerRequestrprepare_requestmerge_environment_settingsr6r8updatesendcontentdecoder ExceptionZlog_request_failpath_urlr exceptionsr strTimeoutrrrZ_raise_warnings status_coderequestZ _raise_errorZlog_request_success)r+r5r6paramsbodyr8ignorerZ orig_bodystartrLprepared_requestsettings send_kwargsresponsedurationraw_dataeZwarnings_headersr2r2r3perform_requests         &     z&RequestsHttpConnection.perform_requestcCs|jjS)N)rrr+r2r2r3rszRequestsHttpConnection.headerscCs|jdS)z/ Explicitly closes connections N)rcloserYr2r2r3rZszRequestsHttpConnection.close)r NNFTTNNNNNNNN)NNNr2N) __name__ __module__ __qualname____doc__rrXpropertyrrZ __classcell__r2r2r0r3r /s*N L r )r>r)rr ImportErrorcompatrrrrHrrrr baser r r2r2r2r3s