HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.60.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 5 05:00:59 EST 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //var/opt/nydus/ops/primordial/__pycache__/zkconfig.cpython-39.pyc
a

�,�hw�@s�ddlZddlZddlmZddlmZddlmZddlm	Z	m
Z
mZddlm
Z
ddlmZddlmZGd	d
�d
e�ZdS)�N)�deque)�Any)�KazooClient)�ConnectionLoss�NoNodeError�ZookeeperError)�KazooTimeoutError)�Config)�
retry_thisc@s�eZdZdZdZe�d�Zedd�dd�Z	dd	�Z
d
d�Zee
eejeefd�d
d��Zdd�Zdd�Zdeeed�dd�ZdS)�ZKConfigzFConfig class that loads configuration options from a ZooKeeper clusterz/configz\s*(\S+?)\s*=\s*(\S+)\s*N)�hosts�returncCs t|dd�|_i|_|��dS)NT)rZ	read_only)r�_client�_config�load_config)�selfr�r�D/opt/nydus/tmp/pip-target-wkfpz8uv/lib/python/primordial/zkconfig.py�__init__szZKConfig.__init__cCs|j��|jS)z�
        This turns this class/object into a context manager for connections to the zookeeper cluster.
        This starts up the connection and returns the client as the resource being managed.
        )r�start)rrrr�	__enter__s
zZKConfig.__enter__cCs0z|j��|j��Wnty*Yn0dS)ze
        This method takes care of releasing the client connection to the zookeeper cluster.
        N)r�stop�close�	Exception)rZ	_exc_typeZ_exc_valZ_exc_tbrrr�__exit__&s

zZKConfig.__exit__)Z
on_ex_classescCsL|�4}|�|�D]}|j�|�||��qWd�n1s>0YdS)z�
        Load HFS config data including config at the various namespaces and flatten it out into
        a dict representation.
        N)�	enumerater�update�get_config_at_path)r�	zk_client�pathrrrr1szZKConfig.load_configccsJt|jg�}|rF|��}|V|�|�D]}d�||�}|�|�q(qdS)z�
        Generate all child paths, starting at a particular path. The starting path is also
        included in this enumeration.
        z{}/{}N)r�ROOT�popleftZget_children�format�append)rrZpaths_to_traverser�childZ
child_pathrrrr<szZKConfig.enumeratec
Csvi}|�d�dd�}|�|�\}}|�d�}|�d�D]8}|j�|�}	|	r8|	��\}
}d�||
g�}|||<q8|S)a,
        Get the data (which is interpreted as config uploaded to that path/namespace) at a particular
        zookeeper path. Parse out the data looking for lines that look like key=value.
        Generate a dict out of this normalizing the key appropriately. Finally return back this dict.
        �/�Nzutf-8�
�.)�split�get�decode�CONFIG_LINE�match�groups�join)
rrr�configZ
path_sectionsZzk_valueZ_zk_statZ
stored_config�liner-�k�vZ
config_keyrrrrKs

zZKConfig.get_config_at_path)�key�defaultr
cCs|j�||�S)z�
        Get the config option as a string

        :param key: config option name
        :param default: default value if no value exists in the config
        :return: option value
        )rr*)rr4r5rrrr*cszZKConfig.get)N)�__name__�
__module__�__qualname__�__doc__r �re�compiler,�strrrrr
rr�socket�errorrrrrrrr*rrrrrs

�
	r)r:r=�collectionsr�typingrZkazoo.clientrZkazoo.exceptionsrrrZkazoo.handlers.threadingrZprimordial.configr	Zprimordial.utilsr
rrrrr�<module>s