HEX
Server: LiteSpeed
System: Linux ws4.angoweb.net 5.14.0-611.13.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 11 04:57:59 EST 2025 x86_64
User: tswangoe (2287)
PHP: 8.1.33
Disabled: show_source, system, shell_exec, passthru, exec, phpinfo, popen, proc_open
Upload Files
File: //lib/python3.9/site-packages/certbot/plugins/__pycache__/storage.cpython-39.pyc
a

}|�g��@sxdZddlZddlZddlmZddlmZddlmZddlmZddl	m
Z
ddl	mZe�e
�ZGd	d
�d
�ZdS)zPlugin storage class.�N)�Any)�Dict)�
configuration)�errors)�
filesystem)�osc@speZdZdZejedd�dd�Zdd�dd�Zdd�d	d
�Z	dd�dd�Z
eedd
�dd�Zeed�dd�Z
dS)�
PluginStoragez4Class implementing storage functionality for pluginsN)�config�classkey�returncCs||_||_d|_||dS)z�Initializes PluginStorage object storing required configuration
        options.

        :param .configuration.NamespaceConfig config: Configuration object
        :param str classkey: class name to use as root key in storage file

        FN)�_config�	_classkey�_initialized)�selfr	r
�r�;/usr/lib/python3.9/site-packages/certbot/plugins/storage.py�__init__s
	zPluginStorage.__init__)rcCs&tj�|jjd�|_|��d|_dS)zhInitializes PluginStorage data and reads current state from the disk
        if the storage json exists.z.pluginstorage.jsonTN)r�path�joinrZ
config_dir�_storagepath�_loadr)rrrr�_initialize_storage!sz!PluginStorage._initialize_storagec
Cs�i}d}z8t|jd��}|��}Wd�n1s40YWnXty�}z@d�|jt|��}tj�|j�r�t	�
|�t�|��WYd}~n
d}~00zt
�|�}WnFty�|s�t	�d|j�n d�|j�}t	�
|�t�|��Yn0||_dS)z�Reads PluginStorage content from the disk to a dict structure

        :raises .errors.PluginStorageError: when unable to open or read the file
        ��rNz1Could not read PluginStorage data file: {0} : {1}z2Plugin storage file %s was empty, no values loadedz$PluginStorage file {0} is corrupted.)�openr�read�OSError�format�strrr�isfile�logger�errorr�PluginStorageError�json�loads�
ValueError�debug�_data)r�dataZfiledata�fh�e�errmsgrrrr)s2*
�
 ��
zPluginStorage._loadc
Cs|jsd}t�|�t�|��zt�|j�}WnFtyt}z.d�	t
|��}t�|�t�|��WYd}~n
d}~00zTt�t
�|jtjtjBtjBd�d��}|�|�Wd�n1s�0YWnLt�y}z2d�	|jt
|��}t�|�t�|��WYd}~n
d}~00dS)z�Saves PluginStorage content to disk

        :raises .errors.PluginStorageError: when unable to serialize the data
            or write it to the filesystem
        z;Unable to save, no values have been added to PluginStorage.z+Could not serialize PluginStorage data: {0}Ni��wz4Could not write PluginStorage data to file {0} : {1})rr r!rr"r#�dumpsr'�	TypeErrorrrr�fdopenrrr�O_WRONLY�O_CREAT�O_TRUNC�writer)rr+Z
serializedr*r)rrr�saveGs8

�
 ��,
�
zPluginStorage.save)�key�valuercCs:|js|��|j|jvr&i|j|j<||j|j|<dS)z�Put configuration value to PluginStorage

        :param str key: Key to store the value to
        :param value: Data to store
        N)rrr
r')rr5r6rrr�putes
zPluginStorage.put)r5rcCs|js|��|j|j|S)z�Get configuration value from PluginStorage

        :param str key: Key to get value from the storage

        :raises KeyError: If the key doesn't exist in the storage
        )rrr'r
)rr5rrr�fetchrszPluginStorage.fetch)�__name__�
__module__�__qualname__�__doc__rZNamespaceConfigrrrrr4rr7r8rrrrrs
r)r<r#Zlogging�typingrrZcertbotrrZcertbot.compatrrZ	getLoggerr9r rrrrr�<module>s