o
    gZh:                     @   s
  U d dl Z d dlZd dlZd dlmZmZ d dlmZ d dlmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZ d dlmZmZmZmZmZmZ d dlmZm Z m!Z!m"Z"m#Z#m$Z$ ddl%m&Z& dd	l'm(Z(m)Z)m*Z* erud
dl+m,Z, dddg dfZ-ee	 e.d< de e&fZ/e!de&Z0ee1eee1ee1ee1e2f f ef  f Z3eeege
ee  f Z4eeegee f Z5h dZ6edede	f dZ7	d?dee3 dee1 dee	 de	dee f
ddZ8de3dee fddZ9dee1ee1e2f f defd d!Z:de1dee fd"d#Z;d$ee1ee1 ee1e1f f de1fd%d&Z<d'e	de1fd(d)Z=d'e	de1fd*d+Z>d,ee1e	f de1fd-d.Z?dee1e	f d/ee1e	f ddfd0d1Z@		2		d@d3ee1 d4eAd5eee1e1f  d6eee1  dee7ge7f f
d7d8ZBd9e	deAfd:d;ZCd<e	deAfd=d>ZDdS )A    N)datedatetime)wraps)TYPE_CHECKINGAny	AwaitableCallable
CollectionDictListMappingOptionalSequenceSetTupleTypeTypeVarUnion)AsyncTransportHttpHeaders
NodeConfigRequestsHttpNodeSniffOptions	Transport)DEFAULTclient_meta_versioncreate_user_agentparse_cloud_idpercent_encodeurl_to_node_config   )__versionstr__)to_bytesto_strwarn_stacklevel   )NamespacedClient      SKIP_IN_PATHeszelasticsearch-py>   Z	opaque_idZapi_keyrequest_timeoutignoreheaders	http_authF.)boundhostscloud_idrequests_session_authkwargsreturnc                    s   |d ur| d urt dt|}n
| d usJ t| }dd | D tdd}|dt |d< |d urB|di d< d	td
tffdd  fdd|D S )Nz<The 'cloud_id' and 'hosts' parameters are mutually exclusivec                 S   s   i | ]\}}|t ur||qS r)   )r   .0kvr)   r)   W/var/www/html/lang_env/lib/python3.10/site-packages/elasticsearch/_sync/client/utils.py
<dictcomp>o   s    z'client_node_configs.<locals>.<dictcomp>r.   r)   
user-agent_extraszrequests.session.authnode_configr6   c                    sP   | j  } dd}|r|| |dt |  | d< | jdi  S )zMNeeds special handling of headers since .replace() wipes out existing headersr.   r)   r=   )r.   copypopupdate
setdefault
USER_AGENTfreezereplace)r?   r.   Zheaders_to_add)node_optionsr)   r;   apply_node_options|   s   

z/client_node_configs.<locals>.apply_node_optionsc                    s   g | ]} |qS r)   r)   )r8   r?   )rH   r)   r;   
<listcomp>       z'client_node_configs.<locals>.<listcomp>)	
ValueErrorcloud_id_to_node_configshosts_to_node_configsitemsr   rA   rC   rD   r   )r2   r3   r4   r5   node_configsr.   r)   )rH   rG   r;   client_node_configs^   s&   

rP   c                 C   sv   t | tr
t| gS g }| D ]*}t |tr|| qt |tr(|t| qt |tr5|t| qtd|S )z7Transforms the many formats of 'hosts' into NodeConfigsz<'hosts' must be a list of URLs, NodeConfigs, or dictionaries)	
isinstancestrrM   r   appendr   r   host_mapping_to_node_configrK   )r2   rO   hostr)   r)   r;   rM      s   




rM   rU   c                 C   s  h d}t |  |}|r(dt|}dt|}td| d| dt| }d|v rj|d}t|t	s>t
dd|v rW|d d	k|krWtd
|d  d| dtjdtt d |d|rgd	nd d|v rd|v rvtdtjdtt d |d|d< tdi |S )zCConverts an old-style dictionary host specification to a NodeConfig>   use_sslschemeportrU   
url_prefixpath_prefixz', 'zCan't specify the options 'z%' via a dictionary in 'hosts', only 'z' options are allowedrV   z 'use_ssl' must be of type 'bool'rW   httpsz+Cannot specify conflicting options 'scheme=z' and 'use_ssl=z'. Use 'scheme' only insteadzQThe 'use_ssl' option is no longer needed as specifying a 'scheme' is now requiredcategory
stacklevelhttprY   rZ   zaCannot specify conflicting options 'url_prefix' and 'path_prefix'. Use 'path_prefix' only insteadz?The 'url_prefix' option is deprecated in favor of 'path_prefix'Nr)   )setkeys
differencejoinsortedrK   dictrA   rQ   bool	TypeErrorwarningswarnDeprecationWarningr$   rC   r   )rU   Zallow_hosts_keysZdisallowed_keysZbad_keys_usedZallowed_keysoptionsrV   r)   r)   r;   rT      sN   

rT   c                 C   s<   t | j}|du st|std|\}}td||ddgS )z0Transforms an Elastic Cloud ID into a NodeConfigNz<Cloud ID missing host and port information for Elasticsearchr[   T)rW   rU   rX   Zhttp_compress)r   Z
es_addressallrK   r   )r3   Zes_addrrU   rX   r)   r)   r;   rL      s   
rL   
auth_valuec                 C   s0   t | ttfrttd| dS t| S )zTakes either a 2-tuple or a base64-encoded string
    and returns a base64-encoded string to be used
    as an HTTP authorization header.
    :ascii)	rQ   listtuplebase64	b64encoder"   rc   decoder#   )rm   r)   r)   r;   _base64_auth_header   s   ru   valuec                 C   s   t | ttfrddd | D } n#t | ttfr|  } nt | tr*t| 	 } nt | t
r5| ddS t | ts>t| S | S )z
    Escape a single value of a URL string or a query parameter. If it is a list
    or tuple, turn it into a comma-separated string first.
    ,c                 S   s   g | ]}t |qS r)   )_escape)r8   itemr)   r)   r;   rI     rJ   z_escape.<locals>.<listcomp>zutf-8surrogatepass)rQ   rp   rq   rc   r   r   	isoformatrf   rR   lowerbytesrt   rv   r)   r)   r;   rx      s   



rx   c                 C   s   t t| dS )Nz,*)r   rx   r~   r)   r)   r;   _quote  s   r   queryc                 C   s   d dd |  D S )N&c                 S   s"   g | ]\}}| d t | qS )=)r   r7   r)   r)   r;   rI     s   " z _quote_query.<locals>.<listcomp>)rc   rN   )r   r)   r)   r;   _quote_query  s   r   valuesc                 C   s6   |  D ]\}}|| v rtd| d|| |< qd S )NzReceived multiple values for 'zB', specify parameters directly instead of using 'body' or 'params')rN   rK   )r5   r   keyvalr)   r)   r;   _merge_kwargs_no_duplicates  s   

r   F	body_namebody_fieldsparameter_aliasesignore_deprecated_optionsc                    s    dt dt f fdd}|S )Napir6   c                    s.   t  dtdtdtf fdd}|S )Nargsr5   r6   c               	      s  t | dkr
tdd|v r2rdvr2|d}|r2t|ds$tdtjdtt d t	|| t
|}|ri }|D ]#}rF|v rFq=z|}|dkrOd	}||||< W q= ty`   Y q=w |rtjd
tt d | d }d }t|dr~t|}|j}|jdi |}|d ur||}|f| dd   } d|v rӈrdvr|d}	|	d urӈrÈ|v rtd d d d|	|< nrt|	dstdt	||	 r D ]\}
}z	||
||< W q ty   Y qw  | i |S )N   zfPositional arguments can't be used with Elasticsearch API methods. Instead only use keyword arguments.paramsrN   z}Couldn't merge 'params' with other parameters as it wasn't a mapping. Instead of using 'params' use individual API parameterszpThe 'params' parameter is deprecated and will be removed in a future version. Instead use individual parameters.r\   r-   Zignore_statuszaPassing transport options in the API method is deprecated. Use 'Elasticsearch.options()' instead.r   _clientr%   bodyzCan't use 'z*' and 'body' parameters together because 'z;' is an alias for 'body'. Instead you should only use the 'z]' parameter. See https://github.com/elastic/elasticsearch-py/issues/1698 for more informationzyCouldn't merge 'body' with other parameters as it wasn't a mapping. Instead of using 'body' use individual API parametersr)   )lenrg   rA   hasattrrK   rh   ri   rj   r$   r   _TRANSPORT_OPTIONSintersectionKeyErrortyper   rk   rN   )r   r5   r   Zmaybe_transport_optionsZtransport_optionsoptionZoption_renameclientZnamespaced_clientr   aliasZ	rename_to)r   r   r   r   r   r)   r;   wrapped0  s   








z5_rewrite_parameters.<locals>.wrapper.<locals>.wrapped)r   r   )r   r   r   r   r   r   )r   r;   wrapper/  s   $cz$_rewrite_parameters.<locals>.wrapper)r0   )r   r   r   r   r   r)   r   r;   _rewrite_parameters)  s   gr   r/   c                 C   s.   zddl m} t| |W S  ty   Y dS w )z=Detect if an http_auth value is a custom Requests auth objectr   )AuthBaseF)Zrequests.authr   rQ   ImportError)r/   r   r)   r)   r;   is_requests_http_auth  s   r   
node_classc                 C   s,   | duo| t uo| dkpt| ot| tS )zLDetect if 'RequestsHttpNode' would be used given the setting of 'node_class'Nrequests)r   inspectisclass
issubclassr   )r   r)   r)   r;   is_requests_node_class  s   r   )N)NFNN)Err   r   rh   r   r   	functoolsr   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   Zelastic_transportr   r   r   r   r   r   Zelastic_transport.client_utilsr   r   r   r   r   r   _versionr!   compatr"   r#   r$   _baser&   r*   __annotations__ZCLIENT_META_SERVICErD   rR   intZ_TYPE_HOSTSZ_TYPE_ASYNC_SNIFF_CALLBACKZ_TYPE_SYNC_SNIFF_CALLBACKr   r0   rP   rM   rT   rL   ru   rx   r   r   r   rf   r   r   r   r)   r)   r)   r;   <module>   sz   
D  	
$	
/"=(
&

p