3 ]U @sddlZddlZddlmZyddlZdZWnek rDdZYnXddlmZddl m Z m Z m Z m Z dd lmZmZGd d d eZdS) N) decodestringTF) Connection)ConnectionErrorImproperlyConfiguredConnectionTimeoutSSLError) urlencode string_typesc s>eZdZdZd fdd Zdddfdfd d Zd d ZZS)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 cloud_id: The Cloud ID from ElasticCloud. Convient way to connect to cloud instances. Other host connection params will be ignored. localhost#NFTc  szts td| rR| jd\} } t| jdjdjd\}}}d||f}d}d}tt|jf|||d| t j |_ | pi|j _ |j j j d d |j j j d |j|dk rt|ttfrt|}nt|trt|jdd }||j _d |jrdnd|||jf|_||j _| s"||j _n|r4|| f|j _|rP|sHtd||j _|jrv| rv|rvtjd|jdS)Nz6Please install requests to use RequestsHttpConnection.:zutf-8$z%s.%si$T)hostportuse_sslz content-typezapplication/jsonz user-agentrzhttp%s://%s:%d%ssz7You cannot pass CA certificates when verify SSL is off.z?Connecting to %s using SSL with verify_certs=False is insecure.)REQUESTS_AVAILABLErsplitrencodedecodesuperr __init__requestsSessionsessionheaders setdefaultZ_get_default_user_agent isinstancetuplelistr authrZ url_prefixbase_urlverifycertwarningswarn)selfrrZ http_authrZ verify_certsZ ssl_show_warnca_certs client_certZ client_keyrZcloud_idkwargsZ cluster_nameurlZes_uuidZ kibana_uuid) __class__O/tmp/pip-build-z81i1n8o/elasticsearch/elasticsearch/connection/http_requests.pyr*sP           zRequestsHttpConnection.__init__cCs|j|}|r"d|t|pif}tj}tj||||d} |jj| } |jj| jiddd} d|ph|j i} | j | y&|jj | f| } tj|}| j }Wnt k r,}zr|j||| j|tj||dt|tjjrtdt||t|tjr tdt||tdt||WYdd}~XnXd| jkoDdkn r| j|kr|j||| jj||| j||j| j||j||| jj|| j||| j| j|fS) Nz%s?%s)methodrr.datatimeout) exceptionzN/ATIMEOUTi,)r%r timerRequestrprepare_requestmerge_environment_settingsr.r4updatesendtext ExceptionZlog_request_failpath_urlr! exceptionsr strTimeoutrr status_coderequestZ _raise_errorZlog_request_successr)r*r2r.paramsbodyr4ignorerstartrEprepared_requestsettings send_kwargsresponsedurationZraw_dataer0r0r1perform_requestls^      "  z&RequestsHttpConnection.perform_requestcCs|jjdS)z/ Explicitly closes connections N)rclose)r*r0r0r1rQszRequestsHttpConnection.close) r rNFTTNNNNN)__name__ __module__ __qualname____doc__rrPrQ __classcell__r0r0)r/r1r s7=r )r8r(base64rrr ImportErrorbaserrArrrr compatr r r r0r0r0r1s