a }|g@sxdZddlZddlZddlmZddlmZddlmZddlmZddl m Z ddl m Z e e ZGd d d ZdS) zPlugin storage class.N)Any)Dict) configuration)errors) filesystem)osc@speZdZdZejeddddZddddZddd d Z ddd d Z ee dd ddZ ee dddZ dS) PluginStoragez4Class implementing storage functionality for pluginsN)configclasskeyreturncCs||_||_d|_||dS)zInitializes 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__)r cCs&tj|jjd|_|d|_dS)zhInitializes PluginStorage data and reads current state from the disk if the storage json exists.z.pluginstorage.jsonTN)rpathjoinr Z config_dir _storagepath_loadr)rrrr_initialize_storage!sz!PluginStorage._initialize_storagec Csi}d}z8t|jd}|}Wdn1s40YWnXty}z@d|jt|}tj|jrt |t |WYd}~n d}~00zt |}WnFty|st d|jn d|j}t |t |Yn0||_dS)zReads 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.)openrreadOSErrorformatstrrrisfileloggererrorrPluginStorageErrorjsonloads ValueErrordebug_data)rdataZfiledatafheerrmsgrrrr)s2*     zPluginStorage._loadc Cs|jsd}t|t|zt|j}WnFtyt}z.d t |}t|t|WYd}~n d}~00zTt t |jt jt jBt jBdd}||Wdn1s0YWnLty}z2d |jt |}t|t|WYd}~n d}~00dS)zSaves 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}Niwz4Could not write PluginStorage data to file {0} : {1})rr r!rr"r#dumpsr' TypeErrorrrrfdopenrrrO_WRONLYO_CREATO_TRUNCwriter)rr+Z serializedr*r)rrrsaveGs8    ,  zPluginStorage.save)keyvaluer cCs:|js||j|jvr&i|j|j<||j|j|<dS)zPut configuration value to PluginStorage :param str key: Key to store the value to :param value: Data to store N)rrr r')rr5r6rrrputes   zPluginStorage.put)r5r cCs|js||j|j|S)zGet 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 )rr5rrrfetchrszPluginStorage.fetch)__name__ __module__ __qualname____doc__rZNamespaceConfigrrrrr4rr7r8rrrrrs r)r<r#ZloggingtypingrrZcertbotrrZcertbot.compatrrZ getLoggerr9r rrrrrs