ŊXNdZddlmZddlZddlZddlZddlZddlZeeds ej e_ eej dsej j ej _ gdZGddeZGd d eZGd d eZGd deZGddeZGddeZGddeZGddeZGddeZGddeZdZdZdZdZd$dZeed 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 LockError LockTimeout AlreadyLocked LockFailed UnlockError NotLocked NotMyLock LinkFileLock MkdirFileLockSQLiteFileLockLockBaselockedceZdZdZdS)rzw Base class for other exceptions. >>> try: ... raise Error ... except Exception: ... pass N__name__ __module__ __qualname____doc__q/builddir/build/BUILD/imunify360-venv-2.6.1/opt/imunify360/venv/lib/python3.11/site-packages/lockfile/__init__.pyrrJ DrrceZdZdZdS)rz Base class for error arising from attempts to acquire the lock. >>> try: ... raise LockError ... except Error: ... pass NrrrrrrVrrrceZdZdZdS)rzRaised when lock creation fails within a user-defined period of time. >>> try: ... raise LockTimeout ... except LockError: ... pass Nrrrrrrb DrrceZdZdZdS)r zSome other thread/process is locking the file. >>> try: ... raise AlreadyLocked ... except LockError: ... pass Nrrrrr r mrrr ceZdZdZdS)r zLock file creation failed for some other reason. >>> try: ... raise LockFailed ... except LockError: ... pass Nrrrrr r xrrr ceZdZdZdS)r z Base class for errors arising from attempts to release the lock. >>> try: ... raise UnlockError ... except Error: ... pass Nrrrrr r rrr ceZdZdZdS)r zRaised when an attempt is made to unlock an unlocked file. >>> try: ... raise NotLocked ... except UnlockError: ... pass Nrrrrr r rrr ceZdZdZdS)r zRaised when an attempt is made to unlock a file someone else locked. >>> try: ... raise NotMyLock ... except UnlockError: ... pass Nrrrrr r rrr c4eZdZdZddZdZdZdZdZdS) _SharedBasec||_dSN)path)selfr)s r__init__z_SharedBase.__init__s  rNc td)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 racquirez_SharedBase.acquires4555rc td)zX Release the lock. If the file is not locked, raise NotLocked. r-r.r*s rreleasez_SharedBase.releases 4555rc.||S)* Context manager support. )r1r3s r __enter__z_SharedBase.__enter__s  rc.|dS)r6N)r4)r*_excs r__exit__z_SharedBase.__exit__s rc2d|jjd|jdS)N<: >) __class__rr)r3s r__repr__z_SharedBase.__repr__s !^444diii@@rr() rrrr+r1r4r7r:r@rrrr&r&sx6666 666 AAAAArr&c<eZdZdZd fd ZdZdZdZdZxZ S) rz.Base class for platform-specific lock classes.TNc tt||tj|dz|_tj|_ tj |_ |r?tj }t|dt|}d|dzz|_nd|_tj|j}tj||j |jd|j t|j|_||_dS)zi >>> lock = LockBase('somefile') >>> lock = LockBase('somefile', threaded=False) z.lockidentz-%xl.N)superrr+osr)abspath lock_filesocket gethostnamehostnamegetpidpid threadingrgetattrhashtnamedirnamejoin unique_namer0)r*r)threadedr0trCrSr?s rr+zLockBase.__init__s  h&&t,,,..8*,, 9;;  (**AAwQ00E%*"45DJJDJ'//$.117<<7;}}7;zzz7;xx7;DI)HII  rc td)z9 Tell whether or not the file is locked. r-r.r3s r is_lockedzLockBase.is_locked4555rc td)zA Return True if this object is locking the file. r-r.r3s r i_am_lockingzLockBase.i_am_lockingrZrc td)zN Remove a lock. Useful if a locking thread failed to unlock. r-r.r3s r break_lockzLockBase.break_lockrZrcBd|jjd|jd|jdS)Nr<r=z -- r>)r?rrUr)r3s rr@zLockBase.__repr__s0#'>#:#:#:D.decor..wrapperHsZD'222D LLNNN tT,V,,  s AA) functoolswraps)rrr)r0s` rdecorzlocked..decorGsC            rr)r)r0rs`` rrr;s)       Lrlinkrdrqrur())r __future__rrrGrJrOrehasattr currentThreadrThreadgetNamer__all__ Exceptionrrrr r r r r objectr&rrorrrrrDrr_llfrsLockFilerv_mlfrwr~rrrrs11f'&&&&& wy*++7(6Iwy,,9 ) 0 8I ! ! !      I                   )        I                 %                    *A*A*A*A*A&*A*A*AZ7.7.7.7.7.{7.7.7.t   %%%%%%%%%2 72v"&&&&&& HH''''''!H r