
    =wg                         d Z ddlZddlZddlZddlZddZ G d de      Z G d de      Z G d d	e      Z	ej                  d
k(  re	ZyeZy)ai  
This module contains classes implementing exclusive locks for platforms with
fcntl (UNIX and Mac OS X) and Windows. Whoosh originally used directory
creation as a locking method, but it had the problem that if the program
crashed the lock directory was left behind and would keep the index locked
until it was cleaned up. Using OS-level file locks fixes this.
    Nc                     t        j                          |z   } |        }|sMt        j                          |k  r6t        j                  |        |        }|st        j                          |k  r6|S )a  Calls ``fn`` every ``delay`` seconds until it returns True or
    ``timeout`` seconds elapse. Returns True if the lock was acquired, or False
    if the timeout was reached.

    :param timeout: Length of time (in seconds) to keep retrying to acquire the
        lock. 0 means return immediately. Only used when blocking is False.
    :param delay: How often (in seconds) to retry acquiring the lock during
        the timeout period. Only used when blocking is False and timeout > 0.
    )timesleep)fntimeoutdelayuntilvs        K/var/www/horilla/myenv/lib/python3.12/site-packages/whoosh/util/filelock.pytry_forr   *   sW     IIK'!E
ADIIK%'

5D DIIK%' H    c                   *    e Zd ZdZd Zd ZddZd Zy)LockBasezBase class for file locks.
    c                 .    d | _         || _        d| _        y )NF)fdfilenamelocked)selfr   s     r   __init__zLockBase.__init__A   s     r   c                 h    t        | d      r| j                  r	 | j                          y y y #  Y y xY w)Nr   )hasattrr   releaser   s    r   __del__zLockBase.__del__F   s2    4477 $+s   - 1c                      y)a"  Acquire the lock. Returns True if the lock was acquired.

        :param blocking: if True, call blocks until the lock is acquired.
            This may not be available on all platforms. On Windows, this is
            actually just a delay of 10 seconds, rechecking every second.
        N )r   blockings     r   acquirezLockBase.acquireM   s     	r   c                      y )Nr   r   s    r   r   zLockBase.releaseV   s    r   NF)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r   =   s    
r   r   c                       e Zd ZdZddZd Zy)	FcntlLockz/File lock based on UNIX-only fcntl module.
    c                    dd l }t        j                  t        j                  z  }t        j                  | j
                  |      | _        |j                  }|s||j                  z  }	 |j                  | j                  |       d| _
        y# t        $ rm t        j                         d   }|j                  t        j                  t        j                   fvr t        j"                  | j                         d | _        Y yw xY w)Nr   T   F)fcntlosO_CREATO_WRONLYopenr   r   LOCK_EXLOCK_NBflockr   IOErrorsysexc_infoerrnoEAGAINEACCESclose)r   r   r)   flagsmodees         r   r   zFcntlLock.acquire^   s    

R[[(''$--/}}EMM!D
	KK&DK 	q!Awwu||U\\::HHTWWDG	s   )#B A3DDc                     | j                   t        d      dd l}|j                  | j                   |j                         t        j                  | j                          d | _         y )NLock was not acquiredr   )r   	Exceptionr)   r0   LOCK_UNr*   r7   )r   r)   s     r   r   zFcntlLock.releaset   sG    77?344DGGU]]+
r   Nr    r!   r"   r#   r$   r   r   r   r   r   r&   r&   Z   s    ,r   r&   c                       e Zd ZdZddZd Zy)
MsvcrtLockz3File lock based on Windows-only msvcrt module.
    c                    dd l }t        j                  t        j                  z  }|j                  }|r|j
                  }t        j                  | j                  |      | _        	 |j                  | j                  |d       y# t        $ r| t        j                         d   }|j                  t        j                  t        j                  t        j                   fvr t        j"                  | j                         d | _        Y yw xY w)Nr   r(   TF)msvcrtr*   r+   r,   LK_NBLCKLK_LOCKr-   r   r   lockingr1   r2   r3   r4   r5   r6   EDEADLKr7   )r   r   rC   r8   r9   r:   s         r   r   zMsvcrtLock.acquire   s    

R[[(>>D''$--/		NN477D!, 	q!Awwu||U\\5==IIHHTWWDG	s   &B BD	D	c                     dd l }| j                  t        d      |j                  | j                  |j                  d       t        j                  | j                         d | _        y )Nr   r<   r(   )rC   r   r=   rF   LK_UNLCKr*   r7   )r   rC   s     r   r   zMsvcrtLock.release   sI    77?344tww3
r   Nr    r?   r   r   r   rA   rA   ~   s    (r   rA   nt)g      @g?)r$   r4   r*   r2   r   r   objectr   r&   rA   nameFileLockr   r   r   <module>rN      sZ   8  	 
 &v :! !H D 77d?HHr   