HOME


Mini Shell 1.0
DIR: /lib/python3/dist-packages/landscape/lib/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/landscape/lib/__pycache__/persist.cpython-312.pyc
�

�~�eLR���ddlZddlZddlZddlZddlmZgd�Ze�ZGd�de	�Z
Gd�de
�ZGd�d	�ZGd
�d�Z
ejd�jZd
�Zd�ZGd�d�ZGd�de�ZGd�de�Zy)�N)�
StringType)�Persist�
PickleBackend�BPickleBackend�path_string_to_tuple�path_tuple_to_string�
RootedPersist�PersistError�PersistReadOnlyErrorc��eZdZy)r
N��__name__�
__module__�__qualname__���7/usr/lib/python3/dist-packages/landscape/lib/persist.pyr
r
,���rr
c��eZdZy)rNr
rrrrr0rrrc���eZdZdZdd�Zd�Zd�Zd�Zeee�Z	ee�Z
d�Zd�Zd	�Z
dd
�Zeefd�Zdd
�Zedddfd�Zdd�Zdd�Zdd�Zdd�Zeddfd�Zdd�Zd�Zy)raPersist 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��|�
t�}||_|j�|_i|_i|_d|_d|_||_||_	|�2tjj|�r|j|�yyy)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�	_modified�_config�filename�os�path�exists�load)�self�backendr s   r�__init__zPersist.__init__Fsx���?�$�&�G���
����
��
���
���
���������� ��
���B�G�G�N�N�8�$<��I�I�h��%=�rc��|jS�N)r�r%s r�
_get_readonlyzPersist._get_readonly\����~�~�rc�$�t|�|_yr))�boolr)r%�flags  r�
_set_readonlyzPersist._set_readonly_s
���d���rc��|jSr)�rr*s r�
_get_modifiedzPersist._get_modifiedbr,rc��d|_y)z(Set the database status as non-modified.FNr2r*s r�reset_modifiedzPersist.reset_modifiedhs	����rc�2�|jrtd��y)zRAssert if the object is writable

        @raise: L{PersistReadOnlyError}
        z"Configuration is in readonly mode.N)rrr*s r�assert_writablezPersist.assert_writablels��
�>�>�&�'K�L�L�rc������fd�}tjj���tjj��s|�ryt	d�����tjj��dk(r|�y	�jj���_y#t$r|�rYyt	d�����wxYw)zLoad a persisted database.c����dz}tjj|�rDtjj|�dkDr"	�jj|��_yy#t$rtd|����wxYw)N�.oldr�Broken configuration file at TF)	r!r"�isfile�getsizerr$r�	Exceptionr
)�filepathold�filepathr%s ��r�load_oldzPersist.load.<locals>.load_oldws}���"�V�+�K������{�+��G�G�O�O�K�0�1�4�
�$(�M�M�$6�$6�{�$C�D�M�
���!��&�7��}�E����s�	 A+�+BNzFile not found: rr;)
r!r"�
expanduserr<r
r=rr$rr>)r%r@rAs`` rr$zPersist.loadts����	�$�7�7�%�%�h�/���w�w�~�~�h�'��z���!1�(��<�=�=�
�7�7�?�?�8�$��)��J��	K� �M�M�.�.�x�8�D�M���	K��z���!>�x�j�I�J�J�	K�s� B)�)C
�;C
c���|�#|j�td��|j}tjj	|�}tjj|�rtj||dz�tjj|�}|r4tjj|�stj|�|jj||j�y)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"rBr<�rename�dirname�isdir�makedirsr�saver)r%r@rEs   rrHzPersist.save�s������}�}�$�"�#5�6�6��}�}�H��7�7�%�%�h�/��
�7�7�>�>�(�#��I�I�h��6� 1�2��'�'�/�/�(�+���2�7�7�=�=��1��K�K�� ��
�
���8�T�]�]�3rc
���|tur|jj|�}t|�}t}|}|r|}|j	d�}|jj||�}|tur@|r|dt|�}tdt|��dt|��dt|�����||urn|r�||ur#||ur|jj||�}|S||ur|}|S	t|�dkDrt|d�turg}	ni}	n|}	|jj||	�}|tur#tdt|��dt|�����|s	|S|}|j	d�}��)NrzCan't traverse z (z): z with )�NOTHINGr�copy�list�pop�get�NotImplemented�lenr
�typer�str�set�int)
r%�objr"�default�setvalue�queue�marker�newobj�elem�newvalues
          r�	_traversezPersist._traverse�s����7�"��}�}�)�)�(�3�H��T�
��������C��9�9�Q�<�D��]�]�&�&�s�D�1�F���'���
�3�u�:�+�.�D�"�%�d�3�i�]�3�,�T�2�5�S��S���F������������v�%����*�*�3��h�?��.�
�+�6�!� ��(�
�%��5�z�A�~���a��>�S�0�')�H�')�H�#+��!�]�]�.�.�s�D�(�C�F���/�*�-�d�3�i�]�;$�$(��J�>�3���!���
�!�C� �9�9�Q�<�D�#rFc���t|t�rt|�}t}|r|j	|j
||�}|S|r|j	|j||�}|S|r|j	|j||�}|S|j	|j
||�}||ur>|j	|j||�}||ur|j	|j||�}|Sr))�
isinstancerrrJr]rrr)r%r"�soft�hard�weakrY�values       r�	_getvaluezPersist._getvalue�s����d�J�'�'��-�D�����N�N�4�=�=�$��?�E�����N�N�4�=�=�$��?�E�����N�N�4�=�=�$��?�E����N�N�4�=�=�$��?�E�������t�}�}�d�F�C���F�?� �N�N�4�=�=�$��G�E��rc���|j||||�}t}||ury||ury|jj||�}|turtdt
|��d���|S)NFTzCan't check z for containment)rdrJr�hasrOr
rQ)	r%r"rcr`rarbrUrY�results	         rrfzPersist.has�sk���n�n�T�4��t�4�����&�=��
�f�_�����"�"�3��.���^�#���d�3�i�]�:J�K�L�L��
rc��|j||||�}|turgS|jj|�}|turtdt
|�����|S)NzCan't return keys for )rdrJr�keysrOr
rQ)r%r"r`rarbrUrgs       rrizPersist.keys�sZ���n�n�T�4��t�4���'�>��I����#�#�C�(���^�#��!7��S�	�{�C�D�D��
rc�t�|j||||�}|tur|S|jj|�Sr))rdrJrrK)r%r"rVr`rarbrcs       rrNzPersist.gets8�����t�T�4��6���G���N��}�}�!�!�%�(�(rc���|sJ�t|t�rt|�}|r
|j}n2|r
|j}n#|j�d|_|j}|j|||��y�NT)rW)	r_rrrrr7rrr])r%r"rcr`rb�maps      rrSzPersist.setsc����t��d�J�'�'��-�D���-�-�C�
��-�-�C�� � �"�!�D�N��-�-�C����s�D�5��1rc�h�|sJ�t|t�rt|�}|r
|j}n2|r
|j}n#|j�d|_|j}|r(|j||�}t|�tur||vry|tjfz}|j|||��yrl)
r_rrrrr7rrr]rQrL�sys�maxsize)r%r"rc�uniquer`rbrm�currents        r�addzPersist.adds�����t��d�J�'�'��-�D���-�-�C�
��-�-�C�� � �"�!�D�N��-�-�C���n�n�S�$�/�G��G�}��$��'�)9���s�{�{�n�$�����s�D�5��1rc�>�|sJ�t|t�rt|�}|r
|j}n2|r
|j}n#|j�d|_|j}t}|r�||ur|j||dd�}|d}d}	n|j||�}|}d}	d}
||urI|jj|||	�}
|
tur$tdj|t|����|jj!|�r
||ur|}n	|dd}n	|
S|r��
S)NT���FzCan't remove {!r} from {!r})r_rrrrr7rrrJr]r�removerOr
�formatrQ�empty)r%r"rcr`rbrmrYrUr[�isvaluergs           rrvzPersist.remove)s,����t��d�J�'�'��-�D���-�-�C�
��-�-�C�� � �"�!�D�N��-�-�C��������n�n�S�$�s��)�4���B�x�����n�n�S�$�/�������F��&� ����-�-�c�4��A���^�+�&�5�<�<�T�4��9�M����}�}�"�"�3�'���&�"�E����9�D���
�/�.�
rc�8�|s|s|j�t|t�rt|�}t|t�rt|�}d}t}|j|||xs||�}||ur*|j
|||��|j||||�d}|S)NF)r`rbT)r7r_rrrJrdrvrS)r%�oldpath�newpathr`rbrgrYrcs        r�movezPersist.moveOs������ � �"��g�z�*�*�7�3�G��g�z�*�*�7�3�G��������w��4�<�4�.@�$�G������K�K��d��K�6��H�H�W�e�T�4�0��F��
rc��t||�S)zv
        Rebase the database hierarchy.

        @return: A L{RootedPersist} using this L{Persist} as parent.
        )r	�r%r"s  r�root_atzPersist.root_at_s���T�4�(�(r)NNr)�FFF�NFFF�FF)rrr�__doc__r'r+r0r3�property�readonly�modifiedr5r7r$rHrJr]rdrfrirNrSrsrvr}r�rrrrr4s����  �,�$���
�}�5�H��
�&�H��M�"K�H4�*,3�W�,�\�$&�E��E�
��)�2�2�&")�u�5�$�L� )rrc��eZdZdZd�Zed��Zed��Zd�Ze	dddfd�Z
dd�Zdd
�Zdd�Z
dd�Ze	ddfd
�Zdd�Zd�Zy	)r	axRoot 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.
    c�b�||_t|t�rt|�|_y||_y)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)�parentr_rr�root)r%r�r�s   rr'zRootedPersist.__init__ss(������d�J�'�,�T�2�D�I��D�Irc�.�|jjSr))r�r�r*s r�<lambda>zRootedPersist.<lambda>���T�[�[�%9�%9�rc�.�|jjSr))r�r�r*s rr�zRootedPersist.<lambda>�r�rc�8�|jj�yr))r�r7r*s rr7zRootedPersist.assert_writable�s�����#�#�%rFc��t|t�rt|�}|jj	|j
|z||||�Sr))r_rrr�rfr�)r%r"rcr`rarbs      rrfzRootedPersist.has�s:���d�J�'�'��-�D��{�{���t�y�y�4�/���d�D�I�Irc��t|t�rt|�}|jj	|j
|z|||�Sr))r_rrr�rir�)r%r"r`rarbs     rrizRootedPersist.keys�s:���d�J�'�'��-�D��{�{����	�	�D� 0�$��d�C�CrNc��t|t�rt|�}|jj	|j
|z||||�Sr))r_rrr�rNr�)r%r"rVr`rarbs      rrNzRootedPersist.get�s:���d�J�'�'��-�D��{�{���t�y�y�4�/��$��d�K�Krc��t|t�rt|�}|jj	|j
|z|||�Sr))r_rrr�rSr��r%r"rcr`rbs     rrSzRootedPersist.set�s8���d�J�'�'��-�D��{�{���t�y�y�4�/���d�C�Crc��t|t�rt|�}|jj	|j
|z||||�Sr))r_rrr�rsr�)r%r"rcrqr`rbs      rrszRootedPersist.add�s:���d�J�'�'��-�D��{�{���t�y�y�4�/����d�K�Krc��t|t�rt|�}|jj	|j
|z|||�Sr))r_rrr�rvr�r�s     rrvzRootedPersist.remove�s:���d�J�'�'��-�D��{�{�!�!�$�)�)�d�"2�E�4��F�Frc���t|t�rt|�}t|t�rt|�}|jj	|j
|z|j
|z||�Sr))r_rrr�r}r�)r%r{r|r`rbs     rr}zRootedPersist.move�s_���g�z�*�*�7�3�G��g�z�*�*�7�3�G��{�{����I�I����I�I�����	
�	
rc��t|t�rt|�}|jj	|j
|z�Sr))r_rrr�r�r�rs  rr�zRootedPersist.root_at�s4���d�J�'�'��-�D��{�{�"�"�4�9�9�t�#3�4�4rr�r�r�)rrrr�r'r�r�r�r7rJrfrirNrSrsrvr}r�rrrr	r	hsk���
��9�:�H��9�:�H�&�&�E��E�J�
D�
L�
D�
L�
")�u�5�G�


�5rr	z(\[-?\d+\])|(?<!\\)\.c�2�d|vrd|vr|fSg}t|�}|D]U}|s�|ddk(r'|ddk(r	|jt|dd���5|j|jdd���Wt
|�S#t$rt	d|����wxYw)	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.
    �.�[rru�]�zInvalid path index: �\.)�
_splitpath�appendrT�
ValueErrorr
�replace�tuple)r"rg�tokens�tokens    rrr�s��� �$��3�d�?��w��
�F�
��
�F��9����Q�x�3��5��9��#3�I��M�M�#�e�A�b�k�"2�3��
�
�e�m�m�E�3�7�8�9���=���	"�I�&�)=�e�Y�'G�H�H�I�s�A>�>Bc���g}|D]P}t|�tur|dxxd|d�d�z
cc<�'|jt|�j	dd���Rdj|�S)Nrur��dr�r�r�)rQrTr�rRr��join)r"rgr[s   rrr�sh��
�F��9����:����2�J�A�d�1�X�Q�-�'�J��M�M�#�d�)�+�+�C��7�8�	9�
�8�8�F��rc�P�eZdZdZd�Zd�Zd�Zefd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zy)
�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]}
    c��t�r)��NotImplementedErrorr*s rrzBackend.new���!�!rc��t�r)r�)r%r@s  rr$zBackend.loadr�rc��t�r)r�)r%r@rms   rrHzBackend.saver�rc��t|�tur|j||�}|St|�ttfvr%t|�t
ur	||}|S||vr|}|S|}|St}|S#t$r|}Y|SwxYw)z(Lookup a child in the given node object.)rQ�dictrNr�rLrT�
IndexErrorrO)r%rUr[�_markerrZs     rrNzBackend.gets�����9����W�W�T�7�+�F��
��#�Y�5�$�-�
'��D�z�S� �%� ��Y�F��
�
�����
�
�!���
�$�F��
��"�%�$�F��
�%�s�A*�*A9�8A9c�2�t|�tur	|x}||<|St|�turet|�turTt	|�}||kr|jd�|}n'|dkr"t
|�|kDr|jdd�d}|x}||<|St}|S)z:Set the value of the given child in the given node object.Nr)	rQr�rLrTrPr��abs�insertrO)r%rUr[rcrZ�lenobjs      rrSzBackend.sets�����9���!&�&�F�S��Y��
��#�Y�$�
�4��:��#4���X�F���~��
�
�4� ������c�$�i�&�0��
�
�1�d�#���!&�&�F�S��Y��
�$�F��
rc��d}t|�tur||vr||=d}|St|�tur<|st|�tur	||=d}|S||vr|D�cgc]
}||k7s�	|��c}|ddd}|St
}|S#t$rY|SwxYwcc}w)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.
        FTN)rQr�rLrTr�rO)r%rUr[ryrg�xs      rrvzBackend.remove.s�������9����s�{���I����
��#�Y�$�
��t�D�z�S�0���D�	�!�F��
����%(�6��A��I�!�6��A�����
�$�F��
��"����
���7s�A4�
B�B�4	B�Bc�^�t|�ttfvrtj|�S|S)zCopy a node or a value.)rQr�rLrK�deepcopy)r%rcs  rrKzBackend.copyHs&����;�4��,�&��=�=��'�'��rc��|S)z.Whether the given node object has no children.r)r%rUs  rrxz
Backend.emptyNs	���w�rc�<�t|dd�}|r||�StS)z?Whether the given node object contains the given child element.�__contains__N)�getattrrO)r%rUr[�containss    rrfzBackend.hasRs#���3���5����D�>�!��rc��t|dd�}|r|�St|�turtt	|��St
S)z?Return the keys of the child elements of the given node object.riN)r�rQrL�rangerPrO)r%rUris   rrizBackend.keysYs:���s�F�D�)����6�M�
�#�Y�$�
���S��?�"��rN)rrrr�rr$rHrJrNrSrvrKrxrfrirrrr�r��s>���>"�"�"�&-��$�"�4���rr�c�$�eZdZd�Zd�Zd�Zd�Zy)rc��ddlm}||_y)Nr)�cPickle)�landscape.lib.compatr��_pickle)r%r�s  rr'zPickleBackend.__init__ds��0���rc��iSr)rr*s rrzPickleBackend.newi����	rc�|�t|d�5}|jj|�cddd�S#1swYyxYw�N�rb)�openr�r$�r%r@�fds   rr$zPickleBackend.loadls5��
�(�D�
!�	)�R��<�<�$�$�R�(�	)�	)�	)�s�2�;c��t|d�5}|jj||d�ddd�y#1swYyxYw)N�wb�)r�r��dump�r%r@rmr�s    rrHzPickleBackend.saveps9��
�(�D�
!�	*�R��L�L���c�2�q�)�	*�	*�	*�s�4�=N�rrrr'rr$rHrrrrrcs���
�)�*rrc�$�eZdZd�Zd�Zd�Zd�Zy)rc��ddlm}||_y)Nr)�bpickle)�
landscape.libr��_bpickle)r%r�s  rr'zBPickleBackend.__init__vs��)���
rc��iSr)rr*s rrzBPickleBackend.new{r�rc��t|d�5}|jj|j��cddd�S#1swYyxYwr�)r�r��loads�readr�s   rr$zBPickleBackend.load~s;��
�(�D�
!�	2�R��=�=�&�&�r�w�w�y�1�	2�	2�	2�s�)A�A	c��t|d�5}|j|jj|��ddd�y#1swYyxYw)Nr�)r��writer��dumpsr�s    rrHzBPickleBackend.save�s>��
�(�D�
!�	/�R��H�H�T�]�]�(�(��-�.�	/�	/�	/�s�+A�A
Nr�rrrrrus�� �
�2�/rr)rKr!�rero�twisted.python.compatr�__all__�objectrJr>r
rrr	�compile�splitr�rrr�rrrrr�<module>r�s���*�	�	�
�,�	���(��	�9�	�	�<�	�q)�q)�h	J5�J5�Z�R�Z�Z�0�
1�
7�
7�
��@�~�~�B*�G�*�$/�W�/r