o
    eZh                      @   s  d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlm	Z	m
Z
mZmZ d dlmZ d dlmZ d dlmZ ddlmZmZmZ dd	lmZ dd
lmZ g dZedZdeeef dedefddZdededefddZdedefddZ ej!dddG dd dZ"dede"fddZ#	 d6d!eee$f d"ed#edefd$d%Z%	 d6d!eee$f d"ed#ede$fd&d'Z&e'd(Z(	)		d7d*ee$ef d+ed"e	e d#e	e def
d,d-Z)d.e
eef defd/d0Z*	1d8d2ed3e+defd4d5Z,ee-e.  [dS )9    N)python_version)OptionalTupleTypeVarUnion)quote)LocationParseError)	parse_url   )DEFAULTDefaultType
NodeConfig)fixup_module_metadata)__version__)CloudIdr   r   basic_auth_to_headerclient_meta_versioncreate_user_agentdataclassesparse_cloud_idpercent_encoderesolve_defaultto_bytesto_strurl_to_node_configTvaldefaultreturnc                 C   s   | t ur| S |S )zrResolves a value that could be the ``DEFAULT`` sentinel
    into either the given value or the default value.
    )r   )r   r    r   U/var/www/html/lang_env/lib/python3.10/site-packages/elastic_transport/client_utils.pyr   5   s   r   nameversionc                 C   s   |  d| dt   dt dS )zBCreates the 'User-Agent' header given the library name and version/z	 (Python/z; elastic-transport/))r   r   )r!   r"   r   r   r    r   <   s   r   c                 C   sH   t d| }|du rtd| \} }t d|r| S |r"| d7 } | S )zsConverts a Python version into a version string
    compatible with the ``X-Elastic-Client-Meta`` HTTP header.
    z^([0-9][0-9.]*[0-9]|[0-9])(.*)$Nz>Version {version!r} not formatted like a Python version stringz^\.post[0-9]*$p)rematch
ValueErrorgroupssearch)r"   r'   Zversion_suffixr   r   r    r   C   s   r   T)frozenreprc                   @   s>   e Zd ZU eed< eeeef  ed< eeeef  ed< dS )r   cluster_name
es_addresskibana_addressN)__name__
__module____qualname__str__annotations__r   r   intr   r   r   r    r   V   s   
 r   cloud_idc              
   C   s2  z^t | } | d\}}} t tt| ddd}|d }|s$t z|d }W n ty5   d}Y nw z|d p<d}W n tyI   d}Y nw d|v r[|d\}}}t	|}nd}W n ttt
fym   td	dw |rw| d
| nd}	|r| d
| nd}
t||	r|	|fnd|
r|
|fdS ddS )z.Parses an Elastic Cloud ID into its components:ascii$r   r
   N     z"Cloud ID is not properly formatted.)r-   r.   r/   )r   	partitionbinascii
a2b_base64r   splitr(   
IndexError
rpartitionr5   UnicodeErrorr   )r6   r-   _partsZ	parent_dnZes_uuidZkibana_uuidZparent_portportZes_hostZkibana_hostr   r   r    r   `   sH   


r   utf-8strictvalueencodingerrorsc                 C      t | tr| ||S | S N)
isinstancebytesdecoderI   rJ   rK   r   r   r    r         
r   c                 C   rL   rM   )rN   r3   encoderQ   r   r   r    r      rR   r   zBABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-~r#   stringsafec                 C   s$   d tt|}t| |||dS )zDPercent-encodes a string so it can be used in an HTTP request target )rJ   rK   )join_QUOTE_ALWAYS_SAFEunionset_quote)rT   rU   rJ   rK   r   r   r    r      s   	r   
basic_authc                 C   sT   t | trt| dkstdd | D rtddtddd | D   S )z;Converts a 2-tuple into a 'Basic' HTTP Authorization headerr:   c                 s   s     | ]}t |ttf V  qd S rM   )rN   r3   rO   ).0itemr   r   r    	<genexpr>   s    z'basic_auth_to_header.<locals>.<genexpr>z@'basic_auth' must be a 2-tuple of str/bytes (username, password)zBasic    :c                 s   s    | ]}t |V  qd S rM   )r   )r]   xr   r   r    r_      s    )	rN   tuplelenanyr(   base64	b64encoderW   rP   )r\   r   r   r    r      s   $r   Furluse_default_ports_for_schemec                 C   s4  zt | }W n ty   td| dw |j}|jdu r4|jdur4|jdkr+d}n	|jdkr4|r4d}tdd |j|j|fD rFtd	|jdusMJ |jdusTJ |dusZJ i }|jr||jd
\}}}t	j
|}t	j
|}	t||	f|d< |jd}
|jr|jdkrd}n|j}t|j|
|||dS )al  Constructs a :class:`elastic_transport.NodeConfig` instance from a URL.
    If a username/password are specified in the URL they are converted to an
    'Authorization' header. Always fills in a default port for HTTPS.

    :param url: URL to transform into a NodeConfig.
    :param use_default_ports_for_scheme: If 'True' will resolve default ports for HTTP.
    zCould not parse URL Nhttpsr;   httpP   c                 s   s    | ]}|d v V  qdS ))NrV   Nr   )r]   	componentr   r   r    r_      s
    
z%url_to_node_config.<locals>.<genexpr>zWURL must include a 'scheme', 'host', and 'port' component (ie 'https://localhost:9200')r7   authorizationz[]r#   rV   )schemehostrF   path_prefixheaders)r	   r   r(   rF   rn   rd   ro   authr=   urllibparseunquoter   strippathr   )rg   rh   
parsed_urlZparsed_portrq   Zencoded_usernamerD   Zencoded_passwordusernamepasswordro   rp   r   r   r    r      sJ   

r   )rG   rH   )r#   NN)F)/re   r>   r   r&   urllib.parsers   platformr   typingr   r   r   r   r   r[   Zurllib3.exceptionsr   Zurllib3.utilr	   Z_modelsr   r   r   _utilsr   _versionr   __all__r   r   r3   r   r   	dataclassr   r   rO   r   r   	frozensetrX   r   r   boolr   r0   globalsr   r   r   r    <module>   s   	*

	

	


=