AlkantarClanX12

Your IP : 18.224.55.63


Current Path : /opt/alt/python311/lib64/python3.11/dbm/__pycache__/
Upload File :
Current File : //opt/alt/python311/lib64/python3.11/dbm/__pycache__/dumb.cpython-311.opt-1.pyc

�

c��fJ-��r�dZddlZddlZddlZddlZddgZ	dZ
eZGd�dej
j��Zdd
�ZdS)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�ZdS)�	_Database�cc��|j�|��}||_|dk|_|dz|_|dz|_|dz|_d|_|�|��|�	|��dS)N�rs.dirs.dats.bak)
�_os�fsencode�_mode�	_readonly�_dirfile�_datfile�_bakfile�_index�_create�_update)�self�filebasename�mode�flags    �//opt/alt/python311/lib64/python3.11/dbm/dumb.py�__init__z_Database.__init__0s����x�(�(��6�6����
��#�+���%�w�.��
�%�w�.��
�$�w�.��
����	
���T�������T������c��|dkr<|j|j|jfD]'}	tj|���#t
$rY�$wxYw	t
j|jdd���}|���dS#t
$rY|dvr�t
j|jdd���5}|�	|j��ddd��YdS#1swxYwYYdSwxYw)N�nr	�Latin-1��encoding�rr�w)
rrrr
�remove�OSError�_ior�close�_chmod)rr�filename�fs    rrz_Database._createJsR���3�;�;�!�]�D�M�4�=�I�
�
����J�x�(�(�(�(�������D�����	������i�@�@�@�A�
�G�G�I�I�I�I�I��
�	+�	+�	+��:�%�%����$�-��y�A�A�A�
+�Q����D�M�*�*�*�
+�
+�
+�
+�
+�
+�
+�
+�
+�
+�
+�
+�
+����
+�
+�
+�
+�
+�
+�
+�	+���sD�3�
A�A�A6�6+C�!C
�<C�
C	�C�C	�C�Cc�l�d|_i|_	tj|jdd���}|5|D]L}|���}t
j|��\}}|�d��}||j|<�M	ddd��dS#1swxYwYdS#t$r|dvr�d|_YdSwxYw)NFr	rrr T)
�	_modifiedrr$rr�rstrip�_ast�literal_eval�encoder#)rrr(�line�key�pos_and_siz_pairs      rrz_Database._update]s(��������	8������i�@�@�@�A��
8�
8��8�8�D��;�;�=�=�D�,0�,=�d�,C�,C�)�C�)��*�*�Y�/�/�C�'7�D�K��$�$�	8�
8�
8�
8�
8�
8�
8�
8�
8�
8�
8�
8�
8����
8�
8�
8�
8�
8�
8���	"�	"�	"��:�%�%��!�D�N�N�N�N�	"���s#�B�AB�B�B�B3�2B3c�@�|j�|jsdS	|j�|j��n#t
$rYnwxYw	|j�|j|j��n#t
$rYnwxYw|j�	|jdd���5}|�
|j��|j���D]5\}}|�d���d|�d�}|�
|���6	ddd��dS#1swxYwYdS)Nr!rr�, �
)rr*r
�unlinkrr#�renamerr$rr&�items�decode�write)rr(r0r1�entrys     r�_commitz_Database._commitqs����;��d�n���F�	��H�O�O�D�M�*�*�*�*���	�	�	��D�	����	��H�O�O�D�M�4�=�9�9�9�9���	�	�	��D�	�����X�]�]�4�=�#�	�]�
B�
B�	�a��K�K��
�&�&�&�)-��):�):�)<�)<�
�
�%��%�'*�j�j��&;�&;�&;�&;�=M�=M�=M�N����������	
�	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s1�2�
?�?�%A)�)
A6�5A6�A*D�D�Dc�2�|j�td���dS�N�"DBM object has already been closed)rr�rs r�_verify_openz_Database._verify_open�s!���;���<�=�=�=��rc�Z�t|t��r|�d��}|���|j|\}}tj|jd��5}|�|��|�	|��}ddd��n#1swxYwY|S)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�d�m�T�
*�
*�	�a�
�F�F�3�K�K�K��&�&��+�+�C�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	��
s�)+B � B$�'B$c��tj|jd��5}|�dd��t	|�����}|tzdz
tztz}|�d||z
z��|}|�|��ddd��n#1swxYwY|t|��fS)N�rb+r���)	r$rrrF�int�tell�
_BLOCKSIZEr9�len)r�valr(rH�nposs     r�_addvalz_Database._addval�s���
�X�d�m�U�
+�
+�	�q�
�F�F�1�a�L�L�L��a�f�f�h�h�-�-�C��:�%��)�j�8�J�F�D�
�G�G�E�4��8�$�%�%�%��C�
�G�G�C�L�L�L�
	�	�	�	�	�	�	�	�	�	�	����	�	�	�	��S��X�X��s�BB.�.B2�5B2c���tj|jd��5}|�|��|�|��ddd��n#1swxYwY|t|��fS)NrM)r$rrrFr9rT)rrHrUr(s    r�_setvalz_Database._setval�s���
�X�d�m�U�
+�
+�	�q�
�F�F�3�K�K�K�
�G�G�C�L�L�L�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	��S��X�X��s�+A�A�Ac��||j|<tj|jdd���5}|�|j��|�|�d���d|�d���ddd��dS#1swxYwYdS)N�arrr3r4)rr$rrr&r9r8)rr0r1r(s    r�_addkeyz_Database._addkey�s���+���C��
�X�d�m�S�9�
=�
=�
=�	L���K�K��
�&�&�&�
�G�G�#�*�*�Y�"7�"7�"7�"7�9I�9I�9I�J�K�K�K�	L�	L�	L�	L�	L�	L�	L�	L�	L�	L�	L�	L����	L�	L�	L�	L�	L�	Ls�A	A=�=B�Bc�<�|jrtd���t|t��r|�d��}n+t|t
tf��std���t|t��r|�d��}n+t|t
tf��std���|���d|_	||j
vr+|�||�|����dS|j
|\}}|tzdz
tz}t|��tzdz
tz}||kr |�||��|j
|<dS|�|��|j
|<dS)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����>�	C��A�B�B�B��c�3���	=��*�*�W�%�%�C�C��C�%��!3�4�4�	=��;�<�<�<��c�3���	?��*�*�W�%�%�C�C��C�%��!3�4�4�	?��=�>�>�>�����������d�k�!�!��L�L��d�l�l�3�/�/�0�0�0�0�0��{�3�'�H�C���z�)�A�-�*�<�I��S���J�.��2�z�A�I��I�%�%�#'�<�<��S�#9�#9���C� � � �
$(�<�<��#4�#4���C� � � rc���|jrtd���t|t��r|�d��}|���d|_|j|=|���dS)Nr^rBT)	r
rrDrEr.r@r*rr;�rr0s  r�__delitem__z_Database.__delitem__�su���>�	C��A�B�B�B��c�3���	&��*�*�W�%�%�C�����������K���
	
�������rc�h�	t|j��S#t$rtd��d�wxYwr=)�listrrarr?s r�keysz_Database.keys��H��	H����$�$�$���	H�	H�	H��<�=�=�4�G�	H������1c�v�������fd��j���D��S)Nc�$��g|]}|�|f��
S�ro)�.0r0rs  �r�
<listcomp>z#_Database.items.<locals>.<listcomp>�s"���?�?�?�S��d�3�i� �?�?�?r)r@rrjr?s`rr7z_Database.items�s=���������?�?�?�?�D�K�,<�,<�,>�,>�?�?�?�?rc��t|t��r|�d��}	||jvS#t$r|j�td��d��wxYw)NrBr>)rDrEr.rrarrfs  r�__contains__z_Database.__contains__�sn���c�3���	&��*�*�W�%�%�C�	��$�+�%�%���	�	�	��{�"��@�A�A�t�K��		���s	�5�#Ac�h�	t|j��S#t$rtd��d�wxYwr=)�iterrrarr?s r�iterkeysz_Database.iterkeysrkrlc�h�	t|j��S#t$rtd��d�wxYwr=)rTrrarr?s r�__len__z_Database.__len__sH��	H��t�{�#�#�#���	H�	H�	H��<�=�=�4�G�	H���rlc��	|���dx|_x|_x|_|_dS#dx|_x|_x|_|_wxYw�N)r;rrrrr?s rr%z_Database.closes]��	O��L�L�N�N�N�JN�N�D�K�N�$�-�N�$�-�$�-�-�-��$�N�D�K�N�$�-�N�$�-�$�-�N�N�N�Ns	�4�Ac�F�|j�||j��dSrz)r
�chmodr)r�files  rr&z_Database._chmods ������t�T�Z�(�(�(�(�(rc��|Srzror?s r�	__enter__z_Database.__enter__s���rc�.�|���dSrz)r%)r�argss  r�__exit__z_Database.__exit__s���
�
�����rN)r)�__name__�
__module__�__qualname__r
r$rrrr;�syncr@rKrWrYr\rdrgrjr7rsrv�__iter__rxr%�__del__r&rr�rorrrr#sy�������C�

�C�����4���&8�8�8�(���2�D�>�>�>����������L�L�L�5�5�5�J
�
�
�H�H�H�@�@�@�	�	�	�H�H�H�
�H�H�H�H�O�O�O��G�)�)�)��������rrr�c���	tjd��}tj|��||z}n#t$rYnwxYw|dvrtd���t	|||���S)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)r	r!rrz)Flag must be one of 'r', 'w', 'c', or 'n')r)r
�umask�AttributeError�
ValueErrorr)r}rr�ums    rrr#s��� �
�Y�q�\�\���	�"�
�
�
�
��s�|����	�
�
�
���
����
�'�'�'��D�E�E�E��T�4�d�+�+�+�+s�(1�
>�>)rr�)�__doc__�astr,�ior$�osr
�collections.abc�collections�__all__rSr#r�abc�MutableMappingrrrorr�<module>r�s�����.�����������������F�
��
�
���}�}�}�}�}���.�}�}�}�@,�,�,�,�,�,r