← back to Atmos Game

assets/gen/.venv/lib/python3.12/site-packages/filelock/__pycache__/_read_write.cpython-312.pyc

222 lines

�

c�bj���t�UddlmZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZddlm
Z
mZmZmZmZmZddlmZddlmZmZmZmZmZmZddlmZe
r$dd	lmZm Z ejBd
k\rddlm"Z"nddl#m"Z"ejHd�Z%d
e&d<ejNZ(de&d<ejRjTdk(Z+de&d<e,ed�xr*ejRjTdk(xrejBdkZ-de&d<e.e/zej`e.zej`e/ze1ze2ze3ejhzdzZ5de&d<e6e2e2fZ7de&d<dZ8de&d<dZ9de&d<Gd �d!ejt�Z;e;�Z<d"e&d#<Gd$�d%�Z=e=�Z>d"e&d&<Gd'�d(�Z?e?�Z@d"e&d)<Gd*�d+ejh�ZAGd,�d-e3�ZBGd.�d/eB�0�ZCd8d1�ZDe
d9d2��ZEd:d3�ZFd;d4�ZGd<d5�ZHee>�ee@�eeC�e+rej�eG�e,ed�rej�eF�6�d/d7gZKy)=�)�annotationsN)�contextmanager�suppress)�
TYPE_CHECKING�ClassVar�Final�Literal�	TypeAlias�cast)�WeakValueDictionary�)�AcquireReturnProxy�_ensure_current_process�_fork_transition�_raise_chained_errors�_register_fork_class�_register_fork_object)�Timeout)�Callable�	Generator)��)�Self�filelockzFinal[logging.Logger]�_LOGGERzFinal[Callable[[], int]]�_GETPID�pypyzFinal[bool]�_IS_PYPY�register_at_fork�cpython)r��_NEEDS_CONNECTION_ESCROWr
�_ConnectionParameter�_DatabaseIdentityi��5wz
Final[int]�_MAX_SQLITE_TIMEOUT_MS�F�_UNSAFE_FORK_EXIT_STATUSc��eZdZUdZded<y)�_SQLiteTransitionContextr�int�depthN)�__name__�
__module__�__qualname__r+�__annotations__���k/Users/macstudio3/Projects/atmos-game/assets/gen/.venv/lib/python3.12/site-packages/filelock/_read_write.pyr)r)0s���E�3�Nr1r)r�_SQLITE_TRANSITION_CONTEXTc�(�eZdZdd�Z		dd�Zdd�Zy)�_ConnectionEscrowc�D�tj�|_d|_y�N)�	threading�RLock�_lock�
_functions��selfs r2�__init__z_ConnectionEscrow.__init__8s���_�_�&��
�tx��r1c� �tsy|j5|j��ddl}|j	d|j
�}|j
|jj|j�j}|j
|jj|j�j}|�|�
d}t|��t
d||��t
d||��f|_|jcddd�S#1swYyxYw)Nrz+CPython reference functions have no addressz$Callable[[sqlite3.Connection], None])
r"r:r;�ctypes�
PYFUNCTYPE�	py_objectr�	pythonapi�	Py_IncRef�c_void_p�value�	Py_DecRef�RuntimeError)r=r@�
function_type�increment_address�decrement_address�msgs      r2�	functionsz_ConnectionEscrow.functions<s���(��
�Z�Z����&�� &� 1� 1�$��8H�8H� I�
�$*�K�K��0@�0@�0J�0J�F�O�O�$\�$b�$b�!�$*�K�K��0@�0@�0J�0J�F�O�O�$\�$b�$b�!�$�,�0A�0I�G�C�&�s�+�+��?��O`�Aa�b��?��O`�Aa�b�#����?�?��Z�Z�s�C&D�D
c�6�tj�|_yr7)r8r9r:r<s r2�_reset_after_fork_in_childz,_ConnectionEscrow._reset_after_fork_in_childQs���_�_�&��
r1N��return�None)rQ�Xtuple[Callable[[sqlite3.Connection], None], Callable[[sqlite3.Connection], None]] | None)r,r-r.r>rMrOr0r1r2r5r57s��y�#�	a�#�*'r1r5�_CONNECTION_ESCROWc�F�eZdZdd�Zd	d�Zd
d�Zdd�Zdd�Zedd��Z	y)�_ForkedDatabaseRegistryc��tj�|_t�|_t�|_d|_d|_y�NF)r8r9r:�set�_paths�_identities�_sqlite_used�_all_paths_poisonedr<s r2r>z _ForkedDatabaseRegistry.__init__Ys3���_�_�&��
�),����36�5���!���#(�� r1c���|j|�}|j5|j}|xs$||jvxs|duxr||jv}ddd�rrdnd|�d�}t|��y#1swY�!xYw)NzOReadWriteLock is unavailable in a PyPy fork child; exec or exit before using itzSQLite database zD was active across fork(); exec or exit before using it in the child)�identityr:r]rZr[rH)r=�pathr_�all_paths_poisoned�poisonedrLs      r2�raise_if_poisonedz)_ForkedDatabaseRegistry.raise_if_poisoned`s����=�=��&��
�Z�Z�!%�!9�!9��"�t�d�d�k�k�&9�t�h�d�>R�>s�W_�cg�cs�cs�Ws�
��
�&�b�'��x�/s�t�
�
�s�#�#�
��Z�s�5A3�3A<c�v�|jj|�|�|jj|�yyr7)rZ�addr[)r=r`r_s   r2�poison_after_forkz)_ForkedDatabaseRegistry.poison_after_forkos1�������������� � ��*� r1c�b�tr|j5d|_ddd�yy#1swYyxYw�NT)rr:r\r<s r2�note_sqlite_usez'_ForkedDatabaseRegistry.note_sqlite_usets&������$(��!������s�%�.c��tj�|_|jxstxr|j
|_d|_yrX)r8r9r:r]rr\r<s r2rOz2_ForkedDatabaseRegistry._reset_after_fork_in_childys6���_�_�&��
�#'�#;�#;�#_��@^�T�M^�M^�� �!��r1c�r�	|j�}|j|jfS#t$rYywxYwr7)�stat�OSError�st_dev�st_ino)r`�stat_results  r2r_z _ForkedDatabaseRegistry.identity~s?��	��)�)�+�K��!�!�;�#5�#5�5�5���	��	�s�*�	6�6NrP)r`�pathlib.PathrQrR)r`rqr_�_DatabaseIdentity | NonerQrR)r`rqrQrr)
r,r-r.r>rcrfrirO�staticmethodr_r0r1r2rVrVXs/��)�
$�+�
)�
"�
�6��6r1rV�_FORKED_DATABASESc�b��eZdZUded<ded<						d	�fd�Zd
d�Z				dd�Zd
d�Z�xZS)�_ForkSafeConnectionr*�_creator_pidz+Callable[[sqlite3.Connection], None] | None�_decrement_escrowc�R��t�|�|�}t�|_d|_|Sr7)�super�__new__rrwrx)�cls�_args�_kwargs�
connection�	__class__s    �r2r{z_ForkSafeConnection.__new__�s+���
�W�_�S�)�
�")�)�
��'+�
�$��r1c�:�t�5t�|jk7r
	ddd�yt�5tj
j
|�|jx}�d|_||�ddd�ddd�y#1swY�xYw#1swYyxYwr7)�_sqlite_transitionrrwr�sqlite3�
Connection�closerx)r=�	decrements  r2r�z_ForkSafeConnection.close�s~��
�
!��y�D�-�-�-��"�
!�"�#��"�"�(�(��.�!%�!7�!7�7�I�D�-1�D�*��d�O�	$�"�
!�$�#��"�
!�s'�B�
B�=B�4B�B	�
B�Bc�2�|�|\}}||�||_yyr7)rx)r=rM�	incrementr�s    r2�acquire_escrowz"_ForkSafeConnection.acquire_escrow�s(��
� �#,� �I�y��d�O�%.�D�"�!r1c��ttjt�5|j	�ddd�y#1swYyxYwr7)rr��ErrorrHr�r<s r2�__del__z_ForkSafeConnection.__del__�s%��
�g�m�m�\�
2��J�J�L�3�
2�
2�s	�9�A)r}r#r~r#rQrrP)rMrSrQrR)	r,r-r.r/r{r�r�r��
__classcell__�r�s@r2rvrv�sQ�����B�B��$��(��
�	�$�/�k�/�
�/�r1rvc�t��eZdZUdZded<ded<ded<ded	<	dd
d
d�									d�fd�Zdd
�Z�xZS)�_ReadWriteLockMetaa

    Resolve singleton instances for ``is_singleton=True`` construction.

    This logic lives here rather than in ReadWriteLock.get_lock so ``ReadWriteLock(path)`` returns cached instances
    without a 2-arg ``super()`` call that type checkers cannot verify.

    �0WeakValueDictionary[pathlib.Path, ReadWriteLock]�
_instanceszthreading.RLock�_instances_lockr*�_instances_pidzset[pathlib.Path]�_instances_under_constructionT��blocking�is_singletonc	���t�|jt�k7r|j�t�}|s/t�
|�||||��}t�|k7r
d}t
|��|Stj|�j�}|j5||jvr�||jvrd|��}t
|��|j}	|	j|�	t�
|�||||��}t�|k(r|	j|�	t�|k7r
d}t
|��||j|<n|j|}|j|k7s|j |k7r-d|j�d|j �d|�d|��}t#|��|cddd�S#t�|k(r|	j|�wwxYw#1swYyxYw)Nr�z5ReadWriteLock construction cannot continue after forkz2Singleton lock construction is already active for z$Singleton lock created with timeout=z, blocking=z, cannot be changed to timeout=)rr�r�_reset_class_after_forkrz�__call__rH�pathlib�Path�resolver�r�r�re�discard�timeoutr��
ValueError)r|�	lock_filer�r�r��construction_pid�instancerL�
normalized�construction_registryr�s          �r2r�z_ReadWriteLockMeta.__call__�s����	 �!������*��'�'�)�"�9����w�'�	�7�X�\h�'�i�H��y�,�,�M��"�3�'�'��O��\�\�)�,�4�4�6�
�
�
 �
 �����/���!B�!B�B�N�y�m�\�C�&�s�+�+�(+�(I�(I�%�%�)�)�*�5�B�$�w�/�	�7�X�dp�/�q�H��y�$4�4�-�5�5�j�A��9� 0�0�Q�C�&�s�+�+�-5����z�*��>�>�*�5�����7�*�h�.?�.?�8�.K�:�8�;K�;K�:L�K�X`�Xi�Xi�Wj�k5�5<�I�[��
�T��!��o�%��3!�
 ���y�$4�4�-�5�5�j�A�5��!�
 �s&�A
G
�(F)�;B$G
�)!G
�
G
�
Gc��t�|_tj�|_t�|_t�|_yr7)	rr�r8r9r�rr�rYr�)r|s r2r�z*_ReadWriteLockMeta._reset_class_after_fork�s/��,�.���'�o�o�/���$�Y���,/�E��)r1������)
r��str | os.PathLike[str]r��floatr��boolr�r�rQ�
ReadWriteLockrP)r,r-r.�__doc__r/r�r�r�r�s@r2r�r��sp����A�@�$�$���#4�4�
�-�
�!�
-�)�-��-�
�-��
-�
�-�^2r1r�c����eZdZUdZe�Zded<ej�Z	e
�Ze�Z
ded<d%�fd�Ze	d&dd�							d'd	��Z	d&ddd
�									d(d�Zd&dd�d)d�Zd&dd�d)d
�Zed*dd�d+d��Zed*dd�d+d��Zdd�d,d�Zd%d�Zd-d�Zd%d�Zd%d�Zd%d�Zed.d��Zd%d�Zd/d�Z 												d0d�Z!d1d�Z"										d2d�Z#d3d�Z$d%d �Z%d4d!�Z&d5d"�Z'd6d#�Z(d7d$�Z)�xZ*S)8r�ap
    Cross-process read-write lock backed by SQLite.

    Allows concurrent shared readers or a single exclusive writer. The lock is reentrant within the same mode (multiple
    ``acquire_read`` calls nest, as do multiple ``acquire_write`` calls from the same thread), but upgrading from read
    to write or downgrading from write to read raises :class:`RuntimeError`. Write locks are pinned to the thread that
    acquired them.

    By default, ``is_singleton=True``: calling ``ReadWriteLock(path)`` with the same resolved path returns the same
    instance. The path is handed to :func:`sqlite3.connect` as given, so a ``.db`` extension is a convention rather
    than a requirement; the filesystem must be one the active SQLite VFS supports.

    :param lock_file: path to the SQLite database file used as the lock
    :param timeout: maximum wait time in seconds; ``-1`` means block indefinitely
    :param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately when the lock is unavailable
    :param is_singleton: if ``True``, reuse existing instances for the same resolved path

    .. versionadded:: 3.21.0

    r�r�zClassVar[set[pathlib.Path]]r�c����t�|��t�|_t	j
�|_t�|_t�|_
t|�yr7)rz�__init_subclass__rr�r8r9r�rr�rYr�r)r|r�s �r2r�zReadWriteLock.__init_subclass__sC���
��!�#�,�.���'�o�o�/���$�Y���,/�E��)��S�!r1T�r�c��||||��S)a	
        Return the singleton :class:`ReadWriteLock` for *lock_file*.

        :param lock_file: path to the SQLite database file used as the lock
        :param timeout: maximum wait time in seconds; ``-1`` means block indefinitely
        :param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately when the lock is unavailable

        :returns: the singleton lock instance

        :raises ValueError: if an instance already exists for this path with different *timeout* or *blocking* values

        r�r0)r|r�r�r�s    r2�get_lockzReadWriteLock.get_locks�� �9�g��9�9r1r�c���tj|�|_tj|�j�|_tj|j�||_	||_
tj�|_
tj�|_d|_d|_d|_t%�|_d|_d|_d|_d|_t1�|_d|_t7|�t9�5t;�5|j=d��}|j?�ddd�ddd�y#1swY�xYw#1swYyxYw)NrTFg@��sqlite_timeout) �os�fspathr�r�r�r��_canonical_pathrtrcr�r�r8�Lock�_transaction_lock�_internal_lock�_lock_level�
_current_mode�_write_thread_idrY�_acquisition_thread_ids�_con� _connection_transaction_released�_connection_identity�_closedrrw�_fork_invalidatedrrr��_open_connectionr�)r=r�r�r�r��validation_connections      r2r>zReadWriteLock.__init__*s
�����9�-���&�|�|�I�6�>�>�@����+�+�D�,@�,@�A���� ��
�!*���!1���'�n�n�.������>B���,0���14���$�04��	�04��-�>B��!����#�I���!&����d�#�
�
�!3�!5�$(�$9�$9��$9�$M�!�!�'�'�)�"6�
�
�!5�!5��
�
�s$�
E�#E�;E�E	�E�E!c�*�|jd||��S)a�
        Acquire a shared read lock.

        If this instance already holds a read lock, the lock level is incremented (reentrant). Attempting to acquire a
        read lock while holding a write lock raises :class:`RuntimeError` (downgrade not allowed).

        :param timeout: maximum wait time in seconds; ``-1`` means block indefinitely
        :param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately when the lock is unavailable

        :returns: a proxy that can be used as a context manager to release the lock

        :raises RuntimeError: if a write lock is already held on this instance
        :raises Timeout: if the lock cannot be acquired within *timeout* seconds

        �readr���_acquire�r=r�r�s   r2�acquire_readzReadWriteLock.acquire_readHs�� �}�}�V�W�x�}�@�@r1c�*�|jd||��S)a�
        Acquire an exclusive write lock.

        If this instance already holds a write lock from the same thread, the lock level is incremented (reentrant).
        Attempting to acquire a write lock while holding a read lock raises :class:`RuntimeError` (upgrade not allowed).
        Write locks are pinned to the acquiring thread: a different thread trying to re-enter also raises
        :class:`RuntimeError`.

        :param timeout: maximum wait time in seconds; ``-1`` means block indefinitely
        :param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately when the lock is unavailable

        :returns: a proxy that can be used as a context manager to release the lock

        :raises RuntimeError: if a read lock is already held, or a write lock is held by a different thread
        :raises Timeout: if the lock cannot be acquired within *timeout* seconds

        �writer�r�r�s   r2�
acquire_writezReadWriteLock.acquire_writeZs��$�}�}�W�g��}�A�Ar1Nc#�K�|�|j}|�|j}|j||��	d��|j�y#|j�wxYw�w)a}
        Context manager that acquires and releases a shared read lock.

        Falls back to instance defaults for *timeout* and *blocking* when ``None``.

        :param timeout: maximum wait time in seconds, or ``None`` to use the instance default
        :param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default

        Nr�)r�r�r��releaser�s   r2�	read_lockzReadWriteLock.read_locknsR�����?��l�l�G����}�}�H����'�H��5�	���L�L�N��D�L�L�N���0A�A�A�A�Ac#�K�|�|j}|�|j}|j||��	d��|j�y#|j�wxYw�w)a�
        Context manager that acquires and releases an exclusive write lock.

        Falls back to instance defaults for *timeout* and *blocking* when ``None``.

        :param timeout: maximum wait time in seconds, or ``None`` to use the instance default
        :param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default

        Nr�)r�r�r�r�r�s   r2�
write_lockzReadWriteLock.write_lock�sR�����?��l�l�G����}�}�H����7�X��6�	���L�L�N��D�L�L�N�r�F)�forcec���t�5t�|jr
	ddd�y|jd�|j	|d��ddd�y#1swYyxYw)al
        Release one level of the current lock.

        When the lock level reaches zero the underlying SQLite transaction is rolled back, releasing the database lock.

        :param force: if ``True``, release the lock completely regardless of the current lock level

        :raises RuntimeError: if no lock is currently held and *force* is ``False``

        Nr�F�r�r��rr�
_inherited�_raise_if_acquiring�_release)r=r�s  r2r�zReadWriteLock.release�sN���
�#�%����� �
�
�$�$�Y�/��M�M��U�M�3� �
�
���A�$A�A"c���t�5t�|jr
	ddd�y|jd�|j	dd��ddd�y#1swYyxYw)z�
        Release the lock (if held) and close the underlying SQLite connection.

        After calling this method, the lock instance is no longer usable.

        Nr�Tr�r�r<s r2r�zReadWriteLock.close�sN���
�#�%����� �
�
�$�$�W�-��M�M��D�M�1� �
�
�r�c�v�|j5|j5|jdk(rR|r'|j�|rd|_	ddd�ddd�y|s'd|j
�dt
|��d�}t|��|s6|jdkDr'|xjdzc_	ddd�ddd�y	|j�|j�|rd|_ddd�ddd�y#tj$r|jr|j��wxYw#1swY�FxYw#1swYyxYw)NrTzCannot release a lock on � (lock id: z) that is not heldr
)
r�r�r�r�r�r��idrH�_finish_connectionr�r�r��_clear_lock_state)r=r�r�rLs    r2r�zReadWriteLock._release�s��
�
#�
#�T�%8�%8����1�$��T�Y�Y�.��'+����&9�
#�
#��5�d�n�n�5E�[�QS�TX�QY�PZ�Zl�m�C�&�s�+�+��T�-�-��1�� � �A�%� ��&9�
#�
#�
��'�'�)�

�"�"�$��#���)&9�
#�
#���=�=�
��8�8��*�*�,��
��&9�%8��
#�
#�sM�
D/�(D#�D/�AD#�#D/�5C/�D#�D/�/1D � D#�#D,	�(D/�/D8c�.�d|_d|_d|_y)Nr)r�r�r�r<s r2r�zReadWriteLock._clear_lock_state�s�����!��� $��r1c���t�t|dd�k(rHt|dd�x}�8ttjt
�5|j
�ddd�yyy#1swYyxYw)Nrwr�)r�getattrrr�r�rHr�)r=rs  r2r�zReadWriteLock.__del__�s^���9���n�d�;�;�w�W[�]c�ei�Oj�Aj��@w��'�-�-��6�� � �"�7�6�Ax�;�6�6�s�A"�"A+c�J�|j�*tj|j|j�d|_d|_d|_t
j�|_t
j�|_	|j�t�|_d|_
yrh)r�rtrfr�r�r�r8r�r�r�r�rYr�r�r<s r2rOz(ReadWriteLock._reset_after_fork_in_child�s{���9�9� ��/�/��0D�0D�d�F_�F_�`���	�04��-�$(��!�!*���!1���'�n�n�.������ �'*�u��$�!%��r1c�L�|jxst�|jk7Sr7)r�rrwr<s r2r�zReadWriteLock._inherited�s ���%�%�G���d�6G�6G�)G�Gr1c��t�|jrd|j�d�}t|��|jrd}tj|��y)N�ReadWriteLock on �4 was invalidated by fork(); construct a new instancez$Cannot operate on a closed database.)rr�r�rHr�r��ProgrammingError)r=rLs  r2�_raise_if_unusablez ReadWriteLock._raise_if_unusable�sP���!��?�?�%�d�n�n�%5�5i�j�C��s�#�#��<�<�8�C��*�*�3�/�/�r1c	���t�5|j�t�}tj�}|j
5|jdkDr#|j|�cddd�cddd�S||jvrd|j�d�}t|��|jj|�ddd�	tj�}|j||��	|j�|j|||||��|j j#�|j
5|jj%|�ddd�cddd�S#1swY��xYw#1swY�xYw#|j j#�wxYw#|j
5|jj%|�ddd�w#1swYwxYwxYw#1swYyxYw)Nrz Cannot acquire ReadWriteLock on �+ while acquisition is active in this thread�r�r��r��
operation_pid�
start_time)rr�rr8�	get_identr�r��_validate_reentrantr�r�rHre�time�perf_counter�_acquire_transaction_lock�_do_acquire_innerr�r�r�)r=�moder�r�r��	thread_idrLr�s        r2r�zReadWriteLock._acquire�s���
�
��#�#�%�#�I�M�!�+�+�-�I��$�$��#�#�a�'��3�3�D�9�%�$�	 �
��� <� <�<�<�T�^�^�<L�Lw�x�C�&�s�+�+��,�,�0�0��;�
%�
D�!�.�.�0�
��.�.��'�.�R�
5��+�+�-��1�1���!)�&3�#-�2���*�*�2�2�4��(�(��0�0�8�8��C�)�5 �
�%�$��,)�(���*�*�2�2�4���(�(��0�0�8�8��C�)�(�(��5 �
�s��;G� E'�&	G�9AE'�=G�'F�.%E?�F�-G�9E3�G�'E0	�,G�3E<�8G�?F�F�
G�+G	�	G�G
�G�G�G(c�L�|j5|jdkDr|j|�cddd�S	ddd�|j�|j	�	|j||||��|j
|||||f��|j|�|j5|j|�||_d|_|dk(rt%j&�|_ddd�t+|��S#1swY��xYw#t$r�}t|tj�r#dt|�vrt|j�}n|}	|j	�n,#tj$r}t!||�Yd}~nd}~wwxYw||ur|d��d}~wwxYw#1swY��xYw)Nrr�)r��	operationzdatabase is lockedr
r���lock)r�r�r�r�r��_open_for_acquisition�_configure_and_begin�_raise_if_process_changed�
BaseException�
isinstancer��OperationalError�strrr�r�rr�r8r�r�r)	r=r�r�r�r�r��error�acquisition_error�
cleanup_errors	         r2r�zReadWriteLock._do_acquire_inners����
 �
 ����!�#��/�/��5�!�
 �#�!��9�9� ��#�#�%�	��&�&��!�+�%�	
'�
�
�%�%���!�(�*�5�	
&�
�
�*�*�=�9��
 �
 ��*�*�=�9�!%�D�� �D���w��(1�(;�(;�(=��%�!�"�t�,�,�M!�
 ��&�	��%��!9�!9�:�?S�WZ�[`�Wa�?a�$+�D�N�N�$;�!�$)�!�
H��'�'�)���=�=�
H�%�&7��G�G��
H�� ��-�'�T�1���	��!�
 �sY� C8�=D�&>F�8D�	F�
?F�
E�F�F�1F�=F�F�F�F�F#c�:�t�5t||tj�|z
��dz}|j	|��}|dt
j
|j�c|_|_	|_
|j|�ddd�y#1swYyxYw)N�r��already_waited��r�F)r��timeout_for_sqliter�r�r�rtr_r�r�r�r�r)r=r�r�r�r�r�rs       r2rz#ReadWriteLock._open_for_acquisitionBs���
�
!�"��%�#'�#4�#4�#6��#C��
��
��.�.�n�.�M�J���!�*�*�4�+?�+?�@�
X�D�I�t�<�d�>W�

�*�*�=�9�"�
!�
!�s�A=B�Bc��t�5|\}}td|j�}tj�|z
}t|||��}	|j
|�|jd|	�d��j�tj�|z
}t|||��}
|j
|�|
|	k7rd|
�d�nd}||dk(rdnd	z
}|d
k(r|dz
}|j|�j�ddd�y#1swYyxYw)Nrvr
zPRAGMA busy_timeout=z; PRAGMA journal_mode=MEMORY;z; �r�zBEGIN EXCLUSIVE TRANSACTION;zBEGIN TRANSACTION;r�z( SELECT name FROM sqlite_schema LIMIT 1;)	r�rr�r�r�rr�
executescriptr�)r=r�r�r�r�r�r�r�waited�
timeout_ms�
recomputed�
statementss            r2rz"ReadWriteLock._configure_and_beginTs�� �
!�(1�%�M�:��3�T�Y�Y�?�J��&�&�(�:�5�F�+�G�h�W]�^�J��*�*�=�9��$�$�';�J�<�Gd�%e�f�l�l�n��&�&�(�:�5�F�+�G�h�W]�^�J��*�*�=�9�BL�PZ�BZ�/�
�|�2�>�`b�J��D�G�O�8�Qe�e�J��v�~��H�H�
��$�$�Z�0�6�6�8�-"�
!�
!�s�C-D�D
c���t�5t�}tj�}t�|k7r
d}t	|��tt
j|j�t|��}|�|j|�t�|k7rJtj|jtj|j��d}t	|��|cddd�S#1swYyxYw)Nz9SQLite connection construction cannot continue after fork)�factoryr�)r�rrTrMrH�_connectr�r�r�rvr�rtrfr_)r=r��creator_pidrMrLrs      r2r�zReadWriteLock._open_connectionts���
�
!�!�)�K�*�4�4�6�I��y�K�'�Q��"�3�'�'�!��	�	�$�.�.�/�+�&��J�
�$��)�)�)�4��y�K�'�!�3�3��(�(�%�.�.�t�/C�/C�D��R��"�3�'�'��)"�
!�
!�s�CC(�(C1c���t�5|jx}�
	ddd�yd}|js,|jr	|j	�d|_nd|_	|j�d|_d|_d|_	|�|�	ddd�y#t
j$r }|jr�d|_|}Yd}~�bd}~wwxYw#t
j$r}|�t||��d}~wwxYw#1swYyxYwrh)
r�r�r��in_transaction�rollbackr�r�r�rr�)r=r�rollback_errorr	�close_errors     r2r�z ReadWriteLock._finish_connection�s��
�
!�"�i�i�'�
�0��"�
!�48�N��8�8��,�,�E�"�+�+�-�AE��=�<@�D�9�
�� � �"�
�D�I�48�D�1�(,�D�%��)�$�$�*�5"�
!��#�=�=�/�%�4�4�!�@D��=�).���	/���=�=�
�!�-�)�.�+�F���
��'"�
!�s]�C2�C2�B�C2�C�/C2�C�%C�;C2�C�C2�C/�C*�*C/�/C2�2C;c��|j|k7rB|dk(rdnd}|dk(rdnd}d|�d|j�dt|��d|�d	|�d
�}t|��|dk(rYt	j
�x}|jk7r6d|j�dt|��d|�d
|j��}t|��|xjdz
c_t|��S)Nr�r��	downgrade�upgradezCannot acquire z	 lock on r�z): already holding a z lock (z
 not allowed)zCannot acquire write lock on z) from thread z while it is held by thread r
r)	r�r�r�rHr8r�r�r�r)r=r��opposite�	directionrL�curs      r2r�z!ReadWriteLock._validate_reentrant�s�������%�"&�&�.�w�f�H�'+�v�~��9�I�!�$��y����0@��B�t�H�:�V%�%-�J�g�i�[�
�O�
��s�#�#��7�?�y�':�':�'<� <���AV�AV�V�/����/?�{�2�d�8�*�U�"�e�#?��@U�@U�?V�X�
��s�#�#����A���!�t�,�,r1c���|s|jjd��}n?|dk(r|jjd��}n|jjd|��}|st|j�d�y)NFr�r�Tr�)r��acquirerr�)r=r�r��acquireds    r2r�z'ReadWriteLock._acquire_transaction_lock�sr����-�-�5�5�u�5�E�H�
��]��-�-�5�5�t�5�D�H��-�-�5�5�t�W�5�U�H���$�.�.�)�t�3�r1c���|j5tj�|jv}ddd�rd|�d|j�d�}t|��y#1swY�*xYw)NzCannot z ReadWriteLock on r�)r�r8r�r�r�rH)r=r��active_in_current_threadrLs    r2r�z!ReadWriteLock._raise_if_acquiring�sa��
�
 �
 �'0�':�':�'<��@\�@\�'\�$�!�#��I�;�&8����8H�Hs�t�C��s�#�#�$�!�
 �s�!A�A c�l�t�|k7s|jrd|j�d�}t|��y)Nr�r�)rr�r�rH)r=r�rLs   r2rz'ReadWriteLock._raise_if_process_changed�s6���9�
�%����%�d�n�n�%5�5i�j�C��s�#�#�*9r1rPr�)r�r�r�r�r�r�rQr�)
r�r�r�r�r�r�r�r�rQrR)r�r�r�r�rQrr7)r�zfloat | Noner�zbool | NonerQ�Generator[None])r�r�rQrR)r�r�r�r�rQrR)rQr�)r��Literal['read', 'write']r�r�r�r�rQr)r�r.r�r�r�r�r�r*r�r�rQr)
r�r�r�r�r�r*r�r�rQrR)
r�r.r�r�r�r�r�ztuple[int, float]rQrR)r�r�rQrv)r�r.rQr)r�r�r�r�rQrR)r�z&Literal['acquire', 'close', 'release']rQrR)r�r*rQrR)+r,r-r.r�rr�r/r8r9r�rr�rYr�r��classmethodr�r>r�r�rr�r�r�r�r�r�r�rO�propertyr�r�r�r�rrr�r�r�r�r�rr�r�s@r2r�r��s�����*DW�CX�J�@�X�%�i�o�o�'�O��Y�N�AD��!�#>�F�"��AC�:�Y]�:�.�:�9>�:�RV�:�	�:��:�(�*�
�!�
*�)�*��*�
�*��
*�
�*�<A�D�A�$B�T�B�(��QU����(��RV����((-�4�$2�$�.%�
#�

&��H��H�0�D�<0-�&�0-��0-�
�0-��
0-��0-�
�0-�d:�$9�&�9��9�
�9�%�
9�
�9�@�.%�<-�$4�$�$r1r�)�	metaclassc�^�tj�tj|d|d|��S)NFr)�check_same_threadr�cached_statementsr�)rtrir��connect)�databaserr�s   r2rr�s.���%�%�'��?�?�������r1c#�K�txjdz
c_	d��txjdzc_y#txjdzc_wxYw�w)Nr
)r3r+r0r1r2r�r��sB�����$�$��)�$�.�
�"�(�(�A�-�(��"�(�(�A�-�(�s�A�;�A�A�Ac�X�tjrtjt�yyr7)r3r+r��_exitr'r0r1r2�_abort_forked_sqlite_transitionr:�s��!�'�'�
���)�*�(r1c�8�|dk(rtj�yy)Nzsqlite3.connect)rtri)�eventr}s  r2�_track_sqlite_user=�s���!�!��)�)�+�"r1c���|dury|dk(rtS|dkr
d}t|��t|dkDrt||z
d�n|dz�}|tkDs|dkr!tjd|t�tS|S)NFrr�z+timeout must be a non-negative number or -1rz7timeout %s is too large for SQLite, using %s ms instead)r%r�r*�maxr�warning)r�r�rrLrs     r2rr�s����5����"�}�%�%���{�;����o���'�A�+�c�'�N�2�A�6�7�VZ�Z�[�J��*�*�j�1�n����Q�SZ�\r�s�%�%��r1)�after_in_childr)r6rrztype[_ForkSafeConnection]r�r�rQrv)rQr-rP)r<rr}ztuple[object, ...]rQrR)r�r�r�r�rr�rQr*)L�
__future__r�loggingr�r�r��sysr8r��
contextlibrr�typingrrrr	r
r�weakrefr�_apirrrrrr�_errorr�collections.abcrr�version_infor�typing_extensions�	getLoggerrr/�getpidr�implementation�namer�hasattrr"r�bytes�PathLiker�r*�typer�r#�tupler$r%r'�localr)r3r5rTrVrtrvr�r�rr�r:r=r�addaudithookr�__all__r0r1r2�<module>rYs[��"��	���
���/�K�K�'�����3�
���7�"��*�!2��!2�!2�:�!>��	�>�$&�I�I��	!�-��*�*�/�/�6�9��+�9��B�"�#�k��(:�(:�(?�(?�9�(L�k�QT�Qa�Qa�dk�Qk��+���%�K�"�+�+�c�"�"�R�[�[��%7�7�%�?�#�E��W�M_�M_�H`�`�cg�g��i�� %�S�#�X���9�.�&7��
�6�')��*�)��y����%=�$>��E�>�'�'�<.�/��E�/�,6�,6�^3�4��5�4�$�'�,�,�$�NA2��A2�HZ$�0�Z$�z��.��.�+�
,�
�$�(�)��'�(��]�#���C���&�'�
�2�!�"��B���'F�G����r1