a Y9@sddlZddlZzddlZdZWney6dZYn0ddlmZddlmZm Z m Z m Z ddl m Z mZGd d d eZdS) NTF) Connection)ConnectionErrorImproperlyConfiguredConnectionTimeoutSSLError) urlencode string_typesc s4eZdZdZdfdd Zdd 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 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 localhost#NFTc  s ts tdtt|jf||d| t|_| p8i|j_|jj dd|durt |t t frnt |}nt |t rt |dd}||j_d|rdnd |||jf|_||j_|s||j_n|r||f|j_|r|std ||j_|r|std |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 splitauth url_prefixbase_urlverifycertwarningswarn) selfrr http_authuse_sslZ verify_certsca_certs client_certZ client_keyrkwargs __class__M/Users/ymaher/Downloads/lambdas_org/elasticsearch/connection/http_requests.pyrs:        zRequestsHttpConnection.__init__r.c Cs|j|}|r"d|t|pif}t}zHtj|||d}|j|} |jj| |pX|jd} t|} | j } Wnt y} zv|j ||| j |t|| dt | tjjrtdt| | t | tjrtdt| | tdt| | WYd} ~ n d} ~ 00d| jkrdksVn| j|vrV| ||| jj || | j| || j| |||| jj || j| | | j| j| fS) Nz%s?%s)methodurldata)timeout) exceptionzN/ATIMEOUTi,)r!r timerRequestrprepare_requestsendr3text Exceptionlog_request_failpath_urlr exceptionsrstrTimeoutrr status_coderequest _raise_errorlog_request_successr)r&r0r1paramsbodyr3ignorestartrCprepared_requestresponsedurationraw_dataer.r.r/perform_request@s2      &(z&RequestsHttpConnection.perform_requestcCs|jdS)z/ Explicitly closes connections N)rclose)r&r.r.r/rP_szRequestsHttpConnection.close) r r NFTNNNN)NNNr.)__name__ __module__ __qualname____doc__rrOrP __classcell__r.r.r,r/r s# r )r7r$rr ImportErrorbaserr?rrrrcompatr r r r.r.r.r/s