id'@ddlmZddlZddlZddlZddlZddlZddlmZm Z ddl m Z ddl m Z ddlmZmZddlmZerdd lmZejd ZGd d Ze Gd dZGddee ZGddeejZdd gZdS)) annotationsN)ABCabstractmethod) dataclass)local) TYPE_CHECKINGAny)Timeout) TracebackTypefilelockc*eZdZdZddZddZddZdS)AcquireReturnProxyzDA context aware object that will release the lock file when exiting.lock BaseFileLockreturnNonec||_dSNr)selfrs B/opt/cloudlinux/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)rreleaserrr r"s r__exit__zAcquireReturnProxy.__exit__!s rN)rrrrrrrrr r!r"r#rr)__name__ __module__ __qualname____doc__rrr'rrrrsVNNrrcNeZdZUdZded<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+r,r-__annotations__r7r8r.rrr0r0*s_LL NNNNNNIII $L####Lrr0ceZdZdZdS)ThreadLocalFileContextz8A thread local version of the ``FileLockContext`` class.N)r*r+r,r-r.rrr;r;AsBBBBrr;ceZdZdZ d0d1dZd2dZed3dZed4dZej d5dZe d6dZ e d6dZ ed2dZ ed7dZ d8dddd9d#Zd:d;d&Zdrz+Abstract base class for a file lock object.Tr2str | os.PathLike[Any]r4r3r6r5 thread_localboolrrcz||_tj|||d}|rtntdi||_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. )r2r4r6Nr.)_is_thread_localosfspathr;r0_context)rr2r4r6r@kwargss rrzBaseFileLock.__init__HsX$!- 9--" "  +fL*e*@*@Ve)p)pio)p)p rc|jS)z>:return: a flag indicating if this lock is thread local or not)rCrs ris_thread_localzBaseFileLock.is_thread_locales $$rr1c|jjS)z:return: path to the lock file)rFr2rs rr2zBaseFileLock.lock_fileis}&&rc|jjS)za :return: the default timeout value, in seconds .. versionadded:: 2.0.0 )rFr4rs rr4zBaseFileLock.timeoutns}$$rvalue float | strc8t||j_dS)zd Change the default timeout value. :param value: the new value, in seconds N)r3rFr4)rrLs rr4zBaseFileLock.timeoutws!&e  rct)zjIf the file lock could be acquired, self._context.lock_file_fd holds the file descriptor of the lock file.NotImplementedErrorrs r_acquirezBaseFileLock._acquire "!rct)z>Releases the lock and sets self._context.lock_file_fd to None.rPrs r_releasezBaseFileLock._releaserSrc|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)rFr7rs r is_lockedzBaseFileLock.is_lockeds})55rc|jjS)zP:return: The number of times this lock has been acquired (but not yet released).)rFr8rs rr8zBaseFileLock.lock_counters}))rN皙?)poll_intervallblocking float | None poll_intervalrZr[rc| |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)rFr4warningswarnDeprecationWarningr8idr2time perf_counterrW_LOGGERdebugrRr sleep BaseExceptionmaxr) rr4r]rZr[msglock_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 0DF3F3FforcecF|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)rWrFr8rdr2rgrhrU)rrqrmrns rr%zBaseFileLock.releases > P M & &! + & &})Q..%.)+D4> CWm\\\ -. * 6OOOOO P P/.rc.||S)zE Acquire the lock. :return: the lock object )rprs rrzBaseFileLock.__enter__s  rrrr 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)rqNrurs r__del__zBaseFileLock.__del__s 4      r)r=r>T) r2r?r4r3r6r5r@rArr)rrA)rr1)rr3)rLrMrr)rr)rr5)NrY) r4r\r]r3rZr\r[rArr)F)rqrArrr(r))r*r+r,r-rrIpropertyr2r4setterrrRrUrWr8rpr%rr'rwr.rrrrEs55 ! qqqqq:%%%%'''X'%%%X% ^---^-"""^""""^" 6 6 6X 6***X* !%#J- (, J-J-J-J-J-J-XPPPPP$    !!!!!!rr) __future__r contextlibloggingrDreraabcrr dataclassesr threadingrtypingrr _errorr typesr getLoggerrgrr0r;ContextDecoratorr__all__r.rrrs"""""" ########!!!!!!%%%%%%%%$###### ' J ' ' $  ,CCCCC_eCCCN!N!N!N!N!3 3N!N!N!d r