ok

Mini Shell

Direktori : /lib/python3.6/site-packages/certbot/plugins/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/certbot/plugins/__pycache__/storage.cpython-36.pyc

3

گa��@sxdZddlZddlZddlmZddlmZddlmZddlmZddl	m
Z
ddl	mZej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.6/storage.py�__init__s
	zPluginStorage.__init__)rcCs&tjj|jjd�|_|j�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_storagecCs�i}d}y$t|jd��}|j�}WdQRXWnVtk
r�}z:dj|jt|��}tjj|j�rrt	j
|�tj|��WYdd}~XnXyt
j|�}WnHtk
r�|s�t	jd|j�n dj|j�}t	j
|�tj|��YnX||_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�IOError�format�strrr�isfile�logger�errorr�PluginStorageError�json�loads�
ValueError�debug�_data)r�dataZfiledata�fh�e�errmsgrrrr)s,


zPluginStorage._loadcCs|jsd}tj|�tj|��ytj|j�}WnDtk
rr}z(dj	t
|��}tj|�tj|��WYdd}~XnXy@tjt
j|jtjtjBtjBd�d��}|j|�WdQRXWnHtk
r�}z,dj	|jt
|��}tj|�tj|��WYdd}~XnXdS)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�saveGs,




zPluginStorage.save)�key�valuercCs:|js|j�|j|jkr&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|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#ZloggingZtypingrrZcertbotrrZcertbot.compatrrZ	getLoggerr9r rrrrr�<module>s


Zerion Mini Shell 1.0