
    1jq                       U d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	m
Z
mZ d dlmZmZmZmZmZmZ d dlmZ ddlmZmZmZmZmZmZ ddlmZ er*d d	lmZm Z  d d
l!m"Z" ejF                  dk\  rd dlm$Z$ nd dl%m$Z$  ejL                  d      Z'de(d<   ejR                  Z*de(d<   ejV                  jX                  dk(  Z-de(d<    e.ed      xr* ejV                  jX                  dk(  xr ejF                  dk  Z/de(d<   e0e1z  ejd                  e0   z  ejd                  e1   z  e3z  e4z  e5ejl                     z  dz  Z7de(d<   e8e4e4f   Z9de(d<   dZ:de(d<   dZ;de(d <    G d! d"ejx                        Z= e=       Z>d#e(d$<    G d% d&      Z? e?       Z@d#e(d'<    G d( d)      ZA eA       ZBd#e(d*<    G d+ d,ejl                        ZC G d- d.e5      ZD G d/ d0eD1      ZEd9d2ZFe
d:d3       ZGd;d4ZHd<d5ZId=d6ZJ ee@        eeB        eeE       e-r ej                  eI        e.ed      r ej                  eH7       d0d8gZMy)>    )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)Unused)      )SelffilelockzFinal[logging.Logger]_LOGGERzFinal[Callable[[], int]]_GETPIDpypyzFinal[bool]_IS_PYPYregister_at_forkcpython)r      _NEEDS_CONNECTION_ESCROWr
   _ConnectionParameter_DatabaseIdentityi5wz
Final[int]_MAX_SQLITE_TIMEOUT_MSF   _UNSAFE_FORK_EXIT_STATUSc                      e Zd ZU dZded<   y)_SQLiteTransitionContextr   intdepthN)__name__
__module____qualname__r,   __annotations__     /home/vela/workspace/domain/tn-silver/web/tn-site/.runtime/depth-eval/venv/lib/python3.12/site-packages/filelock/_read_write.pyr*   r*   2   s    E3Nr2   r*   r   _SQLITE_TRANSITION_CONTEXTc                  (    e Zd ZddZ	 	 ddZddZy)_ConnectionEscrowc                D    t        j                         | _        d | _        y N)	threadingRLock_lock
_functionsselfs    r3   __init__z_ConnectionEscrow.__init__:   s    __&
txr2   c                    t         sy | j                  5  | j                  dd l}|j	                  d |j
                        }|j                  |j                  j                  |j                        j                  }|j                  |j                  j                  |j                        j                  }||d}t        |      t        d ||            t        d ||            f| _        | j                  cd d d        S # 1 sw Y   y xY w)Nr   z+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>   rA   function_typeincrement_addressdecrement_addressmsgs         r3   	functionsz_ConnectionEscrow.functions>   s     (ZZ& & 1 1$8H8H I$*KK0@0@0J0JFOO$\$b$b!$*KK0@0@0J0JFOO$\$b$b!$,0A0IGC&s++?O`Aab?O`Aab# ?? ZZs   C&DDc                6    t        j                         | _        y r8   )r9   r:   r;   r=   s    r3   _reset_after_fork_in_childz,_ConnectionEscrow._reset_after_fork_in_childS   s    __&
r2   NreturnNone)rR   Xtuple[Callable[[sqlite3.Connection], None], Callable[[sqlite3.Connection], None]] | None)r-   r.   r/   r?   rN   rP   r1   r2   r3   r6   r6   9   s    y#	a#*'r2   r6   _CONNECTION_ESCROWc                  F    e Zd ZddZd	dZd
dZddZddZedd       Z	y)_ForkedDatabaseRegistryc                    t        j                         | _        t               | _        t               | _        d| _        d| _        y NF)r9   r:   r;   set_paths_identities_sqlite_used_all_paths_poisonedr=   s    r3   r?   z _ForkedDatabaseRegistry.__init__[   s3    __&
),365!#( r2   c                    | j                  |      }| j                  5  | j                  }|xs$ || j                  v xs |d uxr || j                  v }d d d        rrdnd|d}t        |      y # 1 sw Y   !xY w)NzOReadWriteLock is unavailable in a PyPy fork child; exec or exit before using itzSQLite database zD was active across fork(); exec or exit before using it in the child)identityr;   r^   r[   r\   rI   )r>   pathr`   all_paths_poisonedpoisonedrM   s         r3   raise_if_poisonedz)_ForkedDatabaseRegistry.raise_if_poisonedb   s    ==&ZZ!%!9!9"tddkk&9thd>R>sW_cgcscsWs  
  & b'x/st 
 s##  Zs   5A33A<c                v    | j                   j                  |       || j                  j                  |       y y r8   )r[   addr\   )r>   ra   r`   s      r3   poison_after_forkz)_ForkedDatabaseRegistry.poison_after_forkq   s1      *  r2   c                b    t         r| j                  5  d| _        d d d        y y # 1 sw Y   y xY wNT)r   r;   r]   r=   s    r3   note_sqlite_usez'_ForkedDatabaseRegistry.note_sqlite_usev   s&    $(!  s   %.c                    t        j                         | _        | j                  xs t        xr | j
                  | _        d| _        y rY   )r9   r:   r;   r^   r   r]   r=   s    r3   rP   z2_ForkedDatabaseRegistry._reset_after_fork_in_child{   s6    __&
#'#;#;#_@^TM^M^ !r2   c                r    	 | j                         }|j                  |j                  fS # t        $ r Y y w xY wr8   )statOSErrorst_devst_ino)ra   stat_results     r3   r`   z _ForkedDatabaseRegistry.identity   s?    	))+K !!;#5#555  		s   * 	66NrQ   )ra   pathlib.PathrR   rS   )ra   rr   r`   _DatabaseIdentity | NonerR   rS   )ra   rr   rR   rs   )
r-   r.   r/   r?   rd   rg   rj   rP   staticmethodr`   r1   r2   r3   rW   rW   Z   s/    )$+
)
"
 6 6r2   rW   _FORKED_DATABASESc                  b     e Zd ZU ded<   ded<   	 	 	 	 	 	 d	 fdZd
dZ	 	 	 	 ddZd
dZ xZS )_ForkSafeConnectionr+   _creator_pidz+Callable[[sqlite3.Connection], None] | None_decrement_escrowc                R    t         |   |       }t               |_        d |_        |S r8   )super__new__r   rx   ry   )cls_args_kwargs
connection	__class__s       r3   r|   z_ForkSafeConnection.__new__   s+    
 W_S)
"))
'+
$r2   c                :   t               5  t               | j                  k7  r
	 d d d        y t               5  t        j
                  j                  |        | j                  x}d | _         ||        d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wr8   )_sqlite_transitionr   rx   r   sqlite3
Connectionclosery   )r>   	decrements     r3   r   z_ForkSafeConnection.close   s~    !yD--- "! "#""((.!%!7!77ID-1D*dO	 $ "! $# "!s'   B
B=B4BB	
BBc                2    ||\  }} ||        || _         y y r8   )ry   )r>   rN   	incrementr   s       r3   acquire_escrowz"_ForkSafeConnection.acquire_escrow   s(    
  #, IydO%.D" !r2   c                    t        t        j                  t              5  | j	                          d d d        y # 1 sw Y   y xY wr8   )r   r   ErrorrI   r   r=   s    r3   __del__z_ForkSafeConnection.__del__   s%    gmm\2JJL 322s	   9A)r~   r$   r   r$   rR   r   rQ   )rN   rT   rR   rS   )	r-   r.   r/   r0   r|   r   r   r   __classcell__r   s   @r3   rw   rw      sQ    BB$ ( 
	$/k/ 
/r2   rw   c                  t     e Zd ZU dZded<   ded<   ded<   ded	<   	 dd
d
d	 	 	 	 	 	 	 	 	 d fdZddZ xZS )_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]
_instanceszthreading.RLock_instances_lockr+   _instances_pidzset[pathlib.Path]_instances_under_constructionTblockingis_singletonc          	        t                | j                  t               k7  r| j                          t               }|s/t        
|   ||||      }t               |k7  rd}t        |      |S t        j                  |      j                         }| j                  5  || j                  vr|| j                  v rd|}t        |      | j                  }	|	j                  |       	 t        
|   ||||      }t               |k(  r|	j                  |       	 t               |k7  rd}t        |      || j                  |<   n| j                  |   }|j                  |k7  s|j                   |k7  r-d|j                   d|j                    d| d| }t#        |      |cd d d        S # t               |k(  r|	j                  |       w w xY w# 1 sw Y   y xY w)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=)r   r   r   _reset_class_after_forkr{   __call__rI   pathlibPathresolver   r   r   rf   discardtimeoutr   
ValueError)r}   	lock_filer   r   r   construction_pidinstancerM   
normalizedconstruction_registryr   s             r3   r   z_ReadWriteLockMeta.__call__   s    	 !*'')"9w'	7X\h'iHy,,M"3''O\\),446
  /!B!BBNym\C&s++(+(I(I%%))*5B$w/	7Xdp/qHy$44-55jA9 00QC&s++-5z*>>*57*h.?.?8.K:8;K;K:LKX`XiXiWj k55<I[
T  !o%3 !  y$44-55jA 5 ! s&   A
G(F);B$G)!G

GGc                    t               | _        t        j                         | _        t               | _        t               | _        y r8   )	r   r   r9   r:   r   r   r   rZ   r   )r}   s    r3   r   z*_ReadWriteLockMeta._reset_class_after_fork   s/    ,.'oo/$Y,/E)r2   )
r   str | os.PathLike[str]r   floatr   boolr   r   rR   ReadWriteLockrQ   )r-   r.   r/   __doc__r0   r   r   r   r   s   @r3   r   r      sp     A@$$#44
 -
 !-)- -
 - - 
-^2r2   r   c                      e Zd ZU dZ e       Zded<    ej                         Z	 e
       Z e       Zded<   d% fdZe	 d&dd	 	 	 	 	 	 	 d'd	       Z	 d&ddd
	 	 	 	 	 	 	 	 	 d(dZd&ddd)dZd&ddd)dZed*ddd+d       Zed*ddd+d       Zddd,dZd%dZd-dZd%dZd%dZd%dZed.d       Zd%dZd/dZ 	 	 	 	 	 	 	 	 	 	 	 	 d0dZ!d1dZ"	 	 	 	 	 	 	 	 	 	 d2dZ#d3dZ$d%d Z%d4d!Z&d5d"Z'd6d#Z(d7d$Z) xZ*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   zClassVar[set[pathlib.Path]]r   c                    t         |           t               | _        t	        j
                         | _        t               | _        t               | _
        t        |        y r8   )r{   __init_subclass__r   r   r9   r:   r   r   r   rZ   r   r   )r}   r   s    r3   r   zReadWriteLock.__init_subclass__  sC    !#,.'oo/$Y,/E)S!r2   T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   r1   )r}   r   r   r   s       r3   get_lockzReadWriteLock.get_lock  s      9g99r2   r   c                  t        j                  |      | _        t        j                  |      j                         | _        t        j                  | j                         || _	        || _
        t        j                         | _        t        j                         | _        d| _        d | _        d | _        t%               | _        d | _        d| _        d | _        d| _        t1               | _        d| _        t7        |        t9               5  t;               5  | j=                  d      }|j?                          d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr   TFg      @sqlite_timeout) osfspathr   r   r   r   _canonical_pathru   rd   r   r   r9   Lock_transaction_lock_internal_lock_lock_level_current_mode_write_thread_idrZ   _acquisition_thread_ids_con _connection_transaction_released_connection_identity_closedr   rx   _fork_invalidatedr   r   r   _open_connectionr   )r>   r   r   r   r   validation_connections         r3   r?   zReadWriteLock.__init__,  s    9-&||I6>>@++D,@,@A !*!1'nn.>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               *    | j                  d||      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      r3   acquire_readzReadWriteLock.acquire_readJ  s      }}VWx}@@r2   c               *    | j                  d||      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      r3   acquire_writezReadWriteLock.acquire_write\  s    $ }}Wg}AAr2   Nc             #     K   || j                   }|| j                  }| j                  ||       	 d | j                          y# | j                          w xY w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      r3   	read_lockzReadWriteLock.read_lockp  sR      ?llG}}H'H5	LLNDLLN   0AA AAAc             #     K   || j                   }|| j                  }| j                  ||       	 d | j                          y# | j                          w xY w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      r3   
write_lockzReadWriteLock.write_lock  sR      ?llG}}H7X6	LLNDLLNr   F)forcec                   t               5  t                | j                  r
	 ddd       y| j                  d       | j	                  |d       ddd       y# 1 sw Y   yxY w)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   r   r   
_inherited_raise_if_acquiring_release)r>   r   s     r3   r   zReadWriteLock.release  sN     #%   $$Y/MMUM3     A$AA"c                    t               5  t                | j                  r
	 ddd       y| j                  d       | j	                  dd       ddd       y# 1 sw Y   yxY w)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    r3   r   zReadWriteLock.close  sN     #%   $$W-MMDM1  r   c               v   | j                   5  | j                  5  | j                  dk(  rR|r'| j                  |rd| _        	 d d d        d d d        y |s'd| j
                   dt        |        d}t        |      |s6| j                  dkD  r'| xj                  dz  c_        	 d d d        d d d        y 	 | j                          | j                          |rd| _        d d d        d d d        y # t        j                  $ r | j                  r| j                           w xY w# 1 sw Y   FxY w# 1 sw Y   y xY w)Nr   TzCannot release a lock on  (lock id: z) that is not heldr   )r   r   r   r   r   r   idrI   _finish_connectionr   r   r   _clear_lock_state)r>   r   r   rM   s       r3   r   zReadWriteLock._release  s   ##T%8%81$TYY.'+ &9## 5dnn5E[QSTXQYPZZlmC&s++T--1  A%  &9##'')
 ""$#) &9## == 88**, &9%8##sM   D/(D#D/AD##D/5C/D#D//1D  D##D,	(D//D8c                .    d| _         d | _        d | _        y )Nr   )r   r   r   r=   s    r3   r   zReadWriteLock._clear_lock_state  s    ! $r2   c                    t               t        | dd       k(  rHt        | dd       x}8t        t        j                  t
              5  |j                          d d d        y y y # 1 sw Y   y xY w)Nrx   r   )r   getattrr   r   r   rI   r   )r>   r   s     r3   r   zReadWriteLock.__del__  s^    9nd;;wW[]ceiOjAj@w'--6  " 76 Ax;66s   A""A+c                J   | j                   *t        j                  | j                  | j                         d | _         d| _        d | _        t        j                         | _        t        j                         | _	        | j                          t               | _        d| _        y ri   )r   ru   rg   r   r   r   r9   r   r   r   r   rZ   r   r   r=   s    r3   rP   z(ReadWriteLock._reset_after_fork_in_child  s{    99 //0D0DdF_F_`	04-$(!!*!1'nn. '*u$!%r2   c                L    | j                   xs t               | j                  k7  S r8   )r   r   rx   r=   s    r3   r   zReadWriteLock._inherited  s     %%Gd6G6G)GGr2   c                    t                | j                  rd| j                   d}t        |      | j                  rd}t        j                  |      y )NReadWriteLock on 4 was invalidated by fork(); construct a new instancez$Cannot operate on a closed database.)r   r   r   rI   r   r   ProgrammingError)r>   rM   s     r3   _raise_if_unusablez ReadWriteLock._raise_if_unusable  sP    !??%dnn%55ijCs##<<8C**3// r2   c          	        t               5  | j                          t               }t        j                         }| j
                  5  | j                  dkD  r#| j                  |      cd d d        cd d d        S || j                  v rd| j                   d}t        |      | j                  j                  |       d d d        	 t        j                         }| j                  ||       	 | j                          | j                  |||||      | j                   j#                          | j
                  5  | j                  j%                  |       d d d        cd d d        S # 1 sw Y   xY w# 1 sw Y   xY w# | j                   j#                          w xY w# | j
                  5  | j                  j%                  |       d d d        w # 1 sw Y   w xY wxY w# 1 sw Y   y xY w)Nr   z Cannot acquire ReadWriteLock on + while acquisition is active in this threadr   r   r   operation_pid
start_time)r   r   r   r9   	get_identr   r   _validate_reentrantr   r   rI   rf   timeperf_counter_acquire_transaction_lock_do_acquire_innerr   r   r   )r>   moder   r   r   	thread_idrM   r   s           r3   r   zReadWriteLock._acquire  s   ##%#IM!++-I$$##a'33D9 %$	    < <<<T^^<LLwxC&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9AE'=G'F.%E?F-G9E3G'E0	,G3E<8G?FFG+G		GGGGG(c               L   | j                   5  | j                  dkD  r| j                  |      cd d d        S 	 d d d        | j                  | j	                          	 | j                  ||||       | j                  |||||f       | j                  |       | j                   5  | j                  |       || _        d| _        |dk(  rt%        j&                         | _        d d d        t+        |       S # 1 sw Y   xY w# t        $ r}t        |t        j                        r#dt        |      v rt        | j                        }n|}	 | j	                          n,# t        j                  $ r}t!        ||       Y d }~nd }~ww xY w||ur|d  d }~ww xY w# 1 sw Y   xY w)Nr   r   )r   	operationzdatabase is lockedr   r   lock)r   r   r   r   r   _open_for_acquisition_configure_and_begin_raise_if_process_changedBaseException
isinstancer   OperationalErrorstrr   r   r   r   r   r9   r   r   r   )	r>   r   r   r   r   r   erroracquisition_errorcleanup_errors	            r3   r   zReadWriteLock._do_acquire_inner  s      !#//5 ! # ! 99 ##%	&&!+%	 '  %%!(*5	 &  **=9   **=9!%D Dw(1(;(;(=% ! "t,,M ! &  	%!9!9:?SWZ[`Wa?a$+DNN$;!$)!H'')== H%&7GGH -'T1	 ! sY    C8=D &>F8D	F?FEFF1F=FFFFF#c               :   t               5  t        ||t        j                         |z
        dz  }| j	                  |      }|dt
        j                  | j                        c| _        | _	        | _
        | j                  |       d d d        y # 1 sw Y   y xY w)Nr   already_waited  r   F)r   timeout_for_sqliter   r   r   ru   r`   r   r   r   r   r  )r>   r   r   r   r   r   r   s          r3   r  z#ReadWriteLock._open_for_acquisitionD  s    !"%#'#4#4#6#C
   ..n.MJ!**4+?+?@ XDIt<d>W
 **=9 "!!s   A=BBc                  t               5  |\  }}t        d| j                        }t        j                         |z
  }t        |||      }	| j                  |       |j                  d|	 d      j                          t        j                         |z
  }t        |||      }
| j                  |       |
|	k7  rd|
 dnd}||dk(  rdnd	z  }|d
k(  r|dz  }|j                  |      j                          d d d        y # 1 sw Y   y xY w)Nrw   r  zPRAGMA busy_timeout=z; PRAGMA journal_mode=MEMORY;z;  r   zBEGIN EXCLUSIVE TRANSACTION;zBEGIN TRANSACTION;r   z( SELECT name FROM sqlite_schema LIMIT 1;)	r   r   r   r   r   r  r  executescriptr   )r>   r   r   r   r   r   r   r   waited
timeout_ms
recomputed
statementss               r3   r  z"ReadWriteLock._configure_and_beginV  s     !(1%M:3TYY?J&&(:5F+GhW]^J**=9$$';J<Gd%eflln &&(:5F+GhW]^J**=9BLPZBZ/
|2>`bJDGO8QeeJv~ HH
$$Z0668- "!!s   C-DD
c                  t               5  t               }t        j                         }t               |k7  rd}t	        |      t        t        j                  | j                        t        |      }||j                  |       t               |k7  rJt        j                  | j                  t        j                  | j                               d}t	        |      |cd d d        S # 1 sw Y   y xY w)Nz9SQLite connection construction cannot continue after fork)factoryr   )r   r   rU   rN   rI   _connectr   r   r   rw   r   ru   rg   r`   )r>   r   creator_pidrN   rM   r   s         r3   r   zReadWriteLock._open_connectionv  s    !!)K*446IyK'Q"3''!		$../+&J
 $)))4yK'!33((%..t/C/CD R"3'') "!!s   CC((C1c                   t               5  | j                  x}
	 d d d        y d }| j                  s,|j                  r	 |j	                          d| _        nd| _        	 |j                          d | _        d| _        d | _	        ||	 d d d        y # t
        j                  $ r }|j                  r d| _        |}Y d }~bd }~ww xY w# t
        j                  $ r}|t        ||        d }~ww xY w# 1 sw Y   y xY wri   )
r   r   r   in_transactionrollbackr   r   r   r   r   )r>   r   rollback_errorr
  close_errors        r3   r   z ReadWriteLock._finish_connection  s   !"ii'
0 "! 48N88,,E"++- AE=<@D9  "
 DI48D1(,D%)$$ *5 "! #== /%44!@D=).	/ == !-).+F' "!s]   C2C2BC2C/C2C%C ;C2 CC2C/C**C//C22C;c                   | j                   |k7  rB|dk(  rdnd}|dk(  rdnd}d| d| j                   dt        |        d| d	| d
}t        |      |dk(  rYt	        j
                         x}| j                  k7  r6d| j                   dt        |        d| d| j                   }t        |      | xj                  dz  c_        t        |       S )Nr   r   	downgradeupgradezCannot acquire z	 lock on r   z): already holding a z lock (z not allowed)zCannot acquire write lock on z) from thread z while it is held by thread r   r  )	r   r   r   rI   r9   r   r   r   r   )r>   r   opposite	directionrM   curs         r3   r   z!ReadWriteLock._validate_reentrant  s    %"&&.wfH'+v~9I!$y0@BtH: V%%-Jgi[O  s##7?y':':'< <AVAVV//?{2d8* U"e#?@U@U?VX  s##A!t,,r2   c                   |s| j                   j                  d      }n?|dk(  r| j                   j                  d      }n| j                   j                  d|      }|st        | j                        d y )NFr   r   Tr   )r   acquirer   r   )r>   r   r   acquireds       r3   r   z'ReadWriteLock._acquire_transaction_lock  sr    --55u5EH]--55t5DH--55tW5UH$..)t3 r2   c                    | j                   5  t        j                         | j                  v }d d d        rd| d| j                   d}t        |      y # 1 sw Y   *xY w)NzCannot z ReadWriteLock on r   )r   r9   r   r   r   rI   )r>   r   active_in_current_threadrM   s       r3   r   z!ReadWriteLock._raise_if_acquiring  sa      '0':':'<@\@\'\$ !#I;&88HHstCs## $ ! s   !AA c                l    t               |k7  s| j                  rd| j                   d}t        |      y )Nr   r   )r   r   r   rI   )r>   r   rM   s      r3   r  z'ReadWriteLock._raise_if_process_changed  s6    9%%dnn%55ijCs## *9r2   rQ   r   )r   r   r   r   r   r   rR   r   )
r   r   r   r   r   r   r   r   rR   rS   )r   r   r   r   rR   r   r8   )r   zfloat | Noner   zbool | NonerR   Generator[None])r   r   rR   rS   )r   r   r   r   rR   rS   )rR   r   )r   Literal['read', 'write']r   r   r   r   rR   r   )r   r/  r   r   r   r   r   r+   r   r   rR   r   )
r   r   r   r   r   r+   r   r   rR   rS   )
r   r/  r   r   r   r   r   ztuple[int, float]rR   rS   )r   r   rR   rw   )r   r/  rR   r   )r   r   r   r   rR   rS   )r   z&Literal['acquire', 'close', 'release']rR   rS   )r   r+   rR   rS   )+r-   r.   r/   r   r   r   r0   r9   r:   r   r   r   rZ   r   r   classmethodr   r?   r   r   r   r   r   r   r   r   r   r   rP   propertyr   r   r   r   r  r  r   r   r   r   r   r  r   r   s   @r3   r   r      s   * DWCXJ@X%ioo'OYNAD!#>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$$r2   r   )	metaclassc               ^    t         j                          t        j                  | d|d|      S )NFr   )check_same_threadr  cached_statementsr   )ru   rj   r   connect)databaser  r   s      r3   r  r    s.    %%'?? r2   c               #     K   t         xj                  dz  c_        	 d  t         xj                  dz  c_        y # t         xj                  dz  c_        w xY ww)Nr   )r4   r,   r1   r2   r3   r   r     sB     $$)$."((A-("((A-(s   A; AAAc                 X    t         j                  rt        j                  t               y y r8   )r4   r,   r   _exitr(   r1   r2   r3   _abort_forked_sqlite_transitionr;    s    !''
)* (r2   c                8    | dk(  rt         j                          y y )Nzsqlite3.connect)ru   rj   )eventr~   s     r3   _track_sqlite_user>    s    !!))+ "r2   c                   |du ry| dk(  rt         S | dk  rd}t        |      t        | dkD  rt        | |z
  d      n| dz        }|t         kD  s|dk  r!t        j                  d| t                t         S |S )NFr   r   z+timeout must be a non-negative number or -1r  z7timeout %s is too large for SQLite, using %s ms instead)r&   r   r+   maxr   warning)r   r   r  rM   r  s        r3   r  r    s    5"}%%{;o'A+c'N2A67VZZ[J**j1nQSZ\rs%%r2   )after_in_childr  )r7  r	  r  ztype[_ForkSafeConnection]r   r   rR   rw   )rR   r.  rQ   )r=  r	  r~   r   rR   rS   )r   r   r   r   r  r   rR   r+   )N
__future__r   loggingr   r   r   sysr9   r   
contextlibr   r   typingr   r   r   r	   r
   r   weakrefr   _apir   r   r   r   r   r   _errorr   collections.abcr   r   	_typeshedr   version_infor   typing_extensions	getLoggerr   r0   getpidr   implementationnamer   hasattrr#   r	  bytesPathLiker   r+   typer   r$   tupler%   r&   r(   localr*   r4   r6   rU   rW   ru   rw   r   r   r  r   r;  r>  r  addaudithookr    __all__r1   r2   r3   <module>r[     s^   "  	   
   / K K '  3 
7"*!2!2!2:!>	 >$&II	! -**//69+ 9B"#k(:(:(?(?9(LkQTQaQadkQk +  %K"++c""R[[%77%?#EWM_M_H``cgg i   %S#X 9 . &7 
 6') * )y  %=$> E >' '< ./ E /,6 ,6^ 34 5 4$',, $NA2 A2HZ$0 Z$z . .+
,
$ ( ) ' ( ] #C&'
2!"B'FG r2   