ó á¬_Zc@s£ddlZddlmZddlmZddlmZmZddlm Z m Z m Z ddl m Z mZmZmZd„Zd efd „ƒYZdS( iÿÿÿÿN(tchaini(tUrllib3HttpConnection(tConnectionPooltDummyConnectionPool(tJSONSerializert DeserializertDEFAULT_SERIALIZERS(tConnectionErrortTransportErrortSerializationErrortConnectionTimeoutcCs#|jdgƒdgkrdS|S(sn Simple callback that takes the node info from `/_cluster/nodes` and a parsed connection information and return the connection information. If `None` is returned this node will be skipped. Useful for filtering nodes (by proximity for example) or if additional information needs to be provided for the :class:`~elasticsearch.Connection` class. By default master only nodes are filtered out since they shouldn't typically be used for API operations. :arg node_info: node information from `/_cluster/nodes` :arg host: connection information (host, port) extracted from the node info trolestmasterN(tgettNone(t node_infothost((sr/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-W9yz6j/elasticsearch/elasticsearch/transport.pyt get_host_info st TransportcBs¤eZdZeeeeddeeƒddddedd„Z d „Z d „Z d „Z ed „Z d „Zed„Zd„Zdddd„Zd„ZRS(s× Encapsulation of transport-related to logic. Handles instantiation of the individual connections as well as creating a connection pool to hold them. Main interface is the `perform_request` method. gš™™™™™¹?sapplication/jsoniiöi÷iøtGETcKsütjƒ}| || j<| r/|j| ƒnt|| ƒ|_| |_||_| |_||_ | |_ ||_ ||_ ||_ ||_|j|ƒ|jj|_||_||_tjƒ|_||_||_|rø|jtƒndS(s¥ :arg hosts: list of dictionaries, each containing keyword arguments to create a `connection_class` instance :arg connection_class: subclass of :class:`~elasticsearch.Connection` to use :arg connection_pool_class: subclass of :class:`~elasticsearch.ConnectionPool` to use :arg host_info_callback: callback responsible for taking the node information from `/_cluser/nodes`, along with already extracted information, and producing a list of arguments (same as `hosts` parameter) :arg sniff_on_start: flag indicating whether to obtain a list of nodes from the cluser at startup time :arg sniffer_timeout: number of seconds between automatic sniffs :arg sniff_on_connection_fail: flag controlling if connection failure triggers a sniff :arg sniff_timeout: timeout used for the sniff request - it should be a fast api call and we are talking potentially to more nodes so we want to fail quickly. Not used during initial sniffing (if ``sniff_on_start`` is on) when the connection still isn't initialized. :arg serializer: serializer instance :arg serializers: optional dict of serializer instances that will be used for deserializing data coming from the server. (key is the mimetype) :arg default_mimetype: when no mimetype is specified by the server response assume this mimetype, defaults to `'application/json'` :arg max_retries: maximum number of retries before an exception is propagated :arg retry_on_status: set of HTTP status codes on which we should retry on a different node. defaults to ``(502, 503, 504)`` :arg retry_on_timeout: should timeout trigger a retry on different node? (default `False`) :arg send_get_body_as: for GET requests with body this option allows you to specify an alternate way of execution for environments that don't support passing bodies with GET requests. If you set this to 'POST' a POST method will be used instead, if to 'source' then the body will be serialized and passed as a query parameter `source`. Any extra keyword arguments will be passed to the `connection_class` when creating and instance unless overridden by that connection's options provided as part of the hosts parameter. N(RtcopytmimetypetupdateRt deserializert max_retriestretry_on_timeouttretry_on_statustsend_get_body_ast serializertconnection_pool_classtconnection_classtkwargsthoststset_connectionstconnection_poolt connectionstseed_connectionstsniffer_timeouttsniff_on_connection_failttimet last_snifft sniff_timeoutthost_info_callbackt sniff_hoststTrue(tselfR RRR*tsniff_on_startR%R)R&Rt serializerstdefault_mimetypeRRRRRt _serializers((sr/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-W9yz6j/elasticsearch/elasticsearch/transport.pyt__init__%s.-                cCs$|jj|ƒ|j|jƒdS(s¦ Create a new :class:`~elasticsearch.Connection` instance and add it to the pool. :arg host: kwargs that will be used to create the instance N(R tappendR!(R-R((sr/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-W9yz6j/elasticsearch/elasticsearch/transport.pytadd_connection|scss‡fd†}t||ƒ}tt||ƒƒ}t|ƒdkrWt|ƒˆ_nˆj|ˆjˆ_dS(sù Instantiate all the connections and crate new connection pool to hold them. Tries to identify unchanged hosts and re-use existing :class:`~elasticsearch.Connection` instances. :arg hosts: same as `__init__` cshtˆdƒr?x-ˆjjD]\}}||kr|SqWnˆjjƒ}|j|ƒˆj|S(NR"(thasattrR"tconnection_optsRRRR(Rt connectiontold_hostR(R-(sr/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-W9yz6j/elasticsearch/elasticsearch/transport.pyt_create_connectionŽs   iN(tmaptlisttziptlenRR"RR(R-R R9R#((R-sr/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-W9yz6j/elasticsearch/elasticsearch/transport.pyR!…s  cCsB|jr5tjƒ|j|jkr5|jƒq5n|jjƒS(sŠ Retreive a :class:`~elasticsearch.Connection` instance from the :class:`~elasticsearch.ConnectionPool` instance. (R%R'R(R+R"tget_connection(R-((sr/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-W9yz6j/elasticsearch/elasticsearch/transport.pyR>¤s cCså|j}y²tjƒ|_xœt|jj|jƒD]s}yS|jddd|s[|jndƒ\}}}|j j ||j dƒƒ}PWq4t t fk r¦q4Xq4Wtddƒ‚Wn||_‚nXt|djƒƒS( s¹ Perform the request to get sniffins information. Returns a list of dictionaries (one per node) containing all the information from the cluster. It also sets the last_sniff attribute in case of a successful attempt. In rare cases it might be possible to override this method in your custom Transport class to serve data from alternative source like configuration management. Rs/_nodes/_all/httpttimeouts content-typesN/AsUnable to sniff hosts.tnodesN(R(R'RR"R#R$tperform_requestR)RRtloadsR RR RR;tvalues(R-tinitialtprevious_snifftct_theadersR((sr/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-W9yz6j/elasticsearch/elasticsearch/transport.pyt_get_sniff_data®s"  ! cCs|i}|jdiƒjdƒ}| s4d|kr8dS|jddƒ\|d<|díssN/As.Unable to sniff hosts - no viable hosts found.N(RIR;tfilterRRR!(R-RDRR ((R-sr/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-W9yz6j/elasticsearch/elasticsearch/transport.pyR+ás %cCs*|jj|ƒ|jr&|jƒndS(sô Mark a connection as dead (failed) in the connection pool. If sniffing on failure is enabled this will initiate the sniffing process. :arg connection: instance of :class:`~elasticsearch.Connection` that failed N(R"t mark_deadR&R+(R-R7((sr/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-W9yz6j/elasticsearch/elasticsearch/transport.pyRVös c Csœ|dk rŽ|jj|ƒ}|dkrŽ|jdkrŽ|jdkrQd}q‹|jdkr‹|dkrui}n||dRARt status_codetFalseR RRR,RRVR"t mark_liveRRBR (R-tmethodturlRHtparamstbodyR\R?tattemptR7tstatustheaders_responsetdatatetretry((sr/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-W9yz6j/elasticsearch/elasticsearch/transport.pyRAs^       7      !cCs|jjƒdS(s. Explcitly closes connections N(R"tclose(R-((sr/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-W9yz6j/elasticsearch/elasticsearch/transport.pyRq\sN(iöi÷iø(t__name__t __module__t__doc__RRRReRRR2R4R!R>RIRRR+RVRARq(((sr/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-W9yz6j/elasticsearch/elasticsearch/transport.pyRs    R  &  Z(R't itertoolsRR7RR"RRRRRRt exceptionsRRR R RtobjectR(((sr/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-W9yz6j/elasticsearch/elasticsearch/transport.pyts "