Viewing File: /opt/alt/python35/lib/python3.5/site-packages/lockfile/__pycache__/__init__.cpython-35.opt-1.pyc



UV$
@s'dZddlmZddlZddlZddlZddlZddlZeedsmej	e_
eejdsejjej_
dddd	d
ddd
dddddg
ZGdddeZGdddeZGdddeZGdd	d	eZGdd
d
eZGdddeZGdddeZGdd
d
eZGdddeZGdddeZddZd dZd!dZd"dZdd#dZeed$rd%d&l m!Z"e"j#Z$nd%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_nameError	LockErrorLockTimeout
AlreadyLocked
LockFailedUnlockError	NotLocked	NotMyLockLinkFileLock
MkdirFileLockSQLiteFileLockLockBaselockedc@seZdZdZdS)rzw
    Base class for other exceptions.

    >>> try:
    ...   raise Error
    ... except Exception:
    ...   pass
    N)__name__
__module____qualname____doc__rr/__init__.pyrJsc@seZdZdZdS)rz
    Base class for error arising from attempts to acquire the lock.

    >>> try:
    ...   raise LockError
    ... except Error:
    ...   pass
    N)rrrrrrrrrVsc@seZdZdZdS)rzRaised when lock creation fails within a user-defined period of time.

    >>> try:
    ...   raise LockTimeout
    ... except LockError:
    ...   pass
    N)rrrrrrrrrbsc@seZdZdZdS)rzSome other thread/process is locking the file.

    >>> try:
    ...   raise AlreadyLocked
    ... except LockError:
    ...   pass
    N)rrrrrrrrrmsc@seZdZdZdS)r	zLock file creation failed for some other reason.

    >>> try:
    ...   raise LockFailed
    ... except LockError:
    ...   pass
    N)rrrrrrrrr	xsc@seZdZdZdS)r
z
    Base class for errors arising from attempts to release the lock.

    >>> try:
    ...   raise UnlockError
    ... except Error:
    ...   pass
    N)rrrrrrrrr
sc@seZdZdZdS)rzRaised when an attempt is made to unlock an unlocked file.

    >>> try:
    ...   raise NotLocked
    ... except UnlockError:
    ...   pass
    N)rrrrrrrrrsc@seZdZdZdS)rzRaised when an attempt is made to unlock a file someone else locked.

    >>> try:
    ...   raise NotMyLock
    ... except UnlockError:
    ...   pass
    N)rrrrrrrrrsc@s[eZdZddZdddZddZdd	Zd
dZdd
ZdS)_SharedBasecCs
||_dS)N)path)selfrrrr__init__sz_SharedBase.__init__NcCstddS)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.
        zimplement in subclassN)NotImplemented)rtimeoutrrracquiresz_SharedBase.acquirecCstddS)zX
        Release the lock.

        If the file is not locked, raise NotLocked.
        zimplement in subclassN)r)rrrrreleasesz_SharedBase.releasecCs|j|S)z*
        Context manager support.
        )r)rrrr	__enter__s
z_SharedBase.__enter__cGs|jdS)z*
        Context manager support.
        N)r)rZ_excrrr__exit__sz_SharedBase.__exit__cCsd|jj|jfS)Nz<%s: %r>)	__class__rr)rrrr__repr__sz_SharedBase.__repr__)	rrrrrrr r!r#rrrrrsrcs^eZdZdZddfddZddZdd	Zd
dZdd
ZS)rz.Base class for platform-specific lock classes.TNcstt|j|tjj|d|_tj|_	tj
|_|rtj
}t|dt|}d|d@|_n	d|_tjj|j}tjj|d|j	|j|jt|jf|_||_dS)zi
        >>> lock = LockBase('somefile')
        >>> lock = LockBase('somefile', threaded=False)
        z.lockidentz-%xlz	%s%s.%s%sN)superrrosrabspathZ	lock_filesocketgethostnamehostnamegetpidpid	threadingrgetattrhashZtnamedirnamejoinunique_namer)rrthreadedrtr$r1)r"rrrs 			zLockBase.__init__cCstddS)z9
        Tell whether or not the file is locked.
        zimplement in subclassN)r)rrrr	is_lockedszLockBase.is_lockedcCstddS)zA
        Return True if this object is locking the file.
        zimplement in subclassN)r)rrrri_am_lockingszLockBase.i_am_lockingcCstddS)zN
        Remove a lock.  Useful if a locking thread failed to unlock.
        zimplement in subclassN)r)rrrr
break_lockszLockBase.break_lockcCsd|jj|j|jfS)Nz<%s: %r -- %r>)r"rr3r)rrrrr#szLockBase.__repr__)	rrrrrr6r7r8r#rr)r"rrs!cOsmtjd|tddt|dts=|dd}t|dkr`|r`d|d<|||S)Nz1Import from %s module instead of lockfile package
stacklevelrTr4)warningswarnDeprecationWarning
isinstancestrlen)clsmodargskwdsrrr
_fl_helpers


rFcOs&ddlm}t|jd||S)zFactory function provided for backwards compatibility.

    Do not use in new code.  Instead, import LinkLockFile from the
    lockfile.linklockfile module.
    r;)linklockfilezlockfile.linklockfile)r%rGrFLinkLockFile)rDrErGrrrr
scOs&ddlm}t|jd||S)zFactory function provided for backwards compatibility.

    Do not use in new code.  Instead, import MkdirLockFile from the
    lockfile.mkdirlockfile module.
    r;)
mkdirlockfilezlockfile.mkdirlockfile)r%rIrF
MkdirLockFile)rDrErIrrrr%scOs&ddlm}t|jd||S)zFactory function provided for backwards compatibility.

    Do not use in new code.  Instead, import SQLiteLockFile from the
    lockfile.mkdirlockfile module.
    r;)sqlitelockfilezlockfile.sqlitelockfile)r%rKrFZSQLiteLockFile)rDrErKrrrr0scsfdd}|S)aDecorator which enables locks for decorated function.

    Arguments:
     - path: path for lockfile.
     - timeout (optional): Timeout for acquiring lock.

     Usage:
         @locked('/var/run/myname', timeout=0)
         def myname(...):
             ...
    cs+tjfdd}|S)Nc
s?td}|jz||SWd|jXdS)Nr)FileLockrr)rDkwargslock)funcrrrrwrapperHs

z&locked.<locals>.decor.<locals>.wrapper)	functoolswraps)rOrP)rr)rOrdecorGs'zlocked.<locals>.decorr)rrrSr)rrrr;s
linkr;)rG)rI))rZ
__future__rrQr'r)r.r<hasattr
currentThreadrThreadgetNamer__all__	Exceptionrrrrr	r
rrobjectrrrFr
rrrr%rGZ_llfrHZLockFilerIZ_mlfrJrLrrrr<module>4sF	-:	
Back to Directory File Manager