File: //proc/self/root/usr/lib/python3/dist-packages/landscape/lib/__pycache__/persist.cpython-38.pyc
U
���cR � @ s� d dl Z d dlZd dlZd dlZd dlmZ ddddddd d
gZe� ZG dd � d e �Z
G dd
� d
e
�ZG d
d� de�ZG dd� de�Z
e�d�jZdd� Zdd� ZG dd� de�ZG dd� de�ZG dd� de�ZdS )� N)�
StringType�Persist�
PickleBackend�BPickleBackend�path_string_to_tuple�path_tuple_to_string�
RootedPersist�PersistError�PersistReadOnlyErrorc @ s e Zd ZdS )r N��__name__�
__module__�__qualname__� r r �7/usr/lib/python3/dist-packages/landscape/lib/persist.pyr % s c @ s e Zd ZdS )r
Nr r r r r r
) s c @ s� e Zd ZdZd(dd�Zdd� Zdd� Zd d
� Zeee�Z ee�Z
dd� Zd
d� Zdd� Z
d)dd�Zeefdd�Zd*dd�Zedddfdd�Zd+dd�Zd,dd�Zd-dd�Zd.d d!�Zeddfd"d#�Zd/d$d%�Zd&d'� ZdS )0r a Persist a hierarchical database of key=>value pairs.
There are three different kinds of option maps, regarding the
persistence and priority that maps are queried.
- hard - Options are persistent.
- soft - Options are not persistent, and have a higher priority
than persistent options.
- weak - Options are not persistent, and have a lower priority
than persistent options.
@ivar filename: The name of the file where persist data is saved
or None if no filename is available.
Nc C sd |dkrt � }|| _|�� | _i | _i | _d| _d| _| | _|| _ |dk r`t
j�|�r`| �
|� dS )a�
@param backend: The backend to use. If none is specified,
L{BPickleBackend} will be used.
@param filename: The default filename to save to and load from. If
specified, and the file exists, it will be immediately
loaded. Specifying this will also allow L{save} to be called
without any arguments to save the persist.
NF)r �_backend�new�_hardmap�_softmap�_weakmap� _readonly� _modifiedZ_config�filename�os�path�exists�load)�selfZbackendr r r r �__init__? s
zPersist.__init__c C s | j S �N)r �r r r r �
_get_readonlyU s zPersist._get_readonlyc C s t |�| _d S r )�boolr )r �flagr r r �
_set_readonlyX s zPersist._set_readonlyc C s | j S r �r r r r r �
_get_modified[ s zPersist._get_modifiedc C s
d| _ dS )z(Set the database status as non-modified.FNr% r r r r �reset_modifieda s zPersist.reset_modifiedc C s | j rtd��dS )zRAssert if the object is writable
@raise: L{PersistReadOnlyError}
z"Configuration is in readonly mode.N)r r
r r r r �assert_writablee s zPersist.assert_writablec s� � �fdd�}t j�� �� t j�� �s<|� r0dS td� ��t j�� �dkrV|� dS z�j�� ��_W n, t k
r� |� r�Y dS td� ��Y nX dS )zLoad a persisted database.c s` � d } t j�| �r\t j�| �dkr\z�j�| ��_W n tk
rV td| ��Y nX dS dS )N�.oldr �Broken configuration file at %sTF) r r �isfile�getsizer r r � Exceptionr )Zfilepathold��filepathr r r �load_oldp s ��zPersist.load.<locals>.load_oldNzFile not found: %sr r* )
r r �
expanduserr+ r r, r r r r- )r r/ r0 r r. r r m s zPersist.loadc C s� |dkr | j dkrtd��| j }tj�|�}tj�|�rHt�||d � tj�|�}|rntj�|�snt� |� | j
�|| j� dS )z�Save the persist to the given C{filepath}.
If None is specified, then the filename passed during construction will
be used.
If the destination file already exists, it will be renamed
to C{<filepath>.old}.
NzNeed a filename!r) )
r r r r r1 r+ �rename�dirname�isdir�makedirsr �saver )r r/ r3 r r r r6 � s
zPersist.savec
C s8 |t k r| j�|�}t|�}t }|}|r�|}|�d�}| j�||�}|tkr�|rb|d t|� � }tdt |�t
|�t|�f ��||kr$q�q$||k r�||k r�| j�|||�}n�||kr�|}nxt|�dkr�t |d �t
kr�g } q�i } n|} | j�||| �}|tk�rtdt |�t |�f ��|�s$�q4|}|�d�}q�|S )Nr zCan't traverse %r (%r): %rzCan't traverse %r with %r)�NOTHINGr �copy�list�pop�get�NotImplemented�lenr �typer �str�set�int)
r �objr �default�setvalueZqueue�marker�newobj�elemZnewvaluer r r � _traverse� sN
��
�zPersist._traverseFc C s� t |t�rt|�}t}|r,| �| j||�}nl|rB| �| j||�}nV|rX| �| j||�}n@| �| j||�}||kr�| �| j||�}||kr�| �| j||�}|S r )�
isinstancer r r7 rH r r r )r r �soft�hard�weakrE �valuer r r � _getvalue� s
zPersist._getvaluec C sV | � ||||�}t}||kr dS ||kr,dS | j�||�}|tkrRtdt|� ��|S )NFTzCan't check %r for containment)rN r7 r �hasr<