ŊX N d Z ddlmZ ddlZddlZddlZddlZddlZ eed sej e_ eej d sej j ej _ g dZ G d de Z G d d e Z G d de Z G d de Z G d de Z G d de Z G d de Z G d de Z G d de Z G d de Zd Zd Zd Zd Zd$dZ eed rd!d"l m!Z" e"j# Z$n d!d#l m%Z& e&j' Z$e$Z(dS )%a lockfile.py - Platform-independent advisory file locks. Requires Python 2.5 unless you apply 2.4.diff Locking is done on a per-thread basis instead of a per-process basis. Usage: >>> lock = LockFile('somefile') >>> try: ... lock.acquire() ... except AlreadyLocked: ... print 'somefile', 'is locked already.' ... except LockFailed: ... print 'somefile', 'can\'t be locked.' ... else: ... print 'got lock' got lock >>> print lock.is_locked() True >>> lock.release() >>> lock = LockFile('somefile') >>> print lock.is_locked() False >>> with lock: ... print lock.is_locked() True >>> print lock.is_locked() False >>> lock = LockFile('somefile') >>> # It is okay to lock twice from the same thread... >>> with lock: ... lock.acquire() ... >>> # Though no counter is kept, so you can't unlock multiple times... >>> print lock.is_locked() False Exceptions: Error - base class for other exceptions LockError - base class for all locking exceptions AlreadyLocked - Another thread or process already holds the lock LockFailed - Lock failed for some other reason UnlockError - base class for all unlocking exceptions AlreadyUnlocked - File was not locked. NotMyLock - File was locked but not by the current thread/process )absolute_importNcurrent_threadget_name) Error LockErrorLockTimeout AlreadyLocked LockFailedUnlockError NotLocked NotMyLockLinkFileLock MkdirFileLockSQLiteFileLockLockBaselockedc e Zd ZdZdS )r zw Base class for other exceptions. >>> try: ... raise Error ... except Exception: ... pass N__name__ __module____qualname____doc__ q/builddir/build/BUILD/imunify360-venv-2.6.2/opt/imunify360/venv/lib/python3.11/site-packages/lockfile/__init__.pyr r J Dr r c e Zd ZdZdS )r z Base class for error arising from attempts to acquire the lock. >>> try: ... raise LockError ... except Error: ... pass Nr r r r r r V r r r c e Zd ZdZdS )r zRaised when lock creation fails within a user-defined period of time. >>> try: ... raise LockTimeout ... except LockError: ... pass Nr r r r r r b Dr r c e Zd ZdZdS )r zSome other thread/process is locking the file. >>> try: ... raise AlreadyLocked ... except LockError: ... pass Nr r r r r r m r r r c e Zd ZdZdS )r zLock file creation failed for some other reason. >>> try: ... raise LockFailed ... except LockError: ... pass Nr r r r r r x r r r c e Zd ZdZdS )r z Base class for errors arising from attempts to release the lock. >>> try: ... raise UnlockError ... except Error: ... pass Nr r r r r r r r r c e Zd ZdZdS )r zRaised when an attempt is made to unlock an unlocked file. >>> try: ... raise NotLocked ... except UnlockError: ... pass Nr r r r r r r r r c e Zd ZdZdS )r zRaised when an attempt is made to unlock a file someone else locked. >>> try: ... raise NotMyLock ... except UnlockError: ... pass Nr r r r r r r r r c 4 e Zd Zd ZddZd Zd Zd Zd ZdS ) _SharedBasec || _ d S N)path)selfr) s r __init__z_SharedBase.__init__ s r Nc t d )a Acquire the lock. * If timeout is omitted (or None), wait forever trying to lock the file. * If timeout > 0, try to acquire the lock for that many seconds. If the lock period expires and the file is still locked, raise LockTimeout. * If timeout <= 0, raise AlreadyLocked immediately if the file is already locked. implement in subclassNotImplemented)r* timeouts r acquirez_SharedBase.acquire s 4555r c t d )zX Release the lock. If the file is not locked, raise NotLocked. r- r. r* s r releasez_SharedBase.release s 4555r c . | | S )* Context manager support. )r1 r3 s r __enter__z_SharedBase.__enter__ s r c . | dS )r6 N)r4 )r* _excs r __exit__z_SharedBase.__exit__ s r c 2 d| j j d| j dS )N<: >) __class__r r) r3 s r __repr__z_SharedBase.__repr__ s !^444diii@@r r( ) r r r r+ r1 r4 r7 r: r@ r r r r&