%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/persisted/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/persisted/__pycache__/dirdbm.cpython-312.pyc

�

Ϫ�fv'���dZddlZddlZddlZddlZddlmZ	eGd�d�Z
Gd�de
�Zd
d�Z	gd	�Zy#e$re	ZY�'wxYw)a�
DBM-style interface to a directory.

Each key is stored as a single file.  This is not expected to be very fast or
efficient, but it's good for easy debugging.

DirDBMs are *not* thread-safe, they should only be accessed by one thread at
a time.

No files should be placed in the working directory of a DirDBM save those
created by the DirDBM itself!

Maintainer: Itamar Shtull-Trauring
�N)�FilePathc��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zdd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�DirDBMz�
    A directory with a DBM interface.

    This class presents a hash-like interface to a directory of small,
    flat files. It can only use strings as keys or values.
    c��tjj|�|_t	|�|_|j
j
�s|j
j�ytj|j
jd�j�D]}tj|��tj|j
jd�j�}|D]R}|dd}tjj|�rtj|��=tj||��Ty)zb
        @type name: str
        @param name: Base path to use for the directory storage.
        z*.newz*.rplN���)
�os�path�abspath�dnamer�
_dnamePath�isdir�createDirectory�glob�child�remove�exists�rename)�self�name�f�replacements�olds     �:/usr/lib/python3/dist-packages/twisted/persisted/dirdbm.py�__init__zDirDBM.__init__,s���
�W�W�_�_�T�*��
�"�4�.������$�$�&��O�O�+�+�-��Y�Y�t���4�4�W�=�B�B�C�
���	�	�!��
��9�9�T�_�_�%:�%:�7�%C�%H�%H�I�L�!�
&�����f���7�7�>�>�#�&��I�I�a�L��I�I�a��%�
&�c�l�tj|�jdd�jdd�S)z?
        Encode a key so it can be used as a filename.
        �
�_�/�-)�base64�encodebytes�replace�r�ks  r�_encodezDirDBM._encodeHs/��
�!�!�!�$�,�,�U�D�9�A�A�$��M�Mrc�l�tj|jdd�jdd��S)z3
        Decode a filename to get the key.
        rrr r)r!�decodebytesr#r$s  r�_decodezDirDBM._decodeOs-���!�!�!�)�)�D�%�"8�"@�"@��t�"L�M�Mrc�~�t|jd�5}|j�}ddd�|S#1swYSxYw)z�
        Read in the contents of a file.

        Override in subclasses to e.g. provide transparently encrypted dirdbm.
        �rbN)�_openr	�read)rr	r�ss    r�	_readFilezDirDBM._readFileUs9���4�9�9�d�
#�	�q�����A�	���	���s�2�<c��t|jd�5}|j|�|j�ddd�y#1swYyxYw)zw
        Write data to a file.

        Override in subclasses to e.g. provide transparently encrypted dirdbm.
        �wbN)r,r	�write�flush)rr	�datars    r�
_writeFilezDirDBM._writeFile_s=���4�9�9�d�
#�	�q�
�G�G�D�M�
�G�G�I�	�	�	�s�"A�Ac�H�t|jj��S)zF
        @return: The number of key/value pairs in this Shelf
        )�lenr�listdir�rs r�__len__zDirDBM.__len__is���4�?�?�*�*�,�-�-rc��t|�tk(std��t|�tk(std��|j|�}|jj|�}|j
�r|jd�}n|jd�}	|j||�|j
�r|j�|j|�y#t$r|j��wxYw)z�
        C{dirdbm[k] = v}
        Create or modify a textfile in this directory

        @type k: bytes
        @param k: key to set

        @type v: bytes
        @param v: value to associate with C{k}
        �DirDBM key must be byteszDirDBM value must be bytesz.rplz.newN)�type�bytes�	TypeErrorr&rrr�siblingExtensionr5r�moveTo�
BaseException)rr%�vr�news     r�__setitem__zDirDBM.__setitem__os����A�w�%���6�7�7��A�w�%���8�9�9��L�L��O���o�o�#�#�A�&���:�:�<��&�&�v�.�C��&�&�v�.�C�	��O�O�C��#�
�z�z�|��
�
���J�J�s�O��
�	��J�J�L��	�s�C�C:c���t|�tk(std��|jj	|j|��}	|j
|�S#t$rt|��wxYw)a
        C{dirdbm[k]}
        Get the contents of a file in this directory as a string.

        @type k: bytes
        @param k: key to lookup

        @return: The value associated with C{k}
        @raise KeyError: Raised when there is no such key
        r<)	r=r>r?rrr&r/�OSError�KeyError)rr%r	s   r�__getitem__zDirDBM.__getitem__�se���A�w�%���6�7�7����$�$�T�\�\�!�_�5��	��>�>�$�'�'���	��1�+��	�s�	A�A/c��t|�tk(std��|j|�}	|jj|�j
�y#t$rt|j|���wxYw)z�
        C{del dirdbm[foo]}
        Delete a file in this directory.

        @type k: bytes
        @param k: key to delete

        @raise KeyError: Raised when there is no such key
        r<N)
r=r>r?r&rrrrGrHr)r$s  r�__delitem__zDirDBM.__delitem__�sk���A�w�%���6�7�7��L�L��O��	,��O�O�!�!�!�$�+�+�-���	,��4�<�<��?�+�+�	,�s�)A�$A>c��tt|j|jj	�j���S)z9
        @return: a L{list} of filenames (keys).
        )�list�mapr)r�asBytesModer8r9s r�keyszDirDBM.keys�s0���C����d�o�o�&A�&A�&C�&K�&K�&M�N�O�Orc�`�g}|j�}|D]}|j||��|S)z?
        @return: a L{list} of file-contents (values).
        �rP�append)r�valsrP�keys    r�valuesz
DirDBM.values�s8�����y�y�{���	#�C��K�K��S�	�"�	#��rc�d�g}|j�}|D]}|j|||f��|S)zL
        @return: a L{list} of 2-tuples containing key/value pairs.
        rR)r�itemsrPrUs    rrXzDirDBM.items�s=�����y�y�{���	+�C��L�L�#�t�C�y�)�*�	+��rc��t|�tk(std��|j|�}|jj|�j
�S)z�
        @type key: bytes
        @param key: The key to test

        @return: A true value if this dirdbm has the specified key, a false
        value otherwise.
        r<)r=r>r?r&rr�isfile�rrUs  r�has_keyzDirDBM.has_key�sH���C�y�E�!��6�7�7��l�l�3������$�$�S�)�0�0�2�2rc�"�||vr|||<|S||S)z�
        @type key: bytes
        @param key: The key to lookup

        @param value: The value to associate with key if key is not already
        associated with a value.
        �)rrU�values   r�
setdefaultzDirDBM.setdefault�s#���d�?��D��I��L��C�y�rNc��||vr||S|S)z�
        @type key: bytes
        @param key: The key to lookup

        @param default: The value to return if the given key does not exist

        @return: The value associated with C{key} or C{default} if not
        L{DirDBM.has_key(key)}
        r^)rrU�defaults   r�getz
DirDBM.get�s���$�;���9���Nrc�$�|j|�S)z)
        @see: L{DirDBM.has_key}
        )r\r[s  r�__contains__zDirDBM.__contains__�s���|�|�C� � rc�>�|j�D]
\}}|||<�y)z�
        Add all the key/value pairs in L{dict} to this dirdbm.  Any conflicting
        keys will be overwritten with the values from L{dict}.

        @type dict: mapping
        @param dict: A mapping of key/value pairs to add to this dirdbm.
        N)rX)r�dictrU�vals    r�updatez
DirDBM.update�s&���
�
��	�H�C���D��I�	rc���t|�}||jk7sJ�|j|j�}|j	�|j�D]
}||||<�|S)a<
        Copy the contents of this dirdbm to the dirdbm at C{path}.

        @type path: L{str}
        @param path: The path of the dirdbm to copy to.  If a dirdbm
        exists at the destination path, it is cleared first.

        @rtype: C{DirDBM}
        @return: The dirdbm this dirdbm was copied to.
        )rr�	__class__r	�clearrP)rr	�dr%s    r�copyToz
DirDBM.copyTo
sa����~���t���&�&�&��N�N�4�9�9�%��	���	�����	�A���7�A�a�D�	��rc�4�|j�D]}||=�y)z<
        Delete all key/value pairs in this dirdbm.
        N)rPr$s  rrlzDirDBM.clears ������	�A��Q��	rc��y)zL
        Close this dbm: no-op, for dbm-style interface compliance.
        Nr^r9s r�closezDirDBM.close%s�rc���t|�tk(std��|jj	|j|��}|j
�r|j�St|��)z�
        Returns modification time of an entry.

        @return: Last modification date (seconds since epoch) of entry C{key}
        @raise KeyError: Raised when there is no such key
        r<)	r=r>r?rrr&rZ�getModificationTimerH)rrUr	s   rrszDirDBM.getModificationTime*s[���C�y�E�!��6�7�7����$�$�T�\�\�#�%6�7���;�;�=��+�+�-�-��3�-�r)N)�__name__�
__module__�__qualname__�__doc__rr&r)r/r5r:rErIrKrPrVrXr\r`rcrerirnrlrqrsr^rrrr$st���&�8N�N���.� �D�&,�$P���3��
�!�	��(��

 rrc��eZdZdZd�Zd�Zy)�Shelfz�
    A directory with a DBM shelf interface.

    This class presents a hash-like interface to a directory of small,
    flat files. Keys must be strings, but values can be any given object.
    c�\�tj|�}tj|||�y)z�
        C{shelf[foo] = bar}
        Create or modify a textfile in this directory.

        @type k: str
        @param k: The key to set

        @param v: The value to associate with C{key}
        N)�pickle�dumpsrrE)rr%rCs   rrEzShelf.__setitem__Bs#��
�L�L��O�����4��A�&rc�T�tjtj||��S)a
        C{dirdbm[foo]}
        Get and unpickle the contents of a file in this directory.

        @type k: bytes
        @param k: The key to lookup

        @return: The value associated with the given key
        @raise KeyError: Raised if the given key does not exist
        )r{�loadsrrIr$s  rrIzShelf.__getitem__Os ���|�|�F�.�.�t�Q�7�8�8rN)rtrurvrwrErIr^rrryry:s���'�9rryc��t|�S)z�
    This is for 'anydbm' compatibility.

    @param file: The parameter to pass to the DirDBM constructor.

    @param flag: ignored
    @param mode: ignored
    )r)�file�flag�modes   r�openr�]s���$�<�r)r�rry)NN)
rwr!rrr{�twisted.python.filepathrr,�	NameErrorr�rry�__all__r^rr�<module>r�s`��
� ��	�
�,��	�
S �S �l 9�F� 9�F	�&���S
���E��s�:�A�A

Zerion Mini Shell 1.0