M/edZddlZddlZddlmZddlmZddlmZddlmZddl m Z ddl m Z eje ZGd d Zy) zPlugin storage class.N)Any)Dict) configuration)errors) filesystem)oscteZdZdZdej deddfdZddZddZ dd Z d ed e ddfd Z d ede fd Z y) PluginStoragez4Class implementing storage functionality for pluginsconfigclasskeyreturnNc6||_||_d|_||y)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 s 9/usr/lib/python3/dist-packages/certbot/plugins/storage.py__init__zPluginStorage.__init__s  !!  ctjj|jjd|_|j d|_y)zhInitializes PluginStorage data and reads current state from the disk if the storage json exists.z.pluginstorage.jsonTN)rpathjoinr config_dir _storagepath_loadr)rs r_initialize_storagez!PluginStorage._initialize_storage!s7GGLL)@)@BWX  rci}d} t|jd5}|j}ddd tj|}||_y#1swY'xYw#t$r}dj |jt |}t jj|jr*tj|tj|Yd}~d}~wwxYw#t$rr|s!tj!d|jnEdj |j}tj|tj|Y||_ywxYw)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.)openrreadIOErrorformatstrrrisfileloggererrorrPluginStorageErrorjsonloads ValueErrordebug_data)rdatafiledatafheerrmsgs rrzPluginStorage._load)s9 " 8d''- %779 % 8::h'D ) % % 8HOO!!3q6+Fww~~d//0 V$//771 8 8 Q!..0@FF%%' V$//77 0  8s@AAAC-AA C*(A8C%%C*-A1E('E(c6|js,d}tj|tj| t j |j} tjtj|jtj tj"ztj$zdd5}|j'|dddy#t$rI}djt|}tj|tj|d}~wwxYw#1swYyxYw#t($rT}dj|jt|}tj|tj|d}~wwxYw)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- TypeErrorr#r$rfdopenrr rO_WRONLYO_CREATO_TRUNCwriter")rr2 serializedr1r0s rsavezPluginStorage.saveGsJ   RF LL ++F3 3 4DJJ/J 4:??%%KK"**,rzz9 ! %%'$  % %  4BIIAF LL ++F3 3  4  % %  4KRR!!3q6+F LL ++F3 3  4sPCA%D;?D/D; D,#AD''D,/D84D;8D;; FAFFkeyvaluec|js|j|j|jvri|j|j<||j|j|<y)zPut configuration value to PluginStorage :param str key: Key to store the value to :param value: Data to store N)rrrr-)rr>r?s rputzPluginStorage.putesR    $ $ & >> +)+DJJt~~ &*/ 4>>"3'rcr|js|j|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)rr>s rfetchzPluginStorage.fetchrs1   $ $ &zz$..)#..r)r N)__name__ __module__ __qualname____doc__rNamespaceConfigr$rrrr=rrArCrrr r sb> }<<  PT !<4< 0s 03 04 0 / / /rr )rGr)loggingtypingrrcertbotrrcertbot.compatrr getLoggerrDr&r rIrrrOs> !%   8 $m/m/r