_Y9 @sddlZddlZyddlZdZWnek rHdZYnXddlmZddlmZm Z m Z m Z ddl m Z mZGd d d eZdS) NTF) Connection)ConnectionErrorImproperlyConfiguredConnectionTimeoutSSLError) urlencode string_typesc sgeZdZdZdddddddddfdd Zdddfd d Zd d ZS) 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 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 localhosti#NFTc  sxtstdtt|jd|d|| tj|_| pLi|j_|jjj dd|dk rt |t t frt |}n't |t rt |jdd}||j_d|rd nd |||jf|_||j_|s||j_n|r/||f|j_|rS|sGtd ||j_|rt| rttjd |jdS) Nz6Please install requests to use RequestsHttpConnection.hostportz content-typezapplication/json:rzhttp%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_AVAILABLErsuperr __init__requestsSessionsessionheaders setdefault isinstancetuplelistr splitauthZ url_prefixbase_urlverifycertwarningswarn) selfr rZ http_authZuse_sslZ verify_certsca_certs client_certZ client_keyrkwargs) __class__O/tmp/pip-build-66pc0izb/elasticsearch/elasticsearch/connection/http_requests.pyrs6 "      zRequestsHttpConnection.__init__cCs|j|}|r/d|t|p%if}tj}yntjd|d|d|}|jj|} |jj| d|p|j} tj|} | j } Wnt k rk} z|j ||| j |tj|d| t | tjjrtdt| | t | tjrAtdt| | tdt| | WYdd} ~ XnXd | jkod kn r| j|kr|j ||| jj || | j| |j| j| |j||| jj || j| | | j| j| fS) Nz%s?%smethodurldatatimeout exceptionzN/ATIMEOUTi,)rr timerRequestrprepare_requestsendr.text ExceptionZlog_request_failpath_urlr exceptionsrstrTimeoutrr status_coderequestZ _raise_errorZlog_request_successr)r$r+r,paramsbodyr.ignorestartr=prepared_requestresponsedurationZraw_dataer)r)r*perform_request@s0    ,+/((z&RequestsHttpConnection.perform_requestcCs|jjdS)z/ Explicitly closes connections N)rclose)r$r)r)r*rG_szRequestsHttpConnection.close)__name__ __module__ __qualname____doc__rrFrGr)r))r(r*r s   !r )r2r"rr ImportErrorbaserr9rrrrcompatr r r r)r)r)r*s      "