%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3.12/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3.12/__pycache__/shelve.cpython-312.pyc

�

���fp!����dZddlmZmZmZddlmZddlZgd�Z	Gd�dejj�ZGd�d	ejj�Z
Gd
�de
�ZGd�d
e
�Zdd�Zy)a�
Manage shelves of pickled objects.

A "shelf" is a persistent, dictionary-like object.  The difference
with dbm databases is that the values (not the keys!) in a shelf can
be essentially arbitrary Python objects -- anything that the "pickle"
module can handle.  This includes most class instances, recursive data
types, and objects containing lots of shared sub-objects.  The keys
are ordinary strings.

To summarize the interface (key is a string, data is an arbitrary
object):

        import shelve
        d = shelve.open(filename) # open, with (g)dbm filename -- no suffix

        d[key] = data   # store data at key (overwrites old data if
                        # using an existing key)
        data = d[key]   # retrieve a COPY of the data at key (raise
                        # KeyError if no such key) -- NOTE that this
                        # access returns a *copy* of the entry!
        del d[key]      # delete data stored at key (raises KeyError
                        # if no such key)
        flag = key in d # true if the key exists
        list = d.keys() # a list of all existing keys (slow!)

        d.close()       # close it

Dependent on the implementation, closing a persistent dictionary may
or may not be necessary to flush changes to disk.

Normally, d[key] returns a COPY of the entry.  This needs care when
mutable entries are mutated: for example, if d[key] is a list,
        d[key].append(anitem)
does NOT modify the entry d[key] itself, as stored in the persistent
mapping -- it only modifies the copy, which is then immediately
discarded, so that the append has NO effect whatsoever.  To append an
item to d[key] in a way that will affect the persistent mapping, use:
        data = d[key]
        data.append(anitem)
        d[key] = data

To avoid the problem with mutable entries, you may pass the keyword
argument writeback=True in the call to shelve.open.  When you use:
        d = shelve.open(filename, writeback=True)
then d keeps a cache of all entries you access, and writes them all back
to the persistent mapping when you call d.close().  This ensures that
such usage as d[key].append(anitem) works as intended.

However, using keyword argument writeback=True may consume vast amount
of memory for the cache, and it may make d.close() very slow, if you
access many of d's entries after opening it in this way: d has no way to
check which of the entries you access are mutable and/or which ones you
actually mutate, so it must cache, and write back at close, all of the
entries that you access.  You can call d.sync() to write back all the
entries in the cache, and empty the cache (d.sync() also synchronizes
the persistent dictionary on disk, if feasible).
�)�DEFAULT_PROTOCOL�Pickler�	Unpickler)�BytesION)�Shelf�
BsdDbShelf�DbfilenameShelf�openc�4�eZdZdZd�ZexZxZxZxZxZ	Z
d�Zy)�_ClosedDictz>Marker for a closed dict.  Access attempts raise a ValueError.c��td��)Nz!invalid operation on closed shelf)�
ValueError)�self�argss  �/usr/lib/python3.12/shelve.py�closedz_ClosedDict.closedEs���<�=�=�c��y)Nz<Closed Dictionary>��rs r�__repr__z_ClosedDict.__repr__Is��$rN)�__name__�
__module__�__qualname__�__doc__r�__iter__�__len__�__getitem__�__setitem__�__delitem__�keysrrrrrrBs-��D�>�JP�P�H�P�w�P��P�{�P�[�4�%rrc�f�eZdZdZ		dd�Zd�Zd�Zd�Zdd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zd�Zd�Zy)rz�Base class for shelf implementations.

    This is initialized with a dictionary-like object.
    See the module's __doc__ string for an overview of the interface.
    Nc�Z�||_|�t}||_||_i|_||_y�N)�dictr�	_protocol�	writeback�cache�keyencoding�rr%�protocolr'r)s     r�__init__zShelf.__init__Ts1����	���'�H�!���"�����
�&��rc#�K�|jj�D]}|j|j����!y�wr$)r%r!�decoder))r�ks  rrzShelf.__iter__^s5���������!�	-�A��(�(�4�+�+�,�,�	-�s�>Ac�,�t|j�Sr$)�lenr%rs rrz
Shelf.__len__bs���4�9�9�~�rc�P�|j|j�|jvSr$��encoder)r%�r�keys  r�__contains__zShelf.__contains__es ���z�z�$�*�*�+�t�y�y�8�8rc�^�|j|j�|jvr||S|Sr$r3)rr6�defaults   r�getz	Shelf.geths,���:�:�d�&�&�'�4�9�9�4���9���rc��	|j|}|S#t$rit|j|j	|j
��}t
|�j�}|jr||j|<Y|SwxYwr$)	r(�KeyErrorrr%r4r)r�loadr'�rr6�value�fs    rrzShelf.__getitem__msz��	(��J�J�s�O�E�����	(���	�	�#�*�*�T�-=�-=�">�?�@�A��a�L�%�%�'�E��~�~�"'��
�
�3�����	(�s��A.B�Bc��|jr||j|<t�}t||j�}|j|�|j
�|j|j|j�<yr$)
r'r(rrr&�dump�getvaluer%r4r))rr6r?r@�ps     rrzShelf.__setitem__ws[���>�>�#�D�J�J�s�O��I���A�t�~�~�&��	���u�
�23�*�*�,��	�	�#�*�*�T�-�-�.�/rc��|j|j|j�=	|j|=y#t$rYywxYwr$)r%r4r)r(r<r5s  rr zShelf.__delitem__s?���I�I�c�j�j��!1�!1�2�3�	��
�
�3����	��	�s�
6�	A�Ac��|Sr$rrs r�	__enter__zShelf.__enter__�s���rc�$�|j�yr$)�close)r�typer?�	tracebacks    r�__exit__zShelf.__exit__�s���
�
�rc��|j�y	|j�	|jj�	t	�|_y#t$rY�wxYw#d|_YyxYw#	t	�|_w#d|_YwxYwxYwr$)r%�syncrI�AttributeErrorrrs rrIzShelf.close�s{���9�9���	!��I�I�K�
��	�	���!�
!�'�M��	��
"�
��
��
!� ��	��
!�'�M��	��
!� ��	�sK�A(�A�A�	A�A(�A�A(�	A%�(B�*A:�9B�:	B�Bc�>�t|d�sy|j�y)Nr')�hasattrrIrs r�__del__z
Shelf.__del__�s���t�[�)�
��
�
�rc��|jrH|jr<d|_|jj�D]
\}}|||<�d|_i|_t|jd�r|jj�yy)NFTrN)r'r(�itemsrQr%rN)rr6�entrys   rrNz
Shelf.sync�sn���>�>�d�j�j�"�D�N�"�j�j�.�.�0�
"�
��U�!��S�	�
"�!�D�N��D�J��4�9�9�f�%��I�I�N�N��&r�NFzutf-8r$)rrrrr,rrr7r:rrr rGrLrIrRrNrrrrrMsP���7<�$�'�-��9��
�?����!�"�rrc�:�eZdZdZ		d	d�Zd�Zd�Zd�Zd�Zd�Z	y)
ra�Shelf implementation using the "BSD" db interface.

    This adds methods first(), next(), previous(), last() and
    set_location() that have no counterpart in [g]dbm databases.

    The actual database must be opened using one of the "bsddb"
    modules "open" routines (i.e. bsddb.hashopen, bsddb.btopen or
    bsddb.rnopen) and passed to the constructor.

    See the module's __doc__ string for an overview of the interface.
    Nc�6�tj|||||�yr$)rr,r*s     rr,zBsdDbShelf.__init__�s��
���t�T�8�Y��Drc��|jj|�\}}t|�}|j|j�t|�j
�fSr$)r%�set_locationrr.r)rr=r>s    rrZzBsdDbShelf.set_location�sJ���y�y�-�-�c�2���e��E�N���
�
�4�+�+�,�i��l�.?�.?�.A�B�Brc��t|j�\}}t|�}|j|j�t|�j
�fSr$)�nextr%rr.r)rr=r>s    rr\zBsdDbShelf.next�sC���D�I�I����e��E�N���
�
�4�+�+�,�i��l�.?�.?�.A�B�Brc��|jj�\}}t|�}|j|j�t|�j
�fSr$)r%�previousrr.r)rr=r>s    rr^zBsdDbShelf.previous�sH���y�y�)�)�+���e��E�N���
�
�4�+�+�,�i��l�.?�.?�.A�B�Brc��|jj�\}}t|�}|j|j�t|�j
�fSr$)r%�firstrr.r)rr=r>s    rr`zBsdDbShelf.first�sF���y�y���(���e��E�N���
�
�4�+�+�,�i��l�.?�.?�.A�B�Brc��|jj�\}}t|�}|j|j�t|�j
�fSr$)r%�lastrr.r)rr=r>s    rrbzBsdDbShelf.last�sF���y�y�~�~�'���e��E�N���
�
�4�+�+�,�i��l�.?�.?�.A�B�BrrV)
rrrrr,rZr\r^r`rbrrrrr�s3��
�7<�$�E�C�
C�
C�
C�
Crrc��eZdZdZdd�Zy)r	z�Shelf implementation using the "dbm" generic dbm interface.

    This is initialized with the filename for the dbm database.
    See the module's __doc__ string for an overview of the interface.
    Nc�\�ddl}tj||j||�||�y)Nr)�dbmrr,r
)r�filename�flagr+r'res      rr,zDbfilenameShelf.__init__�s"���
���t�S�X�X�h��5�x��Kr��cNF)rrrrr,rrrr	r	�s
���Lrr	c��t||||�S)a�Open a persistent dictionary for reading and writing.

    The filename parameter is the base filename for the underlying
    database.  As a side-effect, an extension may be added to the
    filename and more than one file may be created.  The optional flag
    parameter has the same interpretation as the flag parameter of
    dbm.open(). The optional protocol parameter specifies the
    version of the pickle protocol.

    See the module's __doc__ string for an overview of the interface.
    )r	)rfrgr+r's    rr
r
�s���8�T�8�Y�?�?rrh)r�picklerrr�ior�collections.abc�collections�__all__�abc�MutableMappingrrrr	r
rrr�<module>rrsp��8�t8�7���
<��%�+�/�/�0�0�%�_�K�O�O�*�*�_�D(C��(C�V	L�e�	L�
@r

Zerion Mini Shell 1.0