ó •abc @@sdZddlmZddlZddlZddlZddlZddlZeedƒspej e_ neej dƒs—ej j ej _ ndddd d d d d dddddg Zdefd„ƒYZdefd„ƒYZdefd„ƒYZd efd„ƒYZd efd„ƒYZd efd„ƒYZd efd„ƒYZd efd„ƒYZdefd„ƒYZdefd„ƒYZd„Zd„Zd „Zd!„Zdd"„Z eed#ƒrûd$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(sˆSome 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(s‡Lock 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__.pyRƒscB@seZdZRS(s’Raised 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(sœRaised 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@sAeZd„Zdd„Zd„Zd„Zd„Zd„ZRS(cC@s ||_dS(N(tpath(tselfR((sA/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/__init__.pyt__init__¦scC@stdƒ‚dS(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__.pytacquire©scC@stdƒ‚dS(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__.pytrelease¹scC@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|jƒdS(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__.pyR¥s      cB@sAeZdZedd„Zd„Zd„Zd„Zd„Z RS(s.Base class for platform-specific lock classes.cC@sðtt|ƒj|ƒtjj|ƒd|_tjƒ|_ tj ƒ|_ |r‹t j ƒ}t|dt|ƒƒ}d|d@|_n d|_tjj|jƒ}tjj|d|j |j|j t|jƒfƒ|_||_dS(si >>> lock = LockBase('somefile') >>> lock = LockBase('somefile', threaded=False) s.locktidents-%xIÿÿÿÿts %s%s.%s%sN(tsuperRRtosRtabspatht lock_filetsockett gethostnamethostnametgetpidtpidt threadingRtgetattrthashttnametdirnametjoint unique_nameR(RRtthreadedRttR!R0((sA/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/__init__.pyRÔs     cC@stdƒ‚dS(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_lockedõscC@stdƒ‚dS(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_lockingûscC@stdƒ‚dS(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__.pyRÒs !   cO@smtjd|tddƒt|dtƒs:|d}nt|ƒdkr`| r`t|d4sF                 -: