abc @@sdZddlmZddlZddlZddlZddlZddlZeedspej e_ neej dsej j ej _ ndddd d d d d dddddg ZdefdYZdefdYZdefdYZd efdYZd efdYZd efdYZd efdYZd efdYZdefdYZdefdYZdZdZd Zd!Zdd"Z eed#rd$d%l!m"Z#e#j$Z%nd$d&l!m&Z'e'j(Z%e%Z)dS('s 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 i(tabsolute_importNtcurrent_threadtget_nametErrort LockErrort LockTimeoutt AlreadyLockedt LockFailedt UnlockErrort NotLockedt NotMyLockt LinkFileLockt MkdirFileLocktSQLiteFileLocktLockBasetlockedcB@seZdZRS(sw Base class for other exceptions. >>> try: ... raise Error ... except Exception: ... pass (t__name__t __module__t__doc__(((sA/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/__init__.pyRJscB@seZdZRS(s Base class for error arising from attempts to acquire the lock. >>> try: ... raise LockError ... except Error: ... pass (RRR(((sA/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/__init__.pyRVscB@seZdZRS(sRaised when lock creation fails within a user-defined period of time. >>> try: ... raise LockTimeout ... except LockError: ... pass (RRR(((sA/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/__init__.pyRbscB@seZdZRS(sSome other thread/process is locking the file. >>> try: ... raise AlreadyLocked ... except LockError: ... pass (RRR(((sA/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/__init__.pyRmscB@seZdZRS(sLock file creation failed for some other reason. >>> try: ... raise LockFailed ... except LockError: ... pass (RRR(((sA/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/__init__.pyRxscB@seZdZRS(s Base class for errors arising from attempts to release the lock. >>> try: ... raise UnlockError ... except Error: ... pass (RRR(((sA/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/__init__.pyRscB@seZdZRS(sRaised when an attempt is made to unlock an unlocked file. >>> try: ... raise NotLocked ... except UnlockError: ... pass (RRR(((sA/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/__init__.pyR scB@seZdZRS(sRaised when an attempt is made to unlock a file someone else locked. >>> try: ... raise NotMyLock ... except UnlockError: ... pass (RRR(((sA/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/__init__.pyR st _SharedBasecB@sAeZdZddZdZdZdZdZRS(cC@s ||_dS(N(tpath(tselfR((sA/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/__init__.pyt__init__scC@stddS(s 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. simplement in subclassN(tNotImplemented(Rttimeout((sA/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/__init__.pytacquirescC@stddS(sX Release the lock. If the file is not locked, raise NotLocked. simplement in subclassN(R(R((sA/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/__init__.pytreleasescC@s|j|S(s* Context manager support. (R(R((sA/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/__init__.pyt __enter__s cG@s|jdS(s* Context manager support. N(R(Rt_exc((sA/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/__init__.pyt__exit__scC@sd|jj|jfS(Ns<%s: %r>(t __class__RR(R((sA/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/__init__.pyt__repr__sN( RRRtNoneRRRRR(((sA/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/__init__.pyRs      cB@sAeZdZeddZdZdZdZdZ RS(s.Base class for platform-specific lock classes.cC@stt|j|tjj|d|_tj|_ tj |_ |rt j }t|dt|}d|d@|_n d|_tjj|j}tjj|d|j |j|j t|jf|_||_dS(si >>> lock = LockBase('somefile') >>> lock = LockBase('somefile', threaded=False) s.locktidents-%xIts %s%s.%s%sN(tsuperRRtosRtabspatht lock_filetsockett gethostnamethostnametgetpidtpidt threadingRtgetattrthashttnametdirnametjoint unique_nameR(RRtthreadedRttR!R0((sA/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/__init__.pyRs     cC@stddS(s9 Tell whether or not the file is locked. simplement in subclassN(R(R((sA/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/__init__.pyt is_lockedscC@stddS(sA Return True if this object is locking the file. simplement in subclassN(R(R((sA/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/__init__.pyt i_am_lockingscC@stddS(sN Remove a lock. Useful if a locking thread failed to unlock. simplement in subclassN(R(R((sA/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/__init__.pyt break_lockscC@sd|jj|j|jfS(Ns<%s: %r -- %r>(RRR2R(R((sA/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/__init__.pyRsN( RRRtTrueR RR5R6R7R(((sA/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/__init__.pyRs !   cO@smtjd|tddt|dts:|d}nt|dkr`| r`t|d4sF                 -: