HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/self/root/usr/lib/python3/dist-packages/landscape/lib/__pycache__/persist.cpython-38.pyc
U

���cR�@s�ddlZddlZddlZddlZddlmZddddddd	d
gZe�ZGdd	�d	e	�Z
Gdd
�d
e
�ZGd
d�de�ZGdd�de�Z
e�d�jZdd�Zdd�ZGdd�de�ZGdd�de�ZGdd�de�ZdS)�N)�
StringType�Persist�
PickleBackend�BPickleBackend�path_string_to_tuple�path_tuple_to_string�
RootedPersist�PersistError�PersistReadOnlyErrorc@seZdZdS)r	N��__name__�
__module__�__qualname__�rr�7/usr/lib/python3/dist-packages/landscape/lib/persist.pyr	%sc@seZdZdS)r
Nrrrrrr
)sc@s�eZdZdZd(dd�Zdd�Zdd�Zd	d
�Zeee�Z	ee�Z
dd�Zd
d�Zdd�Z
d)dd�Zeefdd�Zd*dd�Zedddfdd�Zd+dd�Zd,dd�Zd-dd�Zd.d d!�Zeddfd"d#�Zd/d$d%�Zd&d'�ZdS)0raPersist 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.

    NcCsd|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)�selfZbackendrrrr�__init__?s	
zPersist.__init__cCs|jS�N)r�rrrr�
_get_readonlyUszPersist._get_readonlycCst|�|_dSr)�boolr)r�flagrrr�
_set_readonlyXszPersist._set_readonlycCs|jSr�rr rrr�
_get_modified[szPersist._get_modifiedcCs
d|_dS)z(Set the database status as non-modified.FNr%r rrr�reset_modifiedaszPersist.reset_modifiedcCs|jrtd��dS)zRAssert if the object is writable

        @raise: L{PersistReadOnlyError}
        z"Configuration is in readonly mode.N)rr
r rrr�assert_writableeszPersist.assert_writablecs���fdd�}tj����tj���s<|�r0dStd���tj���dkrV|�dSz�j����_Wn,t	k
r�|�r�YdStd���YnXdS)zLoad a persisted database.cs`�d}tj�|�r\tj�|�dkr\z�j�|��_Wn tk
rVtd|��YnXdSdS)N�.oldr�Broken configuration file at %sTF)	rr�isfile�getsizerrr�	Exceptionr	)Zfilepathold��filepathrrr�load_oldps��zPersist.load.<locals>.load_oldNzFile not found: %srr*)
rr�
expanduserr+r	r,rrrr-)rr/r0rr.rrmszPersist.loadcCs�|dkr |jdkrtd��|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))
rr	rrr1r+�rename�dirname�isdir�makedirsr�saver)rr/r3rrrr6�s	

zPersist.savec
Cs8|tk	r|j�|�}t|�}t}|}|r�|}|�d�}|j�||�}|tkr�|rb|dt|��}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)NrzCan'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�elemZnewvaluerrr�	_traverse�sN
��
�zPersist._traverseFcCs�t|t�rt|�}t}|r,|�|j||�}nl|rB|�|j||�}nV|rX|�|j||�}n@|�|j||�}||kr�|�|j||�}||kr�|�|j||�}|Sr)�
isinstancerrr7rHrrr)rr�soft�hard�weakrE�valuerrr�	_getvalue�s
zPersist._getvaluec	CsV|�||||�}t}||kr dS||kr,dS|j�||�}|tkrRtdt|���|S)NFTzCan't check %r for containment)rNr7r�hasr<r	r>)	rrrMrJrKrLrBrE�resultrrrrO�szPersist.hascCsD|�||||�}|tkrgS|j�|�}|tkr@tdt|���|S)NzCan't return keys for %s)rNr7r�keysr<r	r>)rrrJrKrLrBrPrrrrQ�szPersist.keyscCs(|�||||�}|tkr|S|j�|�Sr)rNr7rr8)rrrCrJrKrLrMrrrr;�szPersist.getcCsZ|st�t|t�rt|�}|r&|j}n |r2|j}n|��d|_|j}|j	|||d�dS�NT)rD)
�AssertionErrorrIrrrrr(rrrH)rrrMrJrL�maprrrr@�s
zPersist.setcCs�|st�t|t�rt|�}|r&|j}n |r2|j}n|��d|_|j}|rn|�	||�}t
|�tkrn||krndS|tj
f}|j	|||d�dSrR)rSrIrrrrr(rrrHr>r9�sys�maxsize)rrrM�uniquerJrLrTZcurrentrrr�add
s 
zPersist.addcCs�|st�t|t�rt|�}|r&|j}n |r2|j}n|��d|_|j}t	}|r�||krx|�
||dd��}|d}d}	n|�
||�}|}d}	d}
||k	r�|j�|||	�}
|
t
kr�td|t|�f��|j�|�r�||k	r�|}q�|dd�}qJq�qJ|
S)NT���FzCan't remove %r from %r)rSrIrrrrr(rrr7rHr�remover<r	r>�empty)rrrMrJrLrTrErBrG�isvaluerPrrrrZs@

�zPersist.removecCs�|s|s|��t|t�r"t|�}t|t�r4t|�}d}t}|�|||pJ||�}||k	r~|j|||d�|�||||�d}|S)NF)rJrLT)r(rIrrr7rNrZr@)r�oldpath�newpathrJrLrPrErMrrr�moveBs

zPersist.movecCs
t||�S)zv
        Rebase the database hierarchy.

        @return: A L{RootedPersist} using this L{Persist} as parent.
        )r�rrrrr�root_atRszPersist.root_at)NN)N)FFF)FFF)NFFF)FF)FFF)FF)rr
r�__doc__rr!r$r&�property�readonly�modifiedr'r(rr6r7rHrNrOrQr;r@rXrZr_rarrrrr-s*

"
+

	


%
c@s�eZdZdZdd�Zedd��Zedd��Zdd�Ze	d	d	d	fd
d�Z
ddd
�Zddd�Zddd�Z
ddd�Ze	d	d	fdd�Zddd�Zdd�ZdS) raxRoot a L{Persist}'s tree at a particular branch.

    This class shares the same interface of L{Persist} and provides a shortcut
    to access the nodes of a particular branch in a L{Persist}'s tree.

    The chosen branch will be viewed as the root of the tree of the
    L{RootedPersist} and all operations will be forwarded to the parent
    L{Persist} as appropriate.
    cCs&||_t|t�rt|�|_n||_dS)z�
        @param parent: the parent L{Persist}.
        @param root: a branch of the parent L{Persist}'s tree, that
            will be used as root of this L{RootedPersist}.
        N)�parentrIrr�root)rrfrgrrrrfs
zRootedPersist.__init__cCs|jjSr)rfrdr rrr�<lambda>r�zRootedPersist.<lambda>cCs|jjSr)rfrer rrrrhsricCs|j��dSr)rfr(r rrrr(uszRootedPersist.assert_writableFcCs,t|t�rt|�}|j�|j|||||�Sr)rIrrrfrOrg)rrrMrJrKrLrrrrOxs
zRootedPersist.hascCs*t|t�rt|�}|j�|j||||�Sr)rIrrrfrQrg)rrrJrKrLrrrrQ}s
zRootedPersist.keysNcCs,t|t�rt|�}|j�|j|||||�Sr)rIrrrfr;rg)rrrCrJrKrLrrrr;�s
zRootedPersist.getcCs*t|t�rt|�}|j�|j||||�Sr)rIrrrfr@rg�rrrMrJrLrrrr@�s
zRootedPersist.setcCs,t|t�rt|�}|j�|j|||||�Sr)rIrrrfrXrg)rrrMrWrJrLrrrrX�s
zRootedPersist.addcCs*t|t�rt|�}|j�|j||||�Sr)rIrrrfrZrgrjrrrrZ�s
zRootedPersist.removecCsBt|t�rt|�}t|t�r$t|�}|j�|j||j|||�Sr)rIrrrfr_rg)rr]r^rJrLrrrr_�s

�zRootedPersist.movecCs$t|t�rt|�}|j�|j|�Sr)rIrrrfrargr`rrrra�s
zRootedPersist.root_at)FFF)NFFF)FF)FFF)FF)rr
rrbrrcrdrer(r7rOrQr;r@rXrZr_rarrrrr[s





z(\[-?\d+\])|(?<!\\)\.c	Cs�d|krd|kr|fSg}t|�}|D]p}|r&|ddkr�|ddkr�z|�t|dd���Wq�tk
r�td|��Yq�Xq&|�|�dd��q&t|�S)	a�Convert a L{Persist} path string to a path tuple.

    Examples:

        >>> path_string_to_tuple("ab")
        ("ab",)
        >>> path_string_to_tuple("ab.cd")
        ("ab", "cd"))
        >>> path_string_to_tuple("ab[0][1]")
        ("ab", 0, 1)
        >>> path_string_to_tuple("ab[0].cd[1]")
        ("ab", 0, "cd", 1)

    Raises L{PersistError} if the given path string is invalid.
    �.�[rrY�]�zInvalid path index: %r�\.)�
_splitpath�appendrA�
ValueErrorr	�replace�tuple)rrP�tokens�tokenrrrr�scCsPg}|D]<}t|�tkr.|dd|7<q|�t|��dd��qd�|�S)NrYz[%d]rkro)r>rArqr?rs�join)rrPrGrrrr�sc@sdeZdZdZdd�Zdd�Zdd�Zefdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�ZdS)�BackendaD
    Base class for L{Persist} backends implementing hierarchical storage
    functionality.

    Each node of the hierarchy is an object of type C{dict}, C{list}
    or C{tuple}. A node can have zero or more children, each child can be
    another node or a leaf value compatible with the backend's serialization
    mechanism.

    Each child element is associated with a unique key, that can be used to
    get, set or remove the child itself from its containing node. If the node
    object is of type C{dict}, then the child keys will be the keys of the
    dictionary, otherwise if the node object is of type C{list} or C{tuple}
    the child element keys are the indexes of the available items, or the value
    of items theselves.

    The root node object is always a C{dict}.

    For example:

        >>> backend = Backend()
        >>> root = backend.new()
        >>> backend.set(root, "foo", "bar")
        'bar'
        >>> egg = backend.set(root, "egg", [1, 2, 3])
        >>> backend.set(egg, 0, 10)
        10
        >>> root
        {'foo': 'bar', 'egg': [10, 2, 3]}
    cCst�dSr��NotImplementedErrorr rrrr�szBackend.newcCst�dSrry)rr/rrrr�szBackend.loadcCst�dSrry)rr/rTrrrr6�szBackend.savecCszt|�tkr|�||�}n\t|�ttfkrrt|�tkr^z||}Wqptk
rZ|}YqpXqv||krl|}qv|}nt}|S)z(Lookup a child in the given node object.)r>�dictr;rtr9rA�
IndexErrorr<)rrBrGZ_markerrFrrrr;�szBackend.getcCs�t|�tkr|}||<nnt|�tkr�t|�tkr�t|�}||krR|�d�|}n$|dkrvt|�|krv|�dd�d}|}||<nt}|S)z:Set the value of the given child in the given node object.Nr)	r>r{r9rAr=rq�abs�insertr<)rrBrGrMrFZlenobjrrrr@s
zBackend.setcs�d}t|�tkr$�|kr�|�=d}nnt|�tkr�|sft��tkrfz|�=d}Wq�tk
rbYq�Xq��|kr��fdd�|D�|dd�<d}nt}|S)z�Remove a the given child in the given node object.

        @param isvalue: In case the node object is a C{list}, a boolean
            indicating if C{elem} is the index of the child or the value
            of the child itself.
        FTcsg|]}|�kr|�qSrr)�.0�x�rGrr�
<listcomp>1sz"Backend.remove.<locals>.<listcomp>N)r>r{r9rAr|r<)rrBrGr\rPrr�rrZs"zBackend.removecCst|�ttfkrt�|�S|S)zCopy a node or a value.)r>r{r9r8�deepcopy)rrMrrrr87s
zBackend.copycCs|S)z.Whether the given node object has no children.r)rrBrrrr[=sz
Backend.emptycCst|dd�}|r||�StS)z?Whether the given node object contains the given child element.�__contains__N)�getattrr<)rrBrG�containsrrrrOAszBackend.hascCs2t|dd�}|r|�St|�tkr.tt|��StS)z?Return the keys of the child elements of the given node object.rQN)r�r>r9�ranger=r<)rrBrQrrrrQHszBackend.keysN)rr
rrbrrr6r7r;r@rZr8r[rOrQrrrrrx�srxc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
rcCsddlm}||_dS)Nr)�cPickle)Zlandscape.lib.compatr��_pickle)rr�rrrrTszPickleBackend.__init__cCsiSrrr rrrrXszPickleBackend.newc
Cs.t|d��}|j�|�W5QR�SQRXdS�N�rb)�openr�r�rr/�fdrrrr[szPickleBackend.loadc	Cs*t|d��}|j�||d�W5QRXdS)N�wb�)r�r��dump�rr/rTr�rrrr6_szPickleBackend.saveN�rr
rrrrr6rrrrrRsc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
rcCsddlm}||_dS)Nr)�bpickle)Z
landscape.libr��_bpickle)rr�rrrrfszBPickleBackend.__init__cCsiSrrr rrrrjszBPickleBackend.newc
Cs2t|d��}|j�|���W5QR�SQRXdSr�)r�r��loads�readr�rrrrmszBPickleBackend.loadc	Cs,t|d��}|�|j�|��W5QRXdS)Nr�)r��writer��dumpsr�rrrr6qszBPickleBackend.saveNr�rrrrrds)rrUr8�reZtwisted.python.compatr�__all__�objectr7r-r	r
rr�compile�splitrprrrxrrrrrr�<module>s2�0I