Ë
    M/ÅeÆ  ã                   ó˜   — d Z ddlZddlZddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddl	mZ  ej                  e«      Z G d	„ d
«      Zy)zPlugin storage class.é    N)ÚAny)ÚDict)Úconfiguration)Úerrors)Ú
filesystem)Úosc                   ót   — e Zd ZdZdej
                  deddfd„Zdd„Zdd„Z	dd	„Z
d
ededdfd„Zd
edefd„Zy)ÚPluginStoragez4Class implementing storage functionality for pluginsÚconfigÚclasskeyÚreturnNc                 ó6   — || _         || _        d| _        |  |  y)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   s      ú9/usr/lib/python3/dist-packages/certbot/plugins/storage.pyÚ__init__zPluginStorage.__init__   s    € ð ˆŒØ!ˆŒØ!ˆÔÙÚó    c                 ó¤   — t         j                  j                  | j                  j                  d«      | _        | j                  «        d| _        y)zhInitializes PluginStorage data and reads current state from the disk
        if the storage json exists.z.pluginstorage.jsonTN)r   ÚpathÚjoinr   Ú
config_dirÚ_storagepathÚ_loadr   )r   s    r   Ú_initialize_storagez!PluginStorage._initialize_storage!   s7   € ô ŸG™GŸL™L¨¯©×)@Ñ)@ÐBWÓXˆÔØ�
‰
ŒØ ˆÕr   c                 óÖ  — i }d}	 t        | j                  d«      5 }|j                  «       }ddd«       	 t        j                  |«      }|| _        y# 1 sw Y   Œ'xY w# t        $ r‚}dj	                  | j                  t        |«      «      }t        j                  j                  | j                  «      r*t        j                  |«       t        j                  |«      ‚Y d}~Œ°d}~ww xY w# t        $ rr |s!t        j!                  d| j                  «       nEdj	                  | j                  «      }t        j                  |«       t        j                  |«      ‚Y || _        yw xY w)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Ústrr   r   ÚisfileÚloggerÚerrorr   ÚPluginStorageErrorÚjsonÚloadsÚ
ValueErrorÚdebugÚ_data)r   ÚdataÚfiledataÚfhÚeÚerrmsgs         r   r   zPluginStorage._load)   s9  € ð
  "ˆØˆð		8Ü�d×'Ñ'¨Ó-ð %°ØŸ7™7›9�÷%ð
	8Ü—:‘:˜hÓ'ˆDð ˆ�
÷)%ð %ûäò 	8ØH×OÑOØ×!Ñ!¤3 q£6ó+ˆFä�w‰w�~‰~˜d×/Ñ/Ô0ä—‘˜VÔ$Ü×/Ñ/°Ó7Ð7ô 1ûð	8ûô ò 	8ÙÜ—‘ÐQØ!×.Ñ.õ0ð @×FÑFØ×%Ñ%ó'�ä—‘˜VÔ$Ü×/Ñ/°Ó7Ð7ð0ð ˆ�
ð	8ús@   †A œA­A ¶C- ÁAÁA Á	C*Á(A8C%Ã%C*Ã-A1E(Å'E(c                 ó6  — | j                   s,d}t        j                  |«       t        j                  |«      ‚	 t        j                  | j                  «      }	 t        j                  t        j                  | j                  t        j                   t        j"                  z  t        j$                  z  d«      d«      5 }|j'                  |«       ddd«       y# t        $ rI}dj                  t        |«      «      }t        j                  |«       t        j                  |«      ‚d}~ww xY w# 1 sw Y   yxY w# t(        $ rT}dj                  | j                  t        |«      «      }t        j                  |«       t        j                  |«      ‚d}~ww xY w)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   r&   r'   r   r(   r)   Údumpsr-   Ú	TypeErrorr#   r$   r   Úfdopenr   r    r   ÚO_WRONLYÚO_CREATÚO_TRUNCÚwriter"   )r   r2   Ú
serializedr1   r0   s        r   ÚsavezPluginStorage.saveG   sJ  € ð × Ò ØRˆFÜ�L‰L˜Ô Ü×+Ñ+¨FÓ3Ð3ð	4ÜŸ™ D§J¡JÓ/ˆJð
	4Ü—‘œ:Ÿ?™?Ø×%Ñ%Ü—K‘K¤"§*¡*Ñ,¬r¯z©zÑ9Øóð  ó!ð %ð %'Ø—‘˜Ô$÷	%ð %øô ò 	4ØB×IÑIÜ�A“óˆFä�L‰L˜Ô Ü×+Ñ+¨FÓ3Ð3ûð		4ú÷%ð %ûô
 ò 	4ØK×RÑRØ×!Ñ!¤3 q£6ó+ˆFä�L‰L˜Ô Ü×+Ñ+¨FÓ3Ð3ûð		4úsP   ºC ÁA%D; Â?D/ÃD; Ã	D,Ã#AD'Ä'D,Ä/D8Ä4D; Ä8D; Ä;	FÅAFÆFÚkeyÚvaluec                 óÖ   — | j                   s| j                  «        | j                  | j                  vri | j                  | j                  <   || j                  | j                     |<   y)zˆPut configuration value to PluginStorage

        :param str key: Key to store the value to
        :param value: Data to store
        N)r   r   r   r-   )r   r>   r?   s      r   ÚputzPluginStorage.pute   sR   € ð × Ò Ø×$Ñ$Ô&à�>‰> §¡Ñ+Ø)+ˆD�J‰J�t—~‘~Ñ&Ø*/ˆ�
‰
�4—>‘>Ñ" 3Ò'r   c                 ór   — | j                   s| 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
        )r   r   r-   r   )r   r>   s     r   ÚfetchzPluginStorage.fetchr   s1   € ð × Ò Ø×$Ñ$Ô&à�z‰z˜$Ÿ.™.Ñ)¨#Ñ.Ð.r   )r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚNamespaceConfigr$   r   r   r   r=   r   rA   rC   © r   r   r
   r
      sb   „ Ù>ð˜}×<Ñ<ð Èð ÐPTó ó!óó<4ð<0�sð 0 3ð 0¨4ó 0ð
/˜ð 
/ ô 
/r   r
   )rG   r)   ÚloggingÚtypingr   r   Úcertbotr   r   Úcertbot.compatr   r   Ú	getLoggerrD   r&   r
   rI   r   r   ú<module>rO      s>   ðÙ Û Û Ý Ý å !Ý Ý %Ý à	ˆ×	Ñ	˜8Ó	$€÷m/ò m/r   