Your IP : 216.73.216.172


Current Path : /lib/python3/dist-packages/certbot/plugins/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/certbot/plugins/__pycache__/storage.cpython-38.pyc

U

�]��@sfdZddlZddlZddlmZmZddlmZddlm	Z	ddlm
Z
e�e�Z
Gdd�de�ZdS)	zPlugin storage class.�N)�Any�Dict)�errors)�os)�
filesystemc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�
PluginStoragez4Class implementing storage functionality for pluginscCs"||_||_d|_d|_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�_data�_storagepath)�selfZconfigZclasskey�r�9/usr/lib/python3/dist-packages/certbot/plugins/storage.py�__init__s
	zPluginStorage.__init__cCs&tj�|jjd�|_|��d|_dS)zhInitializes PluginStorage data and reads current state from the disk
        if the storage json exists.z.pluginstorage.jsonTN)r�path�joinrZ
config_dirr�_loadr
)r
rrr�_initialize_storage sz!PluginStorage._initialize_storagec
Cs�t�}d}z$t|jd��}|��}W5QRXWnVtk
r�}z8d�|jt|��}tj�	|j�rtt
�|�t�
|��W5d}~XYnXzt�|�}WnHtk
r�|s�t
�d|j�n d�|j�}t
�|�t�
|��YnX||_dS)z�Reads PluginStorage content from the disk to a dict structure

        :raises .errors.PluginStorageError: when unable to open or read the file
        ��rz1Could not read PluginStorage data file: {0} : {1}Nz2Plugin storage file %s was empty, no values loadedz$PluginStorage file {0} is corrupted.)�dict�openr�read�IOError�format�strrr�isfile�logger�errorr�PluginStorageError�json�loads�
ValueError�debugr)r
�dataZfiledata�fh�e�errmsgrrrr(s4�
��
zPluginStorage._loadc
Cs|jsd}t�|�t�|��zt�|j�}WnDtk
rr}z&d�	t
|��}t�|�t�|��W5d}~XYnXz@t�t
�|jtjtjBtjBd�d��}|�|�W5QRXWnHtk
r�}z*d�	|jt
|��}t�|�t�|��W5d}~XYnXdS)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})r
rrrr r!�dumpsr�	TypeErrorrrr�fdopenrrr�O_WRONLY�O_CREAT�O_TRUNC�writer)r
r(Z
serializedr'r&rrr�saveFs:

�
���
zPluginStorage.savecCs@|js|��|j|j��kr,t�|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)r
rr	r�keysr)r
�key�valuerrr�putds
zPluginStorage.putcCs|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
        )r
rrr	)r
r3rrr�fetchqszPluginStorage.fetchN)
�__name__�
__module__�__qualname__�__doc__rrrr1r5r6rrrrrs
r)r:r!ZloggingZacme.magic_typingrrZcertbotrZcertbot.compatrrZ	getLoggerr7r�objectrrrrr�<module>s