var/opt/nydus/ops/primordial/__pycache__/zkconfig.cpython-38.pyc000064400000007347147205575730020747 0ustar00U afw@sddlZddlZddlmZddlmZddlmZddlm Z m Z m Z ddl m Z ddlmZddlmZGd d d eZdS) N)deque)Any) KazooClient)ConnectionLoss NoNodeErrorZookeeperError)KazooTimeoutError)Config) retry_thisc@seZdZdZdZedZeddddZ dd Z d d Z e e eejeefd d dZddZddZdeeedddZdS)ZKConfigzFConfig class that loads configuration options from a ZooKeeper clusterz/configz\s*(\S+?)\s*=\s*(\S+)\s*N)hostsreturncCs t|dd|_i|_|dS)NT)r Z read_only)r_client_config load_config)selfr rD/opt/nydus/tmp/pip-target-53d1vnqk/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. )rstart)rrrr __enter__s zZKConfig.__enter__cCs2z|j|jWntk r,YnXdS)ze This method takes care of releasing the client connection to the zookeeper cluster. N)rstopclose Exception)rZ _exc_typeZ_exc_valZ_exc_tbrrr__exit__&s  zZKConfig.__exit__)Z on_ex_classesc Cs8|*}||D]}|j|||qW5QRXdS)z Load HFS config data including config at the various namespaces and flatten it out into a dict representation. N) enumeraterupdateget_config_at_path)r zk_clientpathrrrr1szZKConfig.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)rROOTpopleftZ get_childrenformatappend)rrZpaths_to_traverserchildZ child_pathrrrr<s  zZKConfig.enumeratec Csvi}|ddd}||\}}|d}|dD]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 .)splitgetdecode CONFIG_LINEmatchgroupsjoin) rrrconfigZ path_sectionsZzk_valueZ_zk_statZ stored_configliner-kvZ config_keyrrrrKs    zZKConfig.get_config_at_path)keydefaultr 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 recompiler,strrrrr rrsocketerrorrrrrrrr*rrrrr s    r )r:r= collectionsrtypingrZ kazoo.clientrZkazoo.exceptionsrrrZkazoo.handlers.threadingrZprimordial.configr Zprimordial.utilsr r rrrrs