bgT.ddlmZddlZddlZddlZddlZddlZddlmZm Z ddl m Z ddl m Z ddlmZmZmZddlmZdd lmZer"ddlZdd lmZejd krdd lmZndd lmZejd ZGddZe GddZGddee Z Gddeej!Z"ddgZ#dS)) annotationsN)ABCabstractmethod) dataclass)local) TYPE_CHECKINGAnyClassVar)WeakValueDictionary)Timeout) TracebackType) )Selffilelockc*eZdZdZddZddZddZdS)AcquireReturnProxyzDA context aware object that will release the lock file when exiting.lock BaseFileLockreturnNonec||_dSNr)selfrs ^/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/filelock/_api.py__init__zAcquireReturnProxy.__init__#s  c|jSrrrs r __enter__zAcquireReturnProxy.__enter__&s yrexc_typetype[BaseException] | None exc_valueBaseException | None tracebackTracebackType | Nonec8|jdSr)rreleaserr#r%r's r__exit__zAcquireReturnProxy.__exit__)s rN)rrrr)rrr#r$r%r&r'r(rr)__name__ __module__ __qualname____doc__rr"r,rrrr sVNNrrcNeZdZUdZded<ded<ded<dZd ed <d Zded <dS) FileLockContextzBA dataclass which holds the context for a ``BaseFileLock`` object.str lock_filefloattimeoutintmodeNz int | None lock_file_fdr lock_counter)r.r/r0r1__annotations__r;r<r2rrr4r42s_LL NNNNNNIII $L####Lrr4ceZdZdZdS)ThreadLocalFileContextz8A thread local version of the ``FileLockContext`` class.N)r.r/r0r1r2rrr?r?IsBBBBrr?creZdZUdZeZded< d9ddd:fdZ d9ddd;dZddZ e jd?d Z ed@d!Zed@d"Ze d%%c)nn55 6wws++H-5CN3y>> *rrc||_||_tj|||d}|rtnt di||_dS)a Create a new lock object. :param lock_file: path to the file :param timeout: default timeout when acquiring the lock, in seconds. It will be used as fallback value in the acquire method, if no timeout value (``None``) is given. If you want to disable the timeout, set it to a negative value. A timeout of 0 means, that there is exactly one attempt to acquire the file lock. :param mode: file permissions for the lockfile :param thread_local: Whether this object's internal context should be thread local or not. If this is set to ``False`` then the lock will be reentrant across threads. :param is_singleton: If this is set to ``True`` then only one instance of this class will be created per lock file. This is useful if you want to use the lock object for reentrant locking without needing to pass the same object around. )r6r8r:Nr2)_is_thread_local _is_singletonosfspathr?r4_context)rr6r8r:rFrDrHs rrzBaseFileLock.__init__gs`.!-) 9--" "  +fL*e*@*@Ve)p)pio)p)p rc|jS)z>:return: a flag indicating if this lock is thread local or not)rRr!s ris_thread_localzBaseFileLock.is_thread_locals $$rc|jS)z;:return: a flag indicating if this lock is singleton or not)rSr!s rrDzBaseFileLock.is_singletons !!rr5c|jjS)z:return: path to the lock file)rVr6r!s rr6zBaseFileLock.lock_files}&&rc|jjS)za :return: the default timeout value, in seconds .. versionadded:: 2.0.0 )rVr8r!s rr8zBaseFileLock.timeouts}$$rvalue float | strc8t||j_dS)zd Change the default timeout value. :param value: the new value, in seconds N)r7rVr8)rr\s rr8zBaseFileLock.timeouts!&e  rct)zjIf the file lock could be acquired, self._context.lock_file_fd holds the file descriptor of the lock file.NotImplementedErrorr!s r_acquirezBaseFileLock._acquire "!rct)z>Releases the lock and sets self._context.lock_file_fd to None.r`r!s r_releasezBaseFileLock._releasercrc|jjduS)z :return: A boolean indicating if the lock file is holding the lock currently. .. versionchanged:: 2.0.0 This was previously a method and is now a property. N)rVr;r!s r is_lockedzBaseFileLock.is_lockeds})55rc|jjS)zP:return: The number of times this lock has been acquired (but not yet released).)rVr<r!s rr<zBaseFileLock.lock_counters}))rN皙?)poll_intervallblocking float | None poll_intervalrjrkrc| |jj}| d}tj|td|}|jxjdz c_t |}|j}tj } |j s0t d||| |j rt d||n|d ur+t d ||t|d |cxkrtj |z kr.nn+t d ||t|d }t ||||tj|n6#t $r)t#d |jjdz |j_wxYwt%|S)a_ Try to acquire the file lock. :param timeout: maximum wait time for acquiring the lock, ``None`` means use the default :attr:`~timeout` is and if ``timeout < 0``, there is no timeout and this method will block until the lock could be acquired :param poll_interval: interval of trying to acquire the lock file :param poll_intervall: deprecated, kept for backwards compatibility, use ``poll_interval`` instead :param blocking: defaults to True. If False, function will return immediately if it cannot obtain a lock on the first attempt. Otherwise, this method will block until the timeout expires or the lock is acquired. :raises Timeout: if fails to acquire lock within the timeout period :return: a context object that will unlock the file when the context is exited .. code-block:: python # You can use this method in the context manager (recommended) with lock.acquire(): pass # Or use an equivalent try-finally construct: lock.acquire() try: pass finally: lock.release() .. versionchanged:: 2.0.0 This method returns now a *proxy* object instead of *self*, so that it can be used in a with statement without side effects. Nz+use poll_interval instead of poll_intervall) stacklevelr Tz#Attempting to acquire lock %s on %szLock %s acquired on %sFz+Failed to immediately acquire lock %s on %srz"Timeout on acquiring lock %s on %sz2Lock %s not acquired on %s, waiting %s seconds ...r)rVr8warningswarnDeprecationWarningr<idr6time perf_counterrg_LOGGERdebugrbr sleep BaseExceptionmaxr) rr8rmrjrkmsglock_id lock_filename start_times racquirezBaseFileLock.acquiresP ?m+G  %?C M#1a @ @ @ @*M ""a'""T(( &((   *~$MM"GR_```MMOOO>MM":G]SSSu$$MM"OQXZghhh!-000BBBB$"3"5"5 "BBBBBBMM"FQ^___!-000J c7M=III =))) *    ),Q 0JQ0N)O)ODM &  "t,,,,s 0DF3F3forcecF|jr|jxjdzc_|jjdks|rrt||j}}t d|||d|j_t d||dSdSdS)a* Releases the file lock. Please note, that the lock is only completely released, if the lock counter is 0. Also note, that the lock file itself is not automatically deleted. :param force: If true, the lock counter is ignored and the lock is released in every case/ r rz#Attempting to release lock %s on %szLock %s released on %sN)rgrVr<rtr6rwrxre)rrr}r~s rr*zBaseFileLock.releases > P M & &! + & &})Q..%.)+D4> CWm\\\ -. * 6OOOOO P P/.rc.||S)zE Acquire the lock. :return: the lock object )rr!s rr"zBaseFileLock.__enter__#s  rr#r$r%r&r'r(c.|dS)z Release the lock. :param exc_type: the exception type if raised :param exc_value: the exception value if raised :param traceback: the exception traceback if raised Nr*r+s rr,zBaseFileLock.__exit__,s rc2|ddS)z'Called when the lock object is deleted.T)rNrr!s r__del__zBaseFileLock.__del__;s 4      r)rBrCT)r6rEr8r7r:r9rFrGrDrGrHrIrr) r6rEr8r7r:r9rFrGrDrGrr)rrG)rr5)rr7)r\r]rr)rr)rr9)Nri) r8rlrmr7rjrlrkrGrr)F)rrGrr)rrr-)r.r/r0r1r rAr=rLrrXpropertyrDr6r8setterrrbrergr<rr*r"r,r __classcell__)rPs@rrrMsd55CVCVCXCXJXXXX ! #0! !q#!q!q!q!q!q!qF%%%%"""X"'''X'%%%X% ^---^-"""^""""^" 6 6 6X 6***X* !%#J- (, J-J-J-J-J-J-XPPPPP$    !!!!!!!!rr)$ __future__r contextlibloggingrTrurqabcrr dataclassesr threadingrtypingrr r weakrefr _errorr systypesr version_infortyping_extensions getLoggerrwrr4r?ContextDecoratorr__all__r2rrrs """""" ########!!!!!!//////////''''''+JJJ###### 7""****** ' J ' ' $  ,CCCCC_eCCCp!p!p!p!p!3 3p!p!p!h r