Warning: file_get_contents(https://raw.githubusercontent.com/Den1xxx/Filemanager/master/languages/ru.json): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 88

Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 215

Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 216

Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 217

Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 218

Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 219

Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 220
PK!#$$ __init__.pynu[# -*- coding: utf-8 -*- """ 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 """ from __future__ import absolute_import import functools import os import socket import threading import warnings # Work with PEP8 and non-PEP8 versions of threading module. if not hasattr(threading, "current_thread"): threading.current_thread = threading.currentThread if not hasattr(threading.Thread, "get_name"): threading.Thread.get_name = threading.Thread.getName __all__ = ['Error', 'LockError', 'LockTimeout', 'AlreadyLocked', 'LockFailed', 'UnlockError', 'NotLocked', 'NotMyLock', 'LinkFileLock', 'MkdirFileLock', 'SQLiteFileLock', 'LockBase', 'locked'] class Error(Exception): """ Base class for other exceptions. >>> try: ... raise Error ... except Exception: ... pass """ pass class LockError(Error): """ Base class for error arising from attempts to acquire the lock. >>> try: ... raise LockError ... except Error: ... pass """ pass class LockTimeout(LockError): """Raised when lock creation fails within a user-defined period of time. >>> try: ... raise LockTimeout ... except LockError: ... pass """ pass class AlreadyLocked(LockError): """Some other thread/process is locking the file. >>> try: ... raise AlreadyLocked ... except LockError: ... pass """ pass class LockFailed(LockError): """Lock file creation failed for some other reason. >>> try: ... raise LockFailed ... except LockError: ... pass """ pass class UnlockError(Error): """ Base class for errors arising from attempts to release the lock. >>> try: ... raise UnlockError ... except Error: ... pass """ pass class NotLocked(UnlockError): """Raised when an attempt is made to unlock an unlocked file. >>> try: ... raise NotLocked ... except UnlockError: ... pass """ pass class NotMyLock(UnlockError): """Raised when an attempt is made to unlock a file someone else locked. >>> try: ... raise NotMyLock ... except UnlockError: ... pass """ pass class _SharedBase(object): def __init__(self, path): self.path = path def acquire(self, timeout=None): """ 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. """ raise NotImplemented("implement in subclass") def release(self): """ Release the lock. If the file is not locked, raise NotLocked. """ raise NotImplemented("implement in subclass") def __enter__(self): """ Context manager support. """ self.acquire() return self def __exit__(self, *_exc): """ Context manager support. """ self.release() def __repr__(self): return "<%s: %r>" % (self.__class__.__name__, self.path) class LockBase(_SharedBase): """Base class for platform-specific lock classes.""" def __init__(self, path, threaded=True, timeout=None): """ >>> lock = LockBase('somefile') >>> lock = LockBase('somefile', threaded=False) """ super(LockBase, self).__init__(path) self.lock_file = os.path.abspath(path) + ".lock" self.hostname = socket.gethostname() self.pid = os.getpid() if threaded: t = threading.current_thread() # Thread objects in Python 2.4 and earlier do not have ident # attrs. Worm around that. ident = getattr(t, "ident", hash(t)) self.tname = "-%x" % (ident & 0xffffffff) else: self.tname = "" dirname = os.path.dirname(self.lock_file) # unique name is mostly about the current process, but must # also contain the path -- otherwise, two adjacent locked # files conflict (one file gets locked, creating lock-file and # unique file, the other one gets locked, creating lock-file # and overwriting the already existing lock-file, then one # gets unlocked, deleting both lock-file and unique file, # finally the last lock errors out upon releasing. self.unique_name = os.path.join(dirname, "%s%s.%s%s" % (self.hostname, self.tname, self.pid, hash(self.path))) self.timeout = timeout def is_locked(self): """ Tell whether or not the file is locked. """ raise NotImplemented("implement in subclass") def i_am_locking(self): """ Return True if this object is locking the file. """ raise NotImplemented("implement in subclass") def break_lock(self): """ Remove a lock. Useful if a locking thread failed to unlock. """ raise NotImplemented("implement in subclass") def __repr__(self): return "<%s: %r -- %r>" % (self.__class__.__name__, self.unique_name, self.path) def _fl_helper(cls, mod, *args, **kwds): warnings.warn("Import from %s module instead of lockfile package" % mod, DeprecationWarning, stacklevel=2) # This is a bit funky, but it's only for awhile. The way the unit tests # are constructed this function winds up as an unbound method, so it # actually takes three args, not two. We want to toss out self. if not isinstance(args[0], str): # We are testing, avoid the first arg args = args[1:] if len(args) == 1 and not kwds: kwds["threaded"] = True return cls(*args, **kwds) def LinkFileLock(*args, **kwds): """Factory function provided for backwards compatibility. Do not use in new code. Instead, import LinkLockFile from the lockfile.linklockfile module. """ from . import linklockfile return _fl_helper(linklockfile.LinkLockFile, "lockfile.linklockfile", *args, **kwds) def MkdirFileLock(*args, **kwds): """Factory function provided for backwards compatibility. Do not use in new code. Instead, import MkdirLockFile from the lockfile.mkdirlockfile module. """ from . import mkdirlockfile return _fl_helper(mkdirlockfile.MkdirLockFile, "lockfile.mkdirlockfile", *args, **kwds) def SQLiteFileLock(*args, **kwds): """Factory function provided for backwards compatibility. Do not use in new code. Instead, import SQLiteLockFile from the lockfile.mkdirlockfile module. """ from . import sqlitelockfile return _fl_helper(sqlitelockfile.SQLiteLockFile, "lockfile.sqlitelockfile", *args, **kwds) def locked(path, timeout=None): """Decorator 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(...): ... """ def decor(func): @functools.wraps(func) def wrapper(*args, **kwargs): lock = FileLock(path, timeout=timeout) lock.acquire() try: return func(*args, **kwargs) finally: lock.release() return wrapper return decor if hasattr(os, "link"): from . import linklockfile as _llf LockFile = _llf.LinkLockFile else: from . import mkdirlockfile as _mlf LockFile = _mlf.MkdirLockFile FileLock = LockFile PK!Ǟ+P/P/ __init__.pyonu[ 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                 -:    PK!!&~  mkdirlockfile.pynu[from __future__ import absolute_import, division import time import os import sys import errno from . import (LockBase, LockFailed, NotLocked, NotMyLock, LockTimeout, AlreadyLocked) class MkdirLockFile(LockBase): """Lock file by creating a directory.""" def __init__(self, path, threaded=True, timeout=None): """ >>> lock = MkdirLockFile('somefile') >>> lock = MkdirLockFile('somefile', threaded=False) """ LockBase.__init__(self, path, threaded, timeout) # Lock file itself is a directory. Place the unique file name into # it. self.unique_name = os.path.join(self.lock_file, "%s.%s%s" % (self.hostname, self.tname, self.pid)) def acquire(self, timeout=None): timeout = timeout if timeout is not None else self.timeout end_time = time.time() if timeout is not None and timeout > 0: end_time += timeout if timeout is None: wait = 0.1 else: wait = max(0, timeout / 10) while True: try: os.mkdir(self.lock_file) except OSError: err = sys.exc_info()[1] if err.errno == errno.EEXIST: # Already locked. if os.path.exists(self.unique_name): # Already locked by me. return if timeout is not None and time.time() > end_time: if timeout > 0: raise LockTimeout("Timeout waiting to acquire" " lock for %s" % self.path) else: # Someone else has the lock. raise AlreadyLocked("%s is already locked" % self.path) time.sleep(wait) else: # Couldn't create the lock for some other reason raise LockFailed("failed to create %s" % self.lock_file) else: open(self.unique_name, "wb").close() return def release(self): if not self.is_locked(): raise NotLocked("%s is not locked" % self.path) elif not os.path.exists(self.unique_name): raise NotMyLock("%s is locked, but not by me" % self.path) os.unlink(self.unique_name) os.rmdir(self.lock_file) def is_locked(self): return os.path.exists(self.lock_file) def i_am_locking(self): return (self.is_locked() and os.path.exists(self.unique_name)) def break_lock(self): if os.path.exists(self.lock_file): for name in os.listdir(self.lock_file): os.unlink(os.path.join(self.lock_file, name)) os.rmdir(self.lock_file) PK!|pidlockfile.pycnu[ abc@@sdZddlmZddlZddlZddlZddlmZmZm Z m Z m Z m Z defdYZ dZd Zd ZdS( s8 Lockfile behaviour implemented via Unix PID files. i(tabsolute_importNi(tLockBaset AlreadyLockedt LockFailedt NotLockedt NotMyLockt LockTimeoutt PIDLockFilecB@sVeZdZeddZdZdZdZddZ dZ dZ RS( sA Lockfile implemented as a Unix PID file. The lock file is a normal file named by the attribute `path`. A lock's PID file contains a single line of text, containing the process ID (PID) of the process that acquired the lock. >>> lock = PIDLockFile('somefile') >>> lock = PIDLockFile('somefile') cC@s&tj||t||j|_dS(N(Rt__init__tFalsetpatht unique_name(tselfR tthreadedttimeout((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyR$scC@s t|jS(s- Get the PID from the lock file. (tread_pid_from_pidfileR (R ((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pytread_pid*scC@stjj|jS(sv Test if the lock is currently held. The lock is held if the PID file for this lock exists. (tosR texists(R ((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyt is_locked/scC@s"|jo!tj|jkS(s Test if the lock is held by the current process. Returns ``True`` if the current process ID matches the number stored in the PID file. (RRtgetpidR(R ((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyt i_am_locking7scC@s)|dk r|n|j}tj}|dk rL|dkrL||7}nxtr$yt|jWntk r}|jtjkrtj|kr|dk r|dkrt d|jqt d|jntj |dk r|dpdq!t d|jqOXdSqOWdS(s Acquire the lock. Creates the PID file for this lock, or raises an error if the lock could not be acquired. is&Timeout waiting to acquire lock for %ss%s is already lockedi g?sfailed to create %sN( tNoneRttimetTruetwrite_pid_to_pidfileR tOSErrorterrnotEEXISTRRtsleepR(R Rtend_timetexc((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pytacquire?s$   &cC@sU|js"td|jn|jsDtd|jnt|jdS(s Release the lock. Removes the PID file to release the lock, or raises an error if the current process does not hold the lock. s%s is not lockeds%s is locked, but not by meN(RRR RRtremove_existing_pidfile(R ((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pytrelease_s   cC@st|jdS(s Break an existing lock. Removes the PID file if it already exists, otherwise does nothing. N(R!R (R ((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyt break_locklsN( t__name__t __module__t__doc__R RRRRRR R"R#(((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyRs     cC@sqd}yt|d}Wntk r,nAX|jj}yt|}Wntk rbnX|j|S(s Read the PID recorded in the named PID file. Read and return the numeric PID recorded as text in the named PID file. If the PID file cannot be read, or if the content is not a valid PID, return ``None``. trN(RtopentIOErrortreadlinetstriptintt ValueErrortclose(t pidfile_pathtpidtpidfiletline((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyRvs    cC@sotjtjBtjB}d}tj|||}tj|d}tj}|jd||jdS(s Write the PID in the named PID file. Get the numeric process ID (“PID”) of the current process and write it to the named file as a line of text. itws%s N( RtO_CREATtO_EXCLtO_WRONLYR(tfdopenRtwriteR.(R/t open_flagst open_modet pidfile_fdR1R0((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyRs cC@sCytj|Wn+tk r>}|jtjkr8q?nXdS(s Remove the named PID file if it exists. Removing a PID file that doesn't already exist puts us in the desired state, so we ignore the condition if the file does not exist. N(RtremoveRRtENOENT(R/R((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyR!s (R&t __future__RRRRtRRRRRRRRRR!(((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyt s   .] " PK!iY] ] linklockfile.pyonu[ abc@@spddlmZddlZddlZddlmZmZmZmZm Z m Z defdYZ dS(i(tabsolute_importNi(tLockBaset LockFailedt NotLockedt NotMyLockt LockTimeoutt AlreadyLockedt LinkLockFilecB@s>eZdZddZdZdZdZdZRS(sLock access to a file using atomic property of link(2). >>> lock = LinkLockFile('somefile') >>> lock = LinkLockFile('somefile', threaded=False) cC@s~yt|jdjWn$tk r@td|jnX|dk rS|n|j}tj}|dk r|dkr||7}nxtryyt j |j|j Wnt k rqt j |jj}|dkrdS|dk rKtj|krKt j|j|dkr5td|jqKtd|jntj|dk rg|dpjdqXdSqWdS( Ntwbsfailed to create %siis&Timeout waiting to acquire lock for %ss%s is already lockedi g?(topent unique_nametclosetIOErrorRtNonettimeoutttimetTruetostlinkt lock_filetOSErrortstattst_nlinktunlinkRtpathRtsleep(tselfRtend_timetnlinks((sE/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/linklockfile.pytacquires0       'cC@sq|js"td|jn+tjj|jsMtd|jntj|jtj|jdS(Ns%s is not lockeds%s is locked, but not by me( t is_lockedRRRtexistsR RRR(R((sE/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/linklockfile.pytrelease7s  cC@stjj|jS(N(RRRR(R((sE/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/linklockfile.pyR?scC@s:|jo9tjj|jo9tj|jjdkS(Ni(RRRRR RR(R((sE/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/linklockfile.pyt i_am_lockingBs cC@s,tjj|jr(tj|jndS(N(RRRRR(R((sE/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/linklockfile.pyt break_lockGsN( t__name__t __module__t__doc__R RR RR!R"(((sE/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/linklockfile.pyR s  &   ( t __future__RRRtRRRRRRR(((sE/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/linklockfile.pyts  .PK!_] symlinklockfile.pycnu[ abc@@sjddlmZddlZddlZddlmZmZmZmZm Z defdYZ dS(i(tabsolute_importNi(tLockBaset NotLockedt NotMyLockt LockTimeoutt AlreadyLockedtSymlinkLockFilecB@sMeZdZeddZddZdZdZdZ dZ RS(s'Lock access to a file using symlink(2).cC@s6tj||||tjj|jd|_dS(Ni(Rt__init__tostpathtsplitt unique_name(tselfR tthreadedttimeout((sH/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/symlinklockfile.pyR scC@s|dk r|n|j}tj}|dk rL|dkrL||7}nxtrytj|j|jWntk r |j rdS|dk rtj|kr|dkrt d|j qt d|j ntj |dk r|dndqOXdSqOWdS(Nis&Timeout waiting to acquire lock for %ss%s is already lockedi g?(tNoneRttimetTrueRtsymlinkR t lock_filetOSErrort i_am_lockingRR Rtsleep(R Rtend_time((sH/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/symlinklockfile.pytacquires$      'cC@sX|js"td|jn"|jsDtd|jntj|jdS(Ns%s is not lockeds%s is locked, but not by me(t is_lockedRR RRRtunlinkR(R ((sH/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/symlinklockfile.pytrelease6s   cC@stjj|jS(N(RR tislinkR(R ((sH/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/symlinklockfile.pyR=scC@s.tjj|jo-tj|j|jkS(N(RR RRtreadlinkR (R ((sH/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/symlinklockfile.pyR@scC@s,tjj|jr(tj|jndS(N(RR RRR(R ((sH/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/symlinklockfile.pyt break_lockDsN( t__name__t __module__t__doc__RRRRRRRR(((sH/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/symlinklockfile.pyR s #   ( t __future__RRRtRRRRRR(((sH/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/symlinklockfile.pyts  (PK!_] symlinklockfile.pyonu[ abc@@sjddlmZddlZddlZddlmZmZmZmZm Z defdYZ dS(i(tabsolute_importNi(tLockBaset NotLockedt NotMyLockt LockTimeoutt AlreadyLockedtSymlinkLockFilecB@sMeZdZeddZddZdZdZdZ dZ RS(s'Lock access to a file using symlink(2).cC@s6tj||||tjj|jd|_dS(Ni(Rt__init__tostpathtsplitt unique_name(tselfR tthreadedttimeout((sH/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/symlinklockfile.pyR scC@s|dk r|n|j}tj}|dk rL|dkrL||7}nxtrytj|j|jWntk r |j rdS|dk rtj|kr|dkrt d|j qt d|j ntj |dk r|dndqOXdSqOWdS(Nis&Timeout waiting to acquire lock for %ss%s is already lockedi g?(tNoneRttimetTrueRtsymlinkR t lock_filetOSErrort i_am_lockingRR Rtsleep(R Rtend_time((sH/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/symlinklockfile.pytacquires$      'cC@sX|js"td|jn"|jsDtd|jntj|jdS(Ns%s is not lockeds%s is locked, but not by me(t is_lockedRR RRRtunlinkR(R ((sH/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/symlinklockfile.pytrelease6s   cC@stjj|jS(N(RR tislinkR(R ((sH/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/symlinklockfile.pyR=scC@s.tjj|jo-tj|j|jkS(N(RR RRtreadlinkR (R ((sH/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/symlinklockfile.pyR@scC@s,tjj|jr(tj|jndS(N(RR RRR(R ((sH/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/symlinklockfile.pyt break_lockDsN( t__name__t __module__t__doc__RRRRRRRR(((sH/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/symlinklockfile.pyR s #   ( t __future__RRRtRRRRRR(((sH/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/symlinklockfile.pyts  (PK!6$hb b mkdirlockfile.pyonu[ abc@`sddlmZmZddlZddlZddlZddlZddlmZm Z m Z m Z m Z m Z defdYZdS(i(tabsolute_importtdivisionNi(tLockBaset LockFailedt NotLockedt NotMyLockt LockTimeoutt AlreadyLockedt MkdirLockFilecB`sMeZdZeddZddZdZdZdZ dZ RS(s"Lock file by creating a directory.cC`sKtj||||tjj|jd|j|j|jf|_ dS(ss >>> lock = MkdirLockFile('somefile') >>> lock = MkdirLockFile('somefile', threaded=False) s%s.%s%sN( Rt__init__tostpathtjoint lock_filethostnamettnametpidt unique_name(tselfR tthreadedttimeout((sF/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/mkdirlockfile.pyR s  cC`s{|dk r|n|j}tj}|dk rL|dkrL||7}n|dkrad}ntd|d}xtrvytj|jWntk rXt j d}|j t j krBtj j|jrdS|dk r2tj|kr2|dkrtd|j q2td|j ntj|qstd|jqwXt|jdjdSqwWdS( Nig?i is&Timeout waiting to acquire lock for %ss%s is already lockedsfailed to create %stwb(tNoneRttimetmaxtTrueR tmkdirR tOSErrortsystexc_infoterrnotEEXISTR texistsRRRtsleepRtopentclose(RRtend_timetwaitterr((sF/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/mkdirlockfile.pytacquires2       cC`sq|js"td|jn+tjj|jsMtd|jntj|jtj|j dS(Ns%s is not lockeds%s is locked, but not by me( t is_lockedRR R R RRtunlinktrmdirR (R((sF/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/mkdirlockfile.pytreleaseAs  cC`stjj|jS(N(R R R R (R((sF/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/mkdirlockfile.pyR(IscC`s|jotjj|jS(N(R(R R R R(R((sF/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/mkdirlockfile.pyt i_am_lockingLs cC`shtjj|jrdx9tj|jD]%}tjtjj|j|q(Wtj|jndS(N(R R R R tlistdirR)R R*(Rtname((sF/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/mkdirlockfile.pyt break_lockPs#N( t__name__t __module__t__doc__RRR R'R+R(R,R/(((sF/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/mkdirlockfile.pyR s &   (t __future__RRRR RRtRRRRRRR(((sF/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/mkdirlockfile.pyts     .PK!6$hb b mkdirlockfile.pycnu[ abc@`sddlmZmZddlZddlZddlZddlZddlmZm Z m Z m Z m Z m Z defdYZdS(i(tabsolute_importtdivisionNi(tLockBaset LockFailedt NotLockedt NotMyLockt LockTimeoutt AlreadyLockedt MkdirLockFilecB`sMeZdZeddZddZdZdZdZ dZ RS(s"Lock file by creating a directory.cC`sKtj||||tjj|jd|j|j|jf|_ dS(ss >>> lock = MkdirLockFile('somefile') >>> lock = MkdirLockFile('somefile', threaded=False) s%s.%s%sN( Rt__init__tostpathtjoint lock_filethostnamettnametpidt unique_name(tselfR tthreadedttimeout((sF/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/mkdirlockfile.pyR s  cC`s{|dk r|n|j}tj}|dk rL|dkrL||7}n|dkrad}ntd|d}xtrvytj|jWntk rXt j d}|j t j krBtj j|jrdS|dk r2tj|kr2|dkrtd|j q2td|j ntj|qstd|jqwXt|jdjdSqwWdS( Nig?i is&Timeout waiting to acquire lock for %ss%s is already lockedsfailed to create %stwb(tNoneRttimetmaxtTrueR tmkdirR tOSErrortsystexc_infoterrnotEEXISTR texistsRRRtsleepRtopentclose(RRtend_timetwaitterr((sF/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/mkdirlockfile.pytacquires2       cC`sq|js"td|jn+tjj|jsMtd|jntj|jtj|j dS(Ns%s is not lockeds%s is locked, but not by me( t is_lockedRR R R RRtunlinktrmdirR (R((sF/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/mkdirlockfile.pytreleaseAs  cC`stjj|jS(N(R R R R (R((sF/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/mkdirlockfile.pyR(IscC`s|jotjj|jS(N(R(R R R R(R((sF/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/mkdirlockfile.pyt i_am_lockingLs cC`shtjj|jrdx9tj|jD]%}tjtjj|j|q(Wtj|jndS(N(R R R R tlistdirR)R R*(Rtname((sF/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/mkdirlockfile.pyt break_lockPs#N( t__name__t __module__t__doc__RRR R'R+R(R,R/(((sF/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/mkdirlockfile.pyR s &   (t __future__RRRR RRtRRRRRRR(((sF/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/mkdirlockfile.pyts     .PK!g}Ha__sqlitelockfile.pyonu[ abc@`sddlmZmZddlZddlZyeWnek rOeZnXddlm Z m Z m Z m Z m Z de fdYZdS(i(tabsolute_importtdivisionNi(tLockBaset NotLockedt NotMyLockt LockTimeoutt AlreadyLockedtSQLiteLockFilecB`s\eZdZdZeddZddZdZdZ dZ dZ dZ RS( sDemonstrate SQL-based locking.c C`stj||||t|j|_t|j|_tjdkrddl}|j \}}t j |t j |~~|t_nddl }|jtj|_|jj}y|jdWn|jk rn0X|jjddl} | jt j tjdS(su >>> lock = SQLiteLockFile('somefile') >>> lock = SQLiteLockFile('somefile', threaded=False) iNsGcreate table locks( lock_file varchar(32), unique_name varchar(32))(Rt__init__tunicodet lock_filet unique_nameRttestdbtNonettempfiletmkstemptostclosetunlinktsqlite3tconnectt connectiontcursortexecutetOperationalErrortcommittatexittregister( tselftpathtthreadedttimeoutRt_fdR RtcR((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pyRs(       cC`s|dk r|n|j}tj}|dk rL|dkrL||7}n|dkrad}n|dkrvd}n |d}|jj}x;tr|js.|jd|j|j f|jj |jd|j f|j }t |dkr'|jd|j f|jj qfdSn8|jd|j f|j }t |dkrfdS|dk rtj|kr|dkrt d|jqtd |jntj|qWdS( Nig?i s;insert into locks (lock_file, unique_name) values (?, ?)s*select * from locks where unique_name = ?is(delete from locks where unique_name = ?s&Timeout waiting to acquire lock for %ss%s is already locked(R RttimeRRtTruet is_lockedRR R RtfetchalltlenRRRtsleep(RRtend_timetwaitRtrows((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pytacquire5sD                    cC`s|js"td|jn|jsPtd|j|jfn|jj}|j d|jf|jj dS(Ns%s is not lockeds#%s is locked, but not by me (by %s)s(delete from locks where unique_name = ?( R$RRt i_am_lockingRR t_who_is_lockingRRRR(RR((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pytreleasets    cC`s3|jj}|jd|jf|jdS(Ns2select unique_name from locks where lock_file = ?i(RRRR tfetchone(RR((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pyR-s  cC`s7|jj}|jd|jf|j}| S(Ns(select * from locks where lock_file = ?(RRRR R%(RRR*((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pyR$s    cC`s7|jj}|jd|j|jf|j S(Ns?select * from locks where lock_file = ? and unique_name = ?(RRRR R R%(RR((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pyR,s cC`s6|jj}|jd|jf|jjdS(Ns&delete from locks where lock_file = ?(RRRR R(RR((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pyt break_locks  N( t__name__t __module__t__doc__R R R#RR+R.R-R$R,R0(((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pyRs" ?   (t __future__RRR"RR t NameErrortstrtRRRRRR(((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pyts    (PK!# 8 8 symlinklockfile.pynu[from __future__ import absolute_import import os import time from . import (LockBase, NotLocked, NotMyLock, LockTimeout, AlreadyLocked) class SymlinkLockFile(LockBase): """Lock access to a file using symlink(2).""" def __init__(self, path, threaded=True, timeout=None): # super(SymlinkLockFile).__init(...) LockBase.__init__(self, path, threaded, timeout) # split it back! self.unique_name = os.path.split(self.unique_name)[1] def acquire(self, timeout=None): # Hopefully unnecessary for symlink. # try: # open(self.unique_name, "wb").close() # except IOError: # raise LockFailed("failed to create %s" % self.unique_name) timeout = timeout if timeout is not None else self.timeout end_time = time.time() if timeout is not None and timeout > 0: end_time += timeout while True: # Try and create a symbolic link to it. try: os.symlink(self.unique_name, self.lock_file) except OSError: # Link creation failed. Maybe we've double-locked? if self.i_am_locking(): # Linked to out unique name. Proceed. return else: # Otherwise the lock creation failed. if timeout is not None and time.time() > end_time: if timeout > 0: raise LockTimeout("Timeout waiting to acquire" " lock for %s" % self.path) else: raise AlreadyLocked("%s is already locked" % self.path) time.sleep(timeout / 10 if timeout is not None else 0.1) else: # Link creation succeeded. We're good to go. return def release(self): if not self.is_locked(): raise NotLocked("%s is not locked" % self.path) elif not self.i_am_locking(): raise NotMyLock("%s is locked, but not by me" % self.path) os.unlink(self.lock_file) def is_locked(self): return os.path.islink(self.lock_file) def i_am_locking(self): return (os.path.islink(self.lock_file) and os.readlink(self.lock_file) == self.unique_name) def break_lock(self): if os.path.islink(self.lock_file): # exists && link os.unlink(self.lock_file) PK! # # This is free software: you may copy, modify, and/or distribute this work # under the terms of the Python Software Foundation License, version 2 or # later as published by the Python Software Foundation. # No warranty expressed or implied. See the file LICENSE.PSF-2 for details. """ Lockfile behaviour implemented via Unix PID files. """ from __future__ import absolute_import import errno import os import time from . import (LockBase, AlreadyLocked, LockFailed, NotLocked, NotMyLock, LockTimeout) class PIDLockFile(LockBase): """ Lockfile implemented as a Unix PID file. The lock file is a normal file named by the attribute `path`. A lock's PID file contains a single line of text, containing the process ID (PID) of the process that acquired the lock. >>> lock = PIDLockFile('somefile') >>> lock = PIDLockFile('somefile') """ def __init__(self, path, threaded=False, timeout=None): # pid lockfiles don't support threaded operation, so always force # False as the threaded arg. LockBase.__init__(self, path, False, timeout) self.unique_name = self.path def read_pid(self): """ Get the PID from the lock file. """ return read_pid_from_pidfile(self.path) def is_locked(self): """ Test if the lock is currently held. The lock is held if the PID file for this lock exists. """ return os.path.exists(self.path) def i_am_locking(self): """ Test if the lock is held by the current process. Returns ``True`` if the current process ID matches the number stored in the PID file. """ return self.is_locked() and os.getpid() == self.read_pid() def acquire(self, timeout=None): """ Acquire the lock. Creates the PID file for this lock, or raises an error if the lock could not be acquired. """ timeout = timeout if timeout is not None else self.timeout end_time = time.time() if timeout is not None and timeout > 0: end_time += timeout while True: try: write_pid_to_pidfile(self.path) except OSError as exc: if exc.errno == errno.EEXIST: # The lock creation failed. Maybe sleep a bit. if time.time() > end_time: if timeout is not None and timeout > 0: raise LockTimeout("Timeout waiting to acquire" " lock for %s" % self.path) else: raise AlreadyLocked("%s is already locked" % self.path) time.sleep(timeout is not None and timeout / 10 or 0.1) else: raise LockFailed("failed to create %s" % self.path) else: return def release(self): """ Release the lock. Removes the PID file to release the lock, or raises an error if the current process does not hold the lock. """ if not self.is_locked(): raise NotLocked("%s is not locked" % self.path) if not self.i_am_locking(): raise NotMyLock("%s is locked, but not by me" % self.path) remove_existing_pidfile(self.path) def break_lock(self): """ Break an existing lock. Removes the PID file if it already exists, otherwise does nothing. """ remove_existing_pidfile(self.path) def read_pid_from_pidfile(pidfile_path): """ Read the PID recorded in the named PID file. Read and return the numeric PID recorded as text in the named PID file. If the PID file cannot be read, or if the content is not a valid PID, return ``None``. """ pid = None try: pidfile = open(pidfile_path, 'r') except IOError: pass else: # According to the FHS 2.3 section on PID files in /var/run: # # The file must consist of the process identifier in # ASCII-encoded decimal, followed by a newline character. # # Programs that read PID files should be somewhat flexible # in what they accept; i.e., they should ignore extra # whitespace, leading zeroes, absence of the trailing # newline, or additional lines in the PID file. line = pidfile.readline().strip() try: pid = int(line) except ValueError: pass pidfile.close() return pid def write_pid_to_pidfile(pidfile_path): """ Write the PID in the named PID file. Get the numeric process ID (“PID”) of the current process and write it to the named file as a line of text. """ open_flags = (os.O_CREAT | os.O_EXCL | os.O_WRONLY) open_mode = 0o644 pidfile_fd = os.open(pidfile_path, open_flags, open_mode) pidfile = os.fdopen(pidfile_fd, 'w') # According to the FHS 2.3 section on PID files in /var/run: # # The file must consist of the process identifier in # ASCII-encoded decimal, followed by a newline character. For # example, if crond was process number 25, /var/run/crond.pid # would contain three characters: two, five, and newline. pid = os.getpid() pidfile.write("%s\n" % pid) pidfile.close() def remove_existing_pidfile(pidfile_path): """ Remove the named PID file if it exists. Removing a PID file that doesn't already exist puts us in the desired state, so we ignore the condition if the file does not exist. """ try: os.remove(pidfile_path) except OSError as exc: if exc.errno == errno.ENOENT: pass else: raise PK!iY] ] linklockfile.pycnu[ abc@@spddlmZddlZddlZddlmZmZmZmZm Z m Z defdYZ dS(i(tabsolute_importNi(tLockBaset LockFailedt NotLockedt NotMyLockt LockTimeoutt AlreadyLockedt LinkLockFilecB@s>eZdZddZdZdZdZdZRS(sLock access to a file using atomic property of link(2). >>> lock = LinkLockFile('somefile') >>> lock = LinkLockFile('somefile', threaded=False) cC@s~yt|jdjWn$tk r@td|jnX|dk rS|n|j}tj}|dk r|dkr||7}nxtryyt j |j|j Wnt k rqt j |jj}|dkrdS|dk rKtj|krKt j|j|dkr5td|jqKtd|jntj|dk rg|dpjdqXdSqWdS( Ntwbsfailed to create %siis&Timeout waiting to acquire lock for %ss%s is already lockedi g?(topent unique_nametclosetIOErrorRtNonettimeoutttimetTruetostlinkt lock_filetOSErrortstattst_nlinktunlinkRtpathRtsleep(tselfRtend_timetnlinks((sE/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/linklockfile.pytacquires0       'cC@sq|js"td|jn+tjj|jsMtd|jntj|jtj|jdS(Ns%s is not lockeds%s is locked, but not by me( t is_lockedRRRtexistsR RRR(R((sE/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/linklockfile.pytrelease7s  cC@stjj|jS(N(RRRR(R((sE/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/linklockfile.pyR?scC@s:|jo9tjj|jo9tj|jjdkS(Ni(RRRRR RR(R((sE/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/linklockfile.pyt i_am_lockingBs cC@s,tjj|jr(tj|jndS(N(RRRRR(R((sE/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/linklockfile.pyt break_lockGsN( t__name__t __module__t__doc__R RR RR!R"(((sE/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/linklockfile.pyR s  &   ( t __future__RRRtRRRRRRR(((sE/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/linklockfile.pyts  .PK!g}Ha__sqlitelockfile.pycnu[ abc@`sddlmZmZddlZddlZyeWnek rOeZnXddlm Z m Z m Z m Z m Z de fdYZdS(i(tabsolute_importtdivisionNi(tLockBaset NotLockedt NotMyLockt LockTimeoutt AlreadyLockedtSQLiteLockFilecB`s\eZdZdZeddZddZdZdZ dZ dZ dZ RS( sDemonstrate SQL-based locking.c C`stj||||t|j|_t|j|_tjdkrddl}|j \}}t j |t j |~~|t_nddl }|jtj|_|jj}y|jdWn|jk rn0X|jjddl} | jt j tjdS(su >>> lock = SQLiteLockFile('somefile') >>> lock = SQLiteLockFile('somefile', threaded=False) iNsGcreate table locks( lock_file varchar(32), unique_name varchar(32))(Rt__init__tunicodet lock_filet unique_nameRttestdbtNonettempfiletmkstemptostclosetunlinktsqlite3tconnectt connectiontcursortexecutetOperationalErrortcommittatexittregister( tselftpathtthreadedttimeoutRt_fdR RtcR((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pyRs(       cC`s|dk r|n|j}tj}|dk rL|dkrL||7}n|dkrad}n|dkrvd}n |d}|jj}x;tr|js.|jd|j|j f|jj |jd|j f|j }t |dkr'|jd|j f|jj qfdSn8|jd|j f|j }t |dkrfdS|dk rtj|kr|dkrt d|jqtd |jntj|qWdS( Nig?i s;insert into locks (lock_file, unique_name) values (?, ?)s*select * from locks where unique_name = ?is(delete from locks where unique_name = ?s&Timeout waiting to acquire lock for %ss%s is already locked(R RttimeRRtTruet is_lockedRR R RtfetchalltlenRRRtsleep(RRtend_timetwaitRtrows((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pytacquire5sD                    cC`s|js"td|jn|jsPtd|j|jfn|jj}|j d|jf|jj dS(Ns%s is not lockeds#%s is locked, but not by me (by %s)s(delete from locks where unique_name = ?( R$RRt i_am_lockingRR t_who_is_lockingRRRR(RR((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pytreleasets    cC`s3|jj}|jd|jf|jdS(Ns2select unique_name from locks where lock_file = ?i(RRRR tfetchone(RR((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pyR-s  cC`s7|jj}|jd|jf|j}| S(Ns(select * from locks where lock_file = ?(RRRR R%(RRR*((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pyR$s    cC`s7|jj}|jd|j|jf|j S(Ns?select * from locks where lock_file = ? and unique_name = ?(RRRR R R%(RR((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pyR,s cC`s6|jj}|jd|jf|jjdS(Ns&delete from locks where lock_file = ?(RRRR R(RR((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pyt break_locks  N( t__name__t __module__t__doc__R R R#RR+R.R-R$R,R0(((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pyRs" ?   (t __future__RRR"RR t NameErrortstrtRRRRRR(((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pyts    (PK!+'\ \ linklockfile.pynu[from __future__ import absolute_import import time import os from . import (LockBase, LockFailed, NotLocked, NotMyLock, LockTimeout, AlreadyLocked) class LinkLockFile(LockBase): """Lock access to a file using atomic property of link(2). >>> lock = LinkLockFile('somefile') >>> lock = LinkLockFile('somefile', threaded=False) """ def acquire(self, timeout=None): try: open(self.unique_name, "wb").close() except IOError: raise LockFailed("failed to create %s" % self.unique_name) timeout = timeout if timeout is not None else self.timeout end_time = time.time() if timeout is not None and timeout > 0: end_time += timeout while True: # Try and create a hard link to it. try: os.link(self.unique_name, self.lock_file) except OSError: # Link creation failed. Maybe we've double-locked? nlinks = os.stat(self.unique_name).st_nlink if nlinks == 2: # The original link plus the one I created == 2. We're # good to go. return else: # Otherwise the lock creation failed. if timeout is not None and time.time() > end_time: os.unlink(self.unique_name) if timeout > 0: raise LockTimeout("Timeout waiting to acquire" " lock for %s" % self.path) else: raise AlreadyLocked("%s is already locked" % self.path) time.sleep(timeout is not None and timeout / 10 or 0.1) else: # Link creation succeeded. We're good to go. return def release(self): if not self.is_locked(): raise NotLocked("%s is not locked" % self.path) elif not os.path.exists(self.unique_name): raise NotMyLock("%s is locked, but not by me" % self.path) os.unlink(self.unique_name) os.unlink(self.lock_file) def is_locked(self): return os.path.exists(self.lock_file) def i_am_locking(self): return (self.is_locked() and os.path.exists(self.unique_name) and os.stat(self.unique_name).st_nlink == 2) def break_lock(self): if os.path.exists(self.lock_file): os.unlink(self.lock_file) PK!|pidlockfile.pyonu[ abc@@sdZddlmZddlZddlZddlZddlmZmZm Z m Z m Z m Z defdYZ dZd Zd ZdS( s8 Lockfile behaviour implemented via Unix PID files. i(tabsolute_importNi(tLockBaset AlreadyLockedt LockFailedt NotLockedt NotMyLockt LockTimeoutt PIDLockFilecB@sVeZdZeddZdZdZdZddZ dZ dZ RS( sA Lockfile implemented as a Unix PID file. The lock file is a normal file named by the attribute `path`. A lock's PID file contains a single line of text, containing the process ID (PID) of the process that acquired the lock. >>> lock = PIDLockFile('somefile') >>> lock = PIDLockFile('somefile') cC@s&tj||t||j|_dS(N(Rt__init__tFalsetpatht unique_name(tselfR tthreadedttimeout((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyR$scC@s t|jS(s- Get the PID from the lock file. (tread_pid_from_pidfileR (R ((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pytread_pid*scC@stjj|jS(sv Test if the lock is currently held. The lock is held if the PID file for this lock exists. (tosR texists(R ((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyt is_locked/scC@s"|jo!tj|jkS(s Test if the lock is held by the current process. Returns ``True`` if the current process ID matches the number stored in the PID file. (RRtgetpidR(R ((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyt i_am_locking7scC@s)|dk r|n|j}tj}|dk rL|dkrL||7}nxtr$yt|jWntk r}|jtjkrtj|kr|dk r|dkrt d|jqt d|jntj |dk r|dpdq!t d|jqOXdSqOWdS(s Acquire the lock. Creates the PID file for this lock, or raises an error if the lock could not be acquired. is&Timeout waiting to acquire lock for %ss%s is already lockedi g?sfailed to create %sN( tNoneRttimetTruetwrite_pid_to_pidfileR tOSErrorterrnotEEXISTRRtsleepR(R Rtend_timetexc((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pytacquire?s$   &cC@sU|js"td|jn|jsDtd|jnt|jdS(s Release the lock. Removes the PID file to release the lock, or raises an error if the current process does not hold the lock. s%s is not lockeds%s is locked, but not by meN(RRR RRtremove_existing_pidfile(R ((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pytrelease_s   cC@st|jdS(s Break an existing lock. Removes the PID file if it already exists, otherwise does nothing. N(R!R (R ((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyt break_locklsN( t__name__t __module__t__doc__R RRRRRR R"R#(((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyRs     cC@sqd}yt|d}Wntk r,nAX|jj}yt|}Wntk rbnX|j|S(s Read the PID recorded in the named PID file. Read and return the numeric PID recorded as text in the named PID file. If the PID file cannot be read, or if the content is not a valid PID, return ``None``. trN(RtopentIOErrortreadlinetstriptintt ValueErrortclose(t pidfile_pathtpidtpidfiletline((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyRvs    cC@sotjtjBtjB}d}tj|||}tj|d}tj}|jd||jdS(s Write the PID in the named PID file. Get the numeric process ID (“PID”) of the current process and write it to the named file as a line of text. itws%s N( RtO_CREATtO_EXCLtO_WRONLYR(tfdopenRtwriteR.(R/t open_flagst open_modet pidfile_fdR1R0((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyRs cC@sCytj|Wn+tk r>}|jtjkr8q?nXdS(s Remove the named PID file if it exists. Removing a PID file that doesn't already exist puts us in the desired state, so we ignore the condition if the file does not exist. N(RtremoveRRtENOENT(R/R((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyR!s (R&t __future__RRRRtRRRRRRRRRR!(((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyt s   .] " PK!Ǟ+P/P/ __init__.pycnu[ 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                 -:    PK!sqlitelockfile.pynu[from __future__ import absolute_import, division import time import os try: unicode except NameError: unicode = str from . import LockBase, NotLocked, NotMyLock, LockTimeout, AlreadyLocked class SQLiteLockFile(LockBase): "Demonstrate SQL-based locking." testdb = None def __init__(self, path, threaded=True, timeout=None): """ >>> lock = SQLiteLockFile('somefile') >>> lock = SQLiteLockFile('somefile', threaded=False) """ LockBase.__init__(self, path, threaded, timeout) self.lock_file = unicode(self.lock_file) self.unique_name = unicode(self.unique_name) if SQLiteLockFile.testdb is None: import tempfile _fd, testdb = tempfile.mkstemp() os.close(_fd) os.unlink(testdb) del _fd, tempfile SQLiteLockFile.testdb = testdb import sqlite3 self.connection = sqlite3.connect(SQLiteLockFile.testdb) c = self.connection.cursor() try: c.execute("create table locks" "(" " lock_file varchar(32)," " unique_name varchar(32)" ")") except sqlite3.OperationalError: pass else: self.connection.commit() import atexit atexit.register(os.unlink, SQLiteLockFile.testdb) def acquire(self, timeout=None): timeout = timeout if timeout is not None else self.timeout end_time = time.time() if timeout is not None and timeout > 0: end_time += timeout if timeout is None: wait = 0.1 elif timeout <= 0: wait = 0 else: wait = timeout / 10 cursor = self.connection.cursor() while True: if not self.is_locked(): # Not locked. Try to lock it. cursor.execute("insert into locks" " (lock_file, unique_name)" " values" " (?, ?)", (self.lock_file, self.unique_name)) self.connection.commit() # Check to see if we are the only lock holder. cursor.execute("select * from locks" " where unique_name = ?", (self.unique_name,)) rows = cursor.fetchall() if len(rows) > 1: # Nope. Someone else got there. Remove our lock. cursor.execute("delete from locks" " where unique_name = ?", (self.unique_name,)) self.connection.commit() else: # Yup. We're done, so go home. return else: # Check to see if we are the only lock holder. cursor.execute("select * from locks" " where unique_name = ?", (self.unique_name,)) rows = cursor.fetchall() if len(rows) == 1: # We're the locker, so go home. return # Maybe we should wait a bit longer. if timeout is not None and time.time() > end_time: if timeout > 0: # No more waiting. raise LockTimeout("Timeout waiting to acquire" " lock for %s" % self.path) else: # Someone else has the lock and we are impatient.. raise AlreadyLocked("%s is already locked" % self.path) # Well, okay. We'll give it a bit longer. time.sleep(wait) def release(self): if not self.is_locked(): raise NotLocked("%s is not locked" % self.path) if not self.i_am_locking(): raise NotMyLock("%s is locked, but not by me (by %s)" % (self.unique_name, self._who_is_locking())) cursor = self.connection.cursor() cursor.execute("delete from locks" " where unique_name = ?", (self.unique_name,)) self.connection.commit() def _who_is_locking(self): cursor = self.connection.cursor() cursor.execute("select unique_name from locks" " where lock_file = ?", (self.lock_file,)) return cursor.fetchone()[0] def is_locked(self): cursor = self.connection.cursor() cursor.execute("select * from locks" " where lock_file = ?", (self.lock_file,)) rows = cursor.fetchall() return not not rows def i_am_locking(self): cursor = self.connection.cursor() cursor.execute("select * from locks" " where lock_file = ?" " and unique_name = ?", (self.lock_file, self.unique_name)) return not not cursor.fetchall() def break_lock(self): cursor = self.connection.cursor() cursor.execute("delete from locks" " where lock_file = ?", (self.lock_file,)) self.connection.commit() PK!f ..0__pycache__/symlinklockfile.cpython-36.opt-1.pycnu[3 Pf8 @sLddlmZddlZddlZddlmZmZmZmZm Z GdddeZ dS))absolute_importN)LockBase NotLocked NotMyLock LockTimeout AlreadyLockedc@sDeZdZdZdddZdddZdd Zd d Zd d ZddZ dS)SymlinkLockFilez'Lock access to a file using symlink(2).TNcCs(tj||||tjj|jd|_dS)Nr)r__init__ospathsplit unique_name)selfr Zthreadedtimeoutr%/usr/lib/python3.6/symlinklockfile.pyr szSymlinkLockFile.__init__c Cs|dk r |n|j}tj}|dk r2|dkr2||7}xytj|j|jWnttk r|jrddS|dk rtj|kr|dkrtd|j nt d|j tj |dk r|dndYq4XdSq4WdS)Nrz&Timeout waiting to acquire lock for %sz%s is already locked g?) rtimer symlinkr lock_fileOSError i_am_lockingrr rZsleep)rrZend_timerrracquires$   zSymlinkLockFile.acquirecCs>|jstd|jn|js.td|jtj|jdS)Nz%s is not lockedz%s is locked, but not by me) is_lockedrr rrr unlinkr)rrrrrelease6s zSymlinkLockFile.releasecCstjj|jS)N)r r islinkr)rrrrr=szSymlinkLockFile.is_lockedcCs tjj|jotj|j|jkS)N)r r rrreadlinkr)rrrrr@szSymlinkLockFile.i_am_lockingcCstjj|jrtj|jdS)N)r r rrr)rrrr break_lockDszSymlinkLockFile.break_lock)TN)N) __name__ __module__ __qualname____doc__r rrrrrrrrrr s  #r ) Z __future__rr rrrrrrr rrrrs PK!dF,__pycache__/pidlockfile.cpython-36.opt-1.pycnu[3 Pf@stdZddlmZddlZddlZddlZddlmZmZm Z m Z m Z m Z GdddeZ dd Zd d Zd d ZdS)z8 Lockfile behaviour implemented via Unix PID files. )absolute_importN)LockBase AlreadyLocked LockFailed NotLocked NotMyLock LockTimeoutc@sLeZdZdZdddZddZdd Zd d Zdd d ZddZ ddZ dS) PIDLockFileaA Lockfile implemented as a Unix PID file. The lock file is a normal file named by the attribute `path`. A lock's PID file contains a single line of text, containing the process ID (PID) of the process that acquired the lock. >>> lock = PIDLockFile('somefile') >>> lock = PIDLockFile('somefile') FNcCstj||d||j|_dS)NF)r__init__pathZ unique_name)selfr Zthreadedtimeoutr!/usr/lib/python3.6/pidlockfile.pyr $szPIDLockFile.__init__cCs t|jS)z- Get the PID from the lock file. )read_pid_from_pidfiler )r rrrread_pid*szPIDLockFile.read_pidcCstjj|jS)zv Test if the lock is currently held. The lock is held if the PID file for this lock exists. )osr exists)r rrr is_locked/szPIDLockFile.is_lockedcCs|jotj|jkS)z Test if the lock is held by the current process. Returns ``True`` if the current process ID matches the number stored in the PID file. )rrgetpidr)r rrr i_am_locking7szPIDLockFile.i_am_lockingcCs|dk r |n|j}tj}|dk r2|dkr2||7}xyt|jWntk r}zv|jtjkrtj|kr|dk r|dkrtd|jntd|jtj |dk r|dpdnt d|jWYdd}~Xq4XdSq4WdS)z Acquire the lock. Creates the PID file for this lock, or raises an error if the lock could not be acquired. Nrz&Timeout waiting to acquire lock for %sz%s is already locked g?zfailed to create %s) rtimewrite_pid_to_pidfiler OSErrorerrnoZEEXISTr rZsleepr)r rZend_timeexcrrracquire?s$     zPIDLockFile.acquirecCs:|jstd|j|js,td|jt|jdS)z Release the lock. Removes the PID file to release the lock, or raises an error if the current process does not hold the lock. z%s is not lockedz%s is locked, but not by meN)rrr rrremove_existing_pidfile)r rrrrelease_s zPIDLockFile.releasecCst|jdS)z Break an existing lock. Removes the PID file if it already exists, otherwise does nothing. N)rr )r rrr break_locklszPIDLockFile.break_lock)FN)N) __name__ __module__ __qualname____doc__r rrrrr r!rrrrr s    r cCsbd}yt|d}Wntk r&Yn8X|jj}y t|}Wntk rTYnX|j|S)z Read the PID recorded in the named PID file. Read and return the numeric PID recorded as text in the named PID file. If the PID file cannot be read, or if the content is not a valid PID, return ``None``. Nr)openIOErrorreadlinestripint ValueErrorclose) pidfile_pathpidpidfilelinerrrrvs  rcCsRtjtjBtjB}d}tj|||}tj|d}tj}|jd||jdS)u Write the PID in the named PID file. Get the numeric process ID (“PID”) of the current process and write it to the named file as a line of text. iwz%s N) rO_CREATO_EXCLO_WRONLYr'fdopenrwriter-)r.Z open_flagsZ open_modeZ pidfile_fdr0r/rrrrs rcCsFytj|Wn2tk r@}z|jtjkr.nWYdd}~XnXdS)z Remove the named PID file if it exists. Removing a PID file that doesn't already exist puts us in the desired state, so we ignore the condition if the file does not exist. N)rremoverrENOENT)r.rrrrrs  r)r%Z __future__rrrrrrrrrr r rrrrrrr s  ]"PK!VV)__pycache__/sqlitelockfile.cpython-36.pycnu[3 Pf @srddlmZmZddlZddlZyeWnek r@eZYnXddlm Z m Z m Z m Z m Z Gddde ZdS))absolute_importdivisionN)LockBase NotLocked NotMyLock LockTimeout AlreadyLockedc@sPeZdZdZdZdddZdddZdd Zd d Zd d Z ddZ ddZ dS)SQLiteLockFilezDemonstrate SQL-based locking.NTc Cstj||||t|j|_t|j|_tjdkrdddl}|j\}}t j |t j |~~|t_ddl }|j tj|_|jj}y|jdWn|jk rYn$X|jjddl} | jt j tjdS)zu >>> lock = SQLiteLockFile('somefile') >>> lock = SQLiteLockFile('somefile', threaded=False) NrzGcreate table locks( lock_file varchar(32), unique_name varchar(32)))r__init__unicode lock_file unique_namer testdbtempfileZmkstemposcloseunlinksqlite3Zconnect connectioncursorexecuteZOperationalErrorcommitatexitregister) selfpathZthreadedtimeoutrZ_fdrrcrr$/usr/lib/python3.6/sqlitelockfile.pyr s(        zSQLiteLockFile.__init__cCsH|dk r |n|j}tj}|dk r2|dkr2||7}|dkr@d}n|dkrNd}n|d}|jj}x|js|jd|j|jf|jj|jd|jf|j }t |dkr|jd|jf|jjqdSn(|jd|jf|j }t |dkrdS|dk r6tj|kr6|dkr(t d|j nt d |j tj|qbWdS) Nrg? z;insert into locks (lock_file, unique_name) values (?, ?)z*select * from locks where unique_name = ?rz(delete from locks where unique_name = ?z&Timeout waiting to acquire lock for %sz%s is already locked)rtimerr is_lockedrr rrfetchalllenrrr Zsleep)rrZend_timewaitrrowsrrr acquire5sD          zSQLiteLockFile.acquirecCs\|jstd|j|js4td|j|jf|jj}|j d|jf|jj dS)Nz%s is not lockedz#%s is locked, but not by me (by %s)z(delete from locks where unique_name = ?) r#rr i_am_lockingrr_who_is_lockingrrrr)rrrrr releasets  zSQLiteLockFile.releasecCs&|jj}|jd|jf|jdS)Nz2select unique_name from locks where lock_file = ?r)rrrr Zfetchone)rrrrr r*s  zSQLiteLockFile._who_is_lockingcCs*|jj}|jd|jf|j}| S)Nz(select * from locks where lock_file = ?)rrrr r$)rrr'rrr r#s   zSQLiteLockFile.is_lockedcCs*|jj}|jd|j|jf|j S)Nz?select * from locks where lock_file = ? and unique_name = ?)rrrr rr$)rrrrr r)s zSQLiteLockFile.i_am_lockingcCs(|jj}|jd|jf|jjdS)Nz&delete from locks where lock_file = ?)rrrr r)rrrrr break_locks  zSQLiteLockFile.break_lock)TN)N) __name__ __module__ __qualname____doc__rr r(r+r*r#r)r,rrrr r s " ? r )Z __future__rrr"rr NameErrorstrrrrrr r rrrr s PK!f ..*__pycache__/symlinklockfile.cpython-36.pycnu[3 Pf8 @sLddlmZddlZddlZddlmZmZmZmZm Z GdddeZ dS))absolute_importN)LockBase NotLocked NotMyLock LockTimeout AlreadyLockedc@sDeZdZdZdddZdddZdd Zd d Zd d ZddZ dS)SymlinkLockFilez'Lock access to a file using symlink(2).TNcCs(tj||||tjj|jd|_dS)Nr)r__init__ospathsplit unique_name)selfr Zthreadedtimeoutr%/usr/lib/python3.6/symlinklockfile.pyr szSymlinkLockFile.__init__c Cs|dk r |n|j}tj}|dk r2|dkr2||7}xytj|j|jWnttk r|jrddS|dk rtj|kr|dkrtd|j nt d|j tj |dk r|dndYq4XdSq4WdS)Nrz&Timeout waiting to acquire lock for %sz%s is already locked g?) rtimer symlinkr lock_fileOSError i_am_lockingrr rZsleep)rrZend_timerrracquires$   zSymlinkLockFile.acquirecCs>|jstd|jn|js.td|jtj|jdS)Nz%s is not lockedz%s is locked, but not by me) is_lockedrr rrr unlinkr)rrrrrelease6s zSymlinkLockFile.releasecCstjj|jS)N)r r islinkr)rrrrr=szSymlinkLockFile.is_lockedcCs tjj|jotj|j|jkS)N)r r rrreadlinkr)rrrrr@szSymlinkLockFile.i_am_lockingcCstjj|jrtj|jdS)N)r r rrr)rrrr break_lockDszSymlinkLockFile.break_lock)TN)N) __name__ __module__ __qualname____doc__r rrrrrrrrrr s  #r ) Z __future__rr rrrrrrr rrrrs PK!dF&__pycache__/pidlockfile.cpython-36.pycnu[3 Pf@stdZddlmZddlZddlZddlZddlmZmZm Z m Z m Z m Z GdddeZ dd Zd d Zd d ZdS)z8 Lockfile behaviour implemented via Unix PID files. )absolute_importN)LockBase AlreadyLocked LockFailed NotLocked NotMyLock LockTimeoutc@sLeZdZdZdddZddZdd Zd d Zdd d ZddZ ddZ dS) PIDLockFileaA Lockfile implemented as a Unix PID file. The lock file is a normal file named by the attribute `path`. A lock's PID file contains a single line of text, containing the process ID (PID) of the process that acquired the lock. >>> lock = PIDLockFile('somefile') >>> lock = PIDLockFile('somefile') FNcCstj||d||j|_dS)NF)r__init__pathZ unique_name)selfr Zthreadedtimeoutr!/usr/lib/python3.6/pidlockfile.pyr $szPIDLockFile.__init__cCs t|jS)z- Get the PID from the lock file. )read_pid_from_pidfiler )r rrrread_pid*szPIDLockFile.read_pidcCstjj|jS)zv Test if the lock is currently held. The lock is held if the PID file for this lock exists. )osr exists)r rrr is_locked/szPIDLockFile.is_lockedcCs|jotj|jkS)z Test if the lock is held by the current process. Returns ``True`` if the current process ID matches the number stored in the PID file. )rrgetpidr)r rrr i_am_locking7szPIDLockFile.i_am_lockingcCs|dk r |n|j}tj}|dk r2|dkr2||7}xyt|jWntk r}zv|jtjkrtj|kr|dk r|dkrtd|jntd|jtj |dk r|dpdnt d|jWYdd}~Xq4XdSq4WdS)z Acquire the lock. Creates the PID file for this lock, or raises an error if the lock could not be acquired. Nrz&Timeout waiting to acquire lock for %sz%s is already locked g?zfailed to create %s) rtimewrite_pid_to_pidfiler OSErrorerrnoZEEXISTr rZsleepr)r rZend_timeexcrrracquire?s$     zPIDLockFile.acquirecCs:|jstd|j|js,td|jt|jdS)z Release the lock. Removes the PID file to release the lock, or raises an error if the current process does not hold the lock. z%s is not lockedz%s is locked, but not by meN)rrr rrremove_existing_pidfile)r rrrrelease_s zPIDLockFile.releasecCst|jdS)z Break an existing lock. Removes the PID file if it already exists, otherwise does nothing. N)rr )r rrr break_locklszPIDLockFile.break_lock)FN)N) __name__ __module__ __qualname____doc__r rrrrr r!rrrrr s    r cCsbd}yt|d}Wntk r&Yn8X|jj}y t|}Wntk rTYnX|j|S)z Read the PID recorded in the named PID file. Read and return the numeric PID recorded as text in the named PID file. If the PID file cannot be read, or if the content is not a valid PID, return ``None``. Nr)openIOErrorreadlinestripint ValueErrorclose) pidfile_pathpidpidfilelinerrrrvs  rcCsRtjtjBtjB}d}tj|||}tj|d}tj}|jd||jdS)u Write the PID in the named PID file. Get the numeric process ID (“PID”) of the current process and write it to the named file as a line of text. iwz%s N) rO_CREATO_EXCLO_WRONLYr'fdopenrwriter-)r.Z open_flagsZ open_modeZ pidfile_fdr0r/rrrrs rcCsFytj|Wn2tk r@}z|jtjkr.nWYdd}~XnXdS)z Remove the named PID file if it exists. Removing a PID file that doesn't already exist puts us in the desired state, so we ignore the condition if the file does not exist. N)rremoverrENOENT)r.rrrrrs  r)r%Z __future__rrrrrrrrrr r rrrrrrr s  ]"PK!>> lock = MkdirLockFile('somefile') >>> lock = MkdirLockFile('somefile', threaded=False) z%s.%s%sN) r__init__ospathjoin lock_fileZhostnameZtnamepid unique_name)selfrZthreadedtimeoutr#/usr/lib/python3.6/mkdirlockfile.pyr s  zMkdirLockFile.__init__c Cs|dk r |n|j}tj}|dk r2|dkr2||7}|dkr@d}ntd|d}xytj|jWntk rtjd}|j t j krtj j |j rdS|dk rtj|kr|dkrtd|j ntd|j tj|ntd|jYqPXt|j djdSqPWdS) Nrg? rz&Timeout waiting to acquire lock for %sz%s is already lockedzfailed to create %swb)rtimemaxr mkdirrOSErrorsysexc_infoerrnoZEEXISTrexistsrr r Zsleepropenclose)rrZend_timewaiterrrrracquires2     zMkdirLockFile.acquirecCsP|jstd|jntjj|js4td|jtj|jtj|j dS)Nz%s is not lockedz%s is locked, but not by me) is_lockedrrr r rrunlinkrmdirr)rrrrreleaseAs  zMkdirLockFile.releasecCstjj|jS)N)r rr r)rrrrr&IszMkdirLockFile.is_lockedcCs|jotjj|jS)N)r&r rr r)rrrr i_am_lockingLszMkdirLockFile.i_am_lockingcCsJtjj|jrFx*tj|jD]}tjtjj|j|qWtj|jdS)N)r rr rlistdirr'rr()rnamerrr break_lockPszMkdirLockFile.break_lock)TN)N) __name__ __module__ __qualname____doc__r r%r)r&r*r-rrrrr s &r )Z __future__rrrr rrrrrrr r r rrrrs  PK!ؚ-__pycache__/linklockfile.cpython-36.opt-1.pycnu[3 Pf\ @sPddlmZddlZddlZddlmZmZmZmZm Z m Z GdddeZ dS))absolute_importN)LockBase LockFailed NotLocked NotMyLock LockTimeout AlreadyLockedc@s:eZdZdZd ddZddZddZd d Zd d ZdS) LinkLockFilezLock access to a file using atomic property of link(2). >>> lock = LinkLockFile('somefile') >>> lock = LinkLockFile('somefile', threaded=False) NcCs"yt|jdjWn"tk r6td|jYnX|dk rD|n|j}tj}|dk rj|dkrj||7}xytj|j|j Wnt k rtj |jj }|dkrdS|dk rtj|krtj |j|dkrtd|jntd|jtj|dk r |dp dYqlXdSqlWdS) Nwbzfailed to create %srz&Timeout waiting to acquire lock for %sz%s is already locked g?)open unique_namecloseIOErrorrtimeouttimeoslink lock_fileOSErrorstatst_nlinkunlinkrpathr Zsleep)selfrZend_timeZnlinksr"/usr/lib/python3.6/linklockfile.pyacquires0   $zLinkLockFile.acquirecCsP|jstd|jntjj|js4td|jtj|jtj|jdS)Nz%s is not lockedz%s is locked, but not by me) is_lockedrrrexistsrrrr)rrrrrelease7s  zLinkLockFile.releasecCstjj|jS)N)rrr!r)rrrrr ?szLinkLockFile.is_lockedcCs(|jo&tjj|jo&tj|jjdkS)Nr )r rrr!rrr)rrrr i_am_lockingBszLinkLockFile.i_am_lockingcCstjj|jrtj|jdS)N)rrr!rr)rrrr break_lockGszLinkLockFile.break_lock)N) __name__ __module__ __qualname____doc__rr"r r#r$rrrrr s  &r ) Z __future__rrrrrrrrr r rrrrs  PK!>> lock = MkdirLockFile('somefile') >>> lock = MkdirLockFile('somefile', threaded=False) z%s.%s%sN) r__init__ospathjoin lock_fileZhostnameZtnamepid unique_name)selfrZthreadedtimeoutr#/usr/lib/python3.6/mkdirlockfile.pyr s  zMkdirLockFile.__init__c Cs|dk r |n|j}tj}|dk r2|dkr2||7}|dkr@d}ntd|d}xytj|jWntk rtjd}|j t j krtj j |j rdS|dk rtj|kr|dkrtd|j ntd|j tj|ntd|jYqPXt|j djdSqPWdS) Nrg? rz&Timeout waiting to acquire lock for %sz%s is already lockedzfailed to create %swb)rtimemaxr mkdirrOSErrorsysexc_infoerrnoZEEXISTrexistsrr r Zsleepropenclose)rrZend_timewaiterrrrracquires2     zMkdirLockFile.acquirecCsP|jstd|jntjj|js4td|jtj|jtj|j dS)Nz%s is not lockedz%s is locked, but not by me) is_lockedrrr r rrunlinkrmdirr)rrrrreleaseAs  zMkdirLockFile.releasecCstjj|jS)N)r rr r)rrrrr&IszMkdirLockFile.is_lockedcCs|jotjj|jS)N)r&r rr r)rrrr i_am_lockingLszMkdirLockFile.i_am_lockingcCsJtjj|jrFx*tj|jD]}tjtjj|j|qWtj|jdS)N)r rr rlistdirr'rr()rnamerrr break_lockPszMkdirLockFile.break_lock)TN)N) __name__ __module__ __qualname____doc__r r%r)r&r*r-rrrrr s &r )Z __future__rrrr rrrrrrr r r rrrrs  PK!VV/__pycache__/sqlitelockfile.cpython-36.opt-1.pycnu[3 Pf @srddlmZmZddlZddlZyeWnek r@eZYnXddlm Z m Z m Z m Z m Z Gddde ZdS))absolute_importdivisionN)LockBase NotLocked NotMyLock LockTimeout AlreadyLockedc@sPeZdZdZdZdddZdddZdd Zd d Zd d Z ddZ ddZ dS)SQLiteLockFilezDemonstrate SQL-based locking.NTc Cstj||||t|j|_t|j|_tjdkrdddl}|j\}}t j |t j |~~|t_ddl }|j tj|_|jj}y|jdWn|jk rYn$X|jjddl} | jt j tjdS)zu >>> lock = SQLiteLockFile('somefile') >>> lock = SQLiteLockFile('somefile', threaded=False) NrzGcreate table locks( lock_file varchar(32), unique_name varchar(32)))r__init__unicode lock_file unique_namer testdbtempfileZmkstemposcloseunlinksqlite3Zconnect connectioncursorexecuteZOperationalErrorcommitatexitregister) selfpathZthreadedtimeoutrZ_fdrrcrr$/usr/lib/python3.6/sqlitelockfile.pyr s(        zSQLiteLockFile.__init__cCsH|dk r |n|j}tj}|dk r2|dkr2||7}|dkr@d}n|dkrNd}n|d}|jj}x|js|jd|j|jf|jj|jd|jf|j }t |dkr|jd|jf|jjqdSn(|jd|jf|j }t |dkrdS|dk r6tj|kr6|dkr(t d|j nt d |j tj|qbWdS) Nrg? z;insert into locks (lock_file, unique_name) values (?, ?)z*select * from locks where unique_name = ?rz(delete from locks where unique_name = ?z&Timeout waiting to acquire lock for %sz%s is already locked)rtimerr is_lockedrr rrfetchalllenrrr Zsleep)rrZend_timewaitrrowsrrr acquire5sD          zSQLiteLockFile.acquirecCs\|jstd|j|js4td|j|jf|jj}|j d|jf|jj dS)Nz%s is not lockedz#%s is locked, but not by me (by %s)z(delete from locks where unique_name = ?) r#rr i_am_lockingrr_who_is_lockingrrrr)rrrrr releasets  zSQLiteLockFile.releasecCs&|jj}|jd|jf|jdS)Nz2select unique_name from locks where lock_file = ?r)rrrr Zfetchone)rrrrr r*s  zSQLiteLockFile._who_is_lockingcCs*|jj}|jd|jf|j}| S)Nz(select * from locks where lock_file = ?)rrrr r$)rrr'rrr r#s   zSQLiteLockFile.is_lockedcCs*|jj}|jd|j|jf|j S)Nz?select * from locks where lock_file = ? and unique_name = ?)rrrr rr$)rrrrr r)s zSQLiteLockFile.i_am_lockingcCs(|jj}|jd|jf|jjdS)Nz&delete from locks where lock_file = ?)rrrr r)rrrrr break_locks  zSQLiteLockFile.break_lock)TN)N) __name__ __module__ __qualname____doc__rr r(r+r*r#r)r,rrrr r s " ? r )Z __future__rrr"rr NameErrorstrrrrrr r rrrr s PK!ؚ'__pycache__/linklockfile.cpython-36.pycnu[3 Pf\ @sPddlmZddlZddlZddlmZmZmZmZm Z m Z GdddeZ dS))absolute_importN)LockBase LockFailed NotLocked NotMyLock LockTimeout AlreadyLockedc@s:eZdZdZd ddZddZddZd d Zd d ZdS) LinkLockFilezLock access to a file using atomic property of link(2). >>> lock = LinkLockFile('somefile') >>> lock = LinkLockFile('somefile', threaded=False) NcCs"yt|jdjWn"tk r6td|jYnX|dk rD|n|j}tj}|dk rj|dkrj||7}xytj|j|j Wnt k rtj |jj }|dkrdS|dk rtj|krtj |j|dkrtd|jntd|jtj|dk r |dp dYqlXdSqlWdS) Nwbzfailed to create %srz&Timeout waiting to acquire lock for %sz%s is already locked g?)open unique_namecloseIOErrorrtimeouttimeoslink lock_fileOSErrorstatst_nlinkunlinkrpathr Zsleep)selfrZend_timeZnlinksr"/usr/lib/python3.6/linklockfile.pyacquires0   $zLinkLockFile.acquirecCsP|jstd|jntjj|js4td|jtj|jtj|jdS)Nz%s is not lockedz%s is locked, but not by me) is_lockedrrrexistsrrrr)rrrrrelease7s  zLinkLockFile.releasecCstjj|jS)N)rrr!r)rrrrr ?szLinkLockFile.is_lockedcCs(|jo&tjj|jo&tj|jjdkS)Nr )r rrr!rrr)rrrr i_am_lockingBszLinkLockFile.i_am_lockingcCstjj|jrtj|jdS)N)rrr!rr)rrrr break_lockGszLinkLockFile.break_lock)N) __name__ __module__ __qualname____doc__rr"r r#r$rrrrr s  &r ) Z __future__rrrrrrrrr r rrrrs  PK!-cf&f&#__pycache__/__init__.cpython-36.pycnu[3 Pf$ @sdZddlmZddlZddlZddlZddlZddlZeedsJej e_ eej dsbej j ej _ dddd d d d d dddddg ZGdddeZGdddeZGdddeZGdd d eZGdd d eZGdd d eZGdd d eZGdd d eZGdddeZGdddeZddZd dZd!dZd"dZd(d#dZeed$rjd%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 LockError LockTimeout AlreadyLocked LockFailed UnlockError NotLocked NotMyLock LinkFileLock MkdirFileLockSQLiteFileLockLockBaselockedc@seZdZdZdS)rzw Base class for other exceptions. >>> try: ... raise Error ... except Exception: ... pass N)__name__ __module__ __qualname____doc__rr/usr/lib/python3.6/__init__.pyrJsc@seZdZdZdS)rz Base class for error arising from attempts to acquire the lock. >>> try: ... raise LockError ... except Error: ... pass N)rrrrrrrrrVsc@seZdZdZdS)rzRaised when lock creation fails within a user-defined period of time. >>> try: ... raise LockTimeout ... except LockError: ... pass N)rrrrrrrrrbsc@seZdZdZdS)rzSome other thread/process is locking the file. >>> try: ... raise AlreadyLocked ... except LockError: ... pass N)rrrrrrrrrmsc@seZdZdZdS)r zLock file creation failed for some other reason. >>> try: ... raise LockFailed ... except LockError: ... pass N)rrrrrrrrr xsc@seZdZdZdS)r z Base class for errors arising from attempts to release the lock. >>> try: ... raise UnlockError ... except Error: ... pass N)rrrrrrrrr sc@seZdZdZdS)r zRaised when an attempt is made to unlock an unlocked file. >>> try: ... raise NotLocked ... except UnlockError: ... pass N)rrrrrrrrr sc@seZdZdZdS)r zRaised when an attempt is made to unlock a file someone else locked. >>> try: ... raise NotMyLock ... except UnlockError: ... pass N)rrrrrrrrr sc@s>eZdZddZdddZddZdd Zd d Zd d ZdS) _SharedBasecCs ||_dS)N)path)selfrrrr__init__sz_SharedBase.__init__NcCs tddS)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.acquirecCs tddS)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__sz_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__)N) rrrrrrr r!r#rrrrrs  rcsBeZdZdZdfdd ZddZdd Zd d Zd d ZZ S)rz.Base class for platform-specific lock classes.TNcstt|j|tjj|d|_tj|_ tj |_ |rbt j }t|dt|}d|d@|_nd|_tjj|j}tjj|d|j |j|j t|jf|_||_dS)zi >>> lock = LockBase('somefile') >>> lock = LockBase('somefile', threaded=False) z.lockidentz-%xlz %s%s.%s%sN)superrrosrabspathZ lock_filesocketZ gethostnameZhostnamegetpidpid threadingrgetattrhashZtnamedirnamejoin unique_namer)rrthreadedrtr$r/)r"rrrs    zLockBase.__init__cCs tddS)z9 Tell whether or not the file is locked. zimplement in subclassN)r)rrrr is_lockedszLockBase.is_lockedcCs tddS)zA Return True if this object is locking the file. zimplement in subclassN)r)rrrr i_am_lockingszLockBase.i_am_lockingcCs tddS)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"rr1r)rrrrr#s zLockBase.__repr__)TN) rrrrrr4r5r6r# __classcell__rr)r"rrs !cOsRtjd|tddt|dts.|dd}t|dkrH| rHd|d<|||S)Nz1Import from %s module instead of lockfile package) stacklevelrTr2)warningswarnDeprecationWarning isinstancestrlen)clsmodargskwdsrrr _fl_helper s   rEcOs ddlm}t|jdf||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%rFrE LinkLockFile)rCrDrFrrrr s  cOs ddlm}t|jdf||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%rHrE MkdirLockFile)rCrDrHrrrr%s  cOs ddlm}t|jdf||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%rJrEZSQLiteLockFile)rCrDrJrrrr0s  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(...): ... cstjfdd}|S)Nc s.td}|jz ||S|jXdS)N)r)FileLockrr)rCkwargslock)funcrrrrwrapperHs   z&locked..decor..wrapper) functoolswraps)rNrO)rr)rNrdecorGszlocked..decorr)rrrRr)rrrr;s  linkr:)rF)rH)N))rZ __future__rrPr'r)r,r;hasattrZ currentThreadrZThreadZgetNamer__all__ Exceptionrrrrr r r r objectrrrEr rrrr%rFZ_llfrGZLockFilerHZ_mlfrIrKrrrr4sF            -:      PK!-cf&f&)__pycache__/__init__.cpython-36.opt-1.pycnu[3 Pf$ @sdZddlmZddlZddlZddlZddlZddlZeedsJej e_ eej dsbej j ej _ dddd d d d d dddddg ZGdddeZGdddeZGdddeZGdd d eZGdd d eZGdd d eZGdd d eZGdd d eZGdddeZGdddeZddZd dZd!dZd"dZd(d#dZeed$rjd%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 LockError LockTimeout AlreadyLocked LockFailed UnlockError NotLocked NotMyLock LinkFileLock MkdirFileLockSQLiteFileLockLockBaselockedc@seZdZdZdS)rzw Base class for other exceptions. >>> try: ... raise Error ... except Exception: ... pass N)__name__ __module__ __qualname____doc__rr/usr/lib/python3.6/__init__.pyrJsc@seZdZdZdS)rz Base class for error arising from attempts to acquire the lock. >>> try: ... raise LockError ... except Error: ... pass N)rrrrrrrrrVsc@seZdZdZdS)rzRaised when lock creation fails within a user-defined period of time. >>> try: ... raise LockTimeout ... except LockError: ... pass N)rrrrrrrrrbsc@seZdZdZdS)rzSome other thread/process is locking the file. >>> try: ... raise AlreadyLocked ... except LockError: ... pass N)rrrrrrrrrmsc@seZdZdZdS)r zLock file creation failed for some other reason. >>> try: ... raise LockFailed ... except LockError: ... pass N)rrrrrrrrr xsc@seZdZdZdS)r z Base class for errors arising from attempts to release the lock. >>> try: ... raise UnlockError ... except Error: ... pass N)rrrrrrrrr sc@seZdZdZdS)r zRaised when an attempt is made to unlock an unlocked file. >>> try: ... raise NotLocked ... except UnlockError: ... pass N)rrrrrrrrr sc@seZdZdZdS)r zRaised when an attempt is made to unlock a file someone else locked. >>> try: ... raise NotMyLock ... except UnlockError: ... pass N)rrrrrrrrr sc@s>eZdZddZdddZddZdd Zd d Zd d ZdS) _SharedBasecCs ||_dS)N)path)selfrrrr__init__sz_SharedBase.__init__NcCs tddS)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.acquirecCs tddS)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__sz_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__)N) rrrrrrr r!r#rrrrrs  rcsBeZdZdZdfdd ZddZdd Zd d Zd d ZZ S)rz.Base class for platform-specific lock classes.TNcstt|j|tjj|d|_tj|_ tj |_ |rbt j }t|dt|}d|d@|_nd|_tjj|j}tjj|d|j |j|j t|jf|_||_dS)zi >>> lock = LockBase('somefile') >>> lock = LockBase('somefile', threaded=False) z.lockidentz-%xlz %s%s.%s%sN)superrrosrabspathZ lock_filesocketZ gethostnameZhostnamegetpidpid threadingrgetattrhashZtnamedirnamejoin unique_namer)rrthreadedrtr$r/)r"rrrs    zLockBase.__init__cCs tddS)z9 Tell whether or not the file is locked. zimplement in subclassN)r)rrrr is_lockedszLockBase.is_lockedcCs tddS)zA Return True if this object is locking the file. zimplement in subclassN)r)rrrr i_am_lockingszLockBase.i_am_lockingcCs tddS)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"rr1r)rrrrr#s zLockBase.__repr__)TN) rrrrrr4r5r6r# __classcell__rr)r"rrs !cOsRtjd|tddt|dts.|dd}t|dkrH| rHd|d<|||S)Nz1Import from %s module instead of lockfile package) stacklevelrTr2)warningswarnDeprecationWarning isinstancestrlen)clsmodargskwdsrrr _fl_helper s   rEcOs ddlm}t|jdf||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%rFrE LinkLockFile)rCrDrFrrrr s  cOs ddlm}t|jdf||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%rHrE MkdirLockFile)rCrDrHrrrr%s  cOs ddlm}t|jdf||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%rJrEZSQLiteLockFile)rCrDrJrrrr0s  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(...): ... cstjfdd}|S)Nc s.td}|jz ||S|jXdS)N)r)FileLockrr)rCkwargslock)funcrrrrwrapperHs   z&locked..decor..wrapper) functoolswraps)rNrO)rr)rNrdecorGszlocked..decorr)rrrRr)rrrr;s  linkr:)rF)rH)N))rZ __future__rrPr'r)r,r;hasattrZ currentThreadrZThreadZgetNamer__all__ Exceptionrrrrr r r r objectrrrEr rrrr%rFZ_llfrGZLockFilerHZ_mlfrIrKrrrr4sF            -:      PK!9 README.mdnu[# lockfile A very polite lock file utility, which endeavors to not litter, and to wait patiently for others. ## Usage ```javascript var lockFile = require('lockfile') // opts is optional, and defaults to {} lockFile.lock('some-file.lock', opts, function (er) { // if the er happens, then it failed to acquire a lock. // if there was not an error, then the file was created, // and won't be deleted until we unlock it. // do my stuff, free of interruptions // then, some time later, do: lockFile.unlock('some-file.lock', function (er) { // er means that an error happened, and is probably bad. }) }) ``` ## Methods Sync methods return the value/throw the error, others don't. Standard node fs stuff. All known locks are removed when the process exits. Of course, it's possible for certain types of failures to cause this to fail, but a best effort is made to not be a litterbug. ### lockFile.lock(path, [opts], cb) Acquire a file lock on the specified path ### lockFile.lockSync(path, [opts]) Acquire a file lock on the specified path ### lockFile.unlock(path, cb) Close and unlink the lockfile. ### lockFile.unlockSync(path) Close and unlink the lockfile. ### lockFile.check(path, [opts], cb) Check if the lockfile is locked and not stale. Callback is called with `cb(error, isLocked)`. ### lockFile.checkSync(path, [opts]) Check if the lockfile is locked and not stale. Returns boolean. ## Options ### opts.wait A number of milliseconds to wait for locks to expire before giving up. Only used by lockFile.lock. Poll for `opts.wait` ms. If the lock is not cleared by the time the wait expires, then it returns with the original error. ### opts.pollPeriod When using `opts.wait`, this is the period in ms in which it polls to check if the lock has expired. Defaults to `100`. ### opts.stale A number of milliseconds before locks are considered to have expired. ### opts.retries Used by lock and lockSync. Retry `n` number of times before giving up. ### opts.retryWait Used by lock. Wait `n` milliseconds before retrying. PK!Ogen-changelog.shnu[#!/bin/bash ( echo '# Changes' echo '' git log --first-parent --pretty=format:'%s' \ | grep -v '^update changelog' \ | perl -p -e 's/^((v?[0-9]+\.?)+)$/\n## \1\n/g' \ | perl -p -e 's/^([^#\s].*)$/* \1/g' )> CHANGELOG.md PK!gD lockfile.jsnu[var fs = require('fs') var wx = 'wx' if (process.version.match(/^v0\.[0-6]/)) { var c = require('constants') wx = c.O_TRUNC | c.O_CREAT | c.O_WRONLY | c.O_EXCL } var os = require('os') exports.filetime = 'ctime' if (os.platform() == "win32") { exports.filetime = 'mtime' } var debug var util = require('util') if (util.debuglog) debug = util.debuglog('LOCKFILE') else if (/\blockfile\b/i.test(process.env.NODE_DEBUG)) debug = function() { var msg = util.format.apply(util, arguments) console.error('LOCKFILE %d %s', process.pid, msg) } else debug = function() {} var locks = {} function hasOwnProperty (obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop) } var onExit = require('signal-exit') onExit(function () { debug('exit listener') // cleanup Object.keys(locks).forEach(exports.unlockSync) }) // XXX https://github.com/joyent/node/issues/3555 // Remove when node 0.8 is deprecated. if (/^v0\.[0-8]\./.test(process.version)) { debug('uncaughtException, version = %s', process.version) process.on('uncaughtException', function H (er) { debug('uncaughtException') var l = process.listeners('uncaughtException').filter(function (h) { return h !== H }) if (!l.length) { // cleanup try { Object.keys(locks).forEach(exports.unlockSync) } catch (e) {} process.removeListener('uncaughtException', H) throw er } }) } exports.unlock = function (path, cb) { debug('unlock', path) // best-effort. unlocking an already-unlocked lock is a noop delete locks[path] fs.unlink(path, function (unlinkEr) { cb && cb() }) } exports.unlockSync = function (path) { debug('unlockSync', path) // best-effort. unlocking an already-unlocked lock is a noop try { fs.unlinkSync(path) } catch (er) {} delete locks[path] } // if the file can be opened in readonly mode, then it's there. // if the error is something other than ENOENT, then it's not. exports.check = function (path, opts, cb) { if (typeof opts === 'function') cb = opts, opts = {} debug('check', path, opts) fs.open(path, 'r', function (er, fd) { if (er) { if (er.code !== 'ENOENT') return cb(er) return cb(null, false) } if (!opts.stale) { return fs.close(fd, function (er) { return cb(er, true) }) } fs.fstat(fd, function (er, st) { if (er) return fs.close(fd, function (er2) { return cb(er) }) fs.close(fd, function (er) { var age = Date.now() - st[exports.filetime].getTime() return cb(er, age <= opts.stale) }) }) }) } exports.checkSync = function (path, opts) { opts = opts || {} debug('checkSync', path, opts) if (opts.wait) { throw new Error('opts.wait not supported sync for obvious reasons') } try { var fd = fs.openSync(path, 'r') } catch (er) { if (er.code !== 'ENOENT') throw er return false } if (!opts.stale) { try { fs.closeSync(fd) } catch (er) {} return true } // file exists. however, might be stale if (opts.stale) { try { var st = fs.fstatSync(fd) } finally { fs.closeSync(fd) } var age = Date.now() - st[exports.filetime].getTime() return (age <= opts.stale) } } var req = 1 exports.lock = function (path, opts, cb) { if (typeof opts === 'function') cb = opts, opts = {} opts.req = opts.req || req++ debug('lock', path, opts) opts.start = opts.start || Date.now() if (typeof opts.retries === 'number' && opts.retries > 0) { debug('has retries', opts.retries) var retries = opts.retries opts.retries = 0 cb = (function (orig) { return function cb (er, fd) { debug('retry-mutated callback') retries -= 1 if (!er || retries < 0) return orig(er, fd) debug('lock retry', path, opts) if (opts.retryWait) setTimeout(retry, opts.retryWait) else retry() function retry () { opts.start = Date.now() debug('retrying', opts.start) exports.lock(path, opts, cb) } }})(cb) } // try to engage the lock. // if this succeeds, then we're in business. fs.open(path, wx, function (er, fd) { if (!er) { debug('locked', path, fd) locks[path] = fd return fs.close(fd, function () { return cb() }) } debug('failed to acquire lock', er) // something other than "currently locked" // maybe eperm or something. if (er.code !== 'EEXIST') { debug('not EEXIST error', er) return cb(er) } // someone's got this one. see if it's valid. if (!opts.stale) return notStale(er, path, opts, cb) return maybeStale(er, path, opts, false, cb) }) debug('lock return') } // Staleness checking algorithm // 1. acquire $lock, fail // 2. stat $lock, find that it is stale // 3. acquire $lock.STALE // 4. stat $lock, assert that it is still stale // 5. unlink $lock // 6. link $lock.STALE $lock // 7. unlink $lock.STALE // On any failure, clean up whatever we've done, and raise the error. function maybeStale (originalEr, path, opts, hasStaleLock, cb) { fs.stat(path, function (statEr, st) { if (statEr) { if (statEr.code === 'ENOENT') { // expired already! opts.stale = false debug('lock stale enoent retry', path, opts) exports.lock(path, opts, cb) return } return cb(statEr) } var age = Date.now() - st[exports.filetime].getTime() if (age <= opts.stale) return notStale(originalEr, path, opts, cb) debug('lock stale', path, opts) if (hasStaleLock) { exports.unlock(path, function (er) { if (er) return cb(er) debug('lock stale retry', path, opts) fs.link(path + '.STALE', path, function (er) { fs.unlink(path + '.STALE', function () { // best effort. if the unlink fails, oh well. cb(er) }) }) }) } else { debug('acquire .STALE file lock', opts) exports.lock(path + '.STALE', opts, function (er) { if (er) return cb(er) maybeStale(originalEr, path, opts, true, cb) }) } }) } function notStale (er, path, opts, cb) { debug('notStale', path, opts) // if we can't wait, then just call it a failure if (typeof opts.wait !== 'number' || opts.wait <= 0) { debug('notStale, wait is not a number') return cb(er) } // poll for some ms for the lock to clear var now = Date.now() var start = opts.start || now var end = start + opts.wait if (end <= now) return cb(er) debug('now=%d, wait until %d (delta=%d)', start, end, end-start) var wait = Math.min(end - start, opts.pollPeriod || 100) var timer = setTimeout(poll, wait) function poll () { debug('notStale, polling', path, opts) exports.lock(path, opts, cb) } } exports.lockSync = function (path, opts) { opts = opts || {} opts.req = opts.req || req++ debug('lockSync', path, opts) if (opts.wait || opts.retryWait) { throw new Error('opts.wait not supported sync for obvious reasons') } try { var fd = fs.openSync(path, wx) locks[path] = fd try { fs.closeSync(fd) } catch (er) {} debug('locked sync!', path, fd) return } catch (er) { if (er.code !== 'EEXIST') return retryThrow(path, opts, er) if (opts.stale) { var st = fs.statSync(path) var ct = st[exports.filetime].getTime() if (!(ct % 1000) && (opts.stale % 1000)) { // probably don't have subsecond resolution. // round up the staleness indicator. // Yes, this will be wrong 1/1000 times on platforms // with subsecond stat precision, but that's acceptable // in exchange for not mistakenly removing locks on // most other systems. opts.stale = 1000 * Math.ceil(opts.stale / 1000) } var age = Date.now() - ct if (age > opts.stale) { debug('lockSync stale', path, opts, age) exports.unlockSync(path) return exports.lockSync(path, opts) } } // failed to lock! debug('failed to lock', path, opts, er) return retryThrow(path, opts, er) } } function retryThrow (path, opts, er) { if (typeof opts.retries === 'number' && opts.retries > 0) { var newRT = opts.retries - 1 debug('retryThrow', path, opts, newRT) opts.retries = newRT return exports.lockSync(path, opts) } throw er } PK!]A sockets.mdnu[to ACQUIRE(lockname) - create server, listen on lockname - if enotsock, WATCH(lockname) - if eaddrinuse, - CONNECT(lockname) - unref server - lock has been acquired via server ! on connection, place sockets in queue to RELEASE(lockname) - if acquired via connection - disconnect - if acquired via server - send "OK" to front-most connection - when connection disconnects, RELEASE(lockname) - if acquired via filename - unlink file to CONNECT(lockname) - net.connect(lockname) - if enoent or socket termination, ACQUIRE(lockname) - when server says "OK", - lock has been acquired via connection to WATCH(lockname) - fs.watch(lockname) - on change, ACQUIRE(lockname) PK!~~ .travis.ymlnu[language: node_js sudo: false node_js: - 8 - 6 - 4 notifications: email: false cache: directories: - $HOME/.npm PK!aGWLICENSEnu[The ISC License Copyright (c) Isaac Z. Schlueter and Contributors Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. PK!5!! CHANGELOG.mdnu[# Changes ## 1.0.4 * test parallel * upgrade tap * upgrade node versions in travis.yml * Use signal-exit package to detect exit instead of process.on('exit') * added some debugging lines ## v1.0.3 * handle the case where callback is not passed by user ## v1.0.2 * git ignore coverage and node_modules * update tap to v7 * build a changelog * package: fix repository link * pass tests on 0.8 * before_script needs to be before_install * tap 1.2.0 and travis ## v1.0.1 * isc license * updated README.md ## v1.0.0 * Simulate staleness instead of waiting excessively * whitespace * manage 'retries' so it does not clash with 'wait' polling * manage 'wait' timer properly * Get rid of the excessive Object.create opts shadowing stuff * failing test for the time taken for retries + wait options * doc: add pollPeriod, correct opts.wait * Fixed #6: polling period should be configurable ## v0.4.3 * Implement race-resistant stale lock detection * set req id to 1 to start out ## v0.4.2 * stale option fix for windows file tunneling ## v0.4.1 * Fix version parsing ## v0.4.0 * Don't keep lockfiles open ## v0.3.4 * retry more aggressively ## v0.3.3 * Add debugging function ## v0.3.2 * remove console.error ## v0.3.1 * Support lack of subsecond fs precision * Fix error closure overwriting in notStale ## v0.3.0 * Use polling instead of watchers * Add more overhead buffer to contention test ## v0.2.2 * Fix wait calculation * fixup * Style: prefer early return to giant if/else * unlock: Close before unlinking * Don't get tripped up by locks named 'hasOwnProperty' * test: Pathological extreme lock contention * refactor license ## 0.2.1 * Handle race conditions more thoroughly ## 0.2.0 * Rename to 'lockfile' ## 0.0.2 * Add retries * bsd ## 0.0.1 * tests * package.json * the code * first PK!hbb speedtest.jsnu[const path = require('path'); const async = require('async'); const lf = require('lockfile'); const fs = require('fs'); const n = +process.argv[3] || 300; const a = Array.apply(null, {length: n}).map(function(_, i) { return i }) const file = path.resolve(__dirname, 'speed-test.lock'); try{ fs.unlinkSync(file); } catch(e){} /// NOTE: this should run in about 30ms on a SSD Ubuntu 16.04, that is fast, because we are locking/unlocking 300 locks /// *HOWEVER* if we change async.eachSeries to async.each, lockfile will barf immediately, and I can't get lockfile /// to not barf, using any of the options {} available to lockfile#lock. const parallel = process.argv[2] === 'parallel'; var fn, msg; if(parallel){ msg = 'parallel'; fn = async.each; } else{ msg = 'series'; fn = async.eachSeries; } const start = Date.now(); console.log(' => locking/unlocking ' + a.length + ' times, in ' + msg); fn(a, function (val, cb) { console.log('try %d', val) lf.lock(file, { retries: n * 3 }, function (err) { if (err) { cb(err); } else { console.log('complete %d', val) lf.unlock(file, cb); } }); }, function complete(err) { if (err) { throw err; } console.log(' => Time required for lockfile => ', Date.now() - start, 'ms'); process.exit(0); }); PK!֭B package.jsonnu[{ "_args": [ [ "lockfile@1.0.4", "/Users/rebecca/code/npm" ] ], "_from": "lockfile@1.0.4", "_id": "lockfile@1.0.4", "_inBundle": false, "_integrity": "sha512-cvbTwETRfsFh4nHsL1eGWapU1XFi5Ot9E85sWAwia7Y7EgB7vfqcZhTKZ+l7hCGxSPoushMv5GKhT5PdLv03WA==", "_location": "/lockfile", "_phantomChildren": {}, "_requested": { "type": "version", "registry": true, "raw": "lockfile@1.0.4", "name": "lockfile", "escapedName": "lockfile", "rawSpec": "1.0.4", "saveSpec": null, "fetchSpec": "1.0.4" }, "_requiredBy": [ "/" ], "_resolved": "https://registry.npmjs.org/lockfile/-/lockfile-1.0.4.tgz", "_spec": "1.0.4", "_where": "/Users/rebecca/code/npm", "author": { "name": "Isaac Z. Schlueter", "email": "i@izs.me", "url": "http://blog.izs.me/" }, "bugs": { "url": "https://github.com/npm/lockfile/issues" }, "dependencies": { "signal-exit": "^3.0.2" }, "description": "A very polite lock file utility, which endeavors to not litter, and to wait patiently for others.", "devDependencies": { "tap": "^11.1.3", "touch": "0" }, "directories": { "test": "test" }, "homepage": "https://github.com/npm/lockfile#readme", "keywords": [ "lockfile", "lock", "file", "fs", "O_EXCL" ], "license": "ISC", "main": "lockfile.js", "name": "lockfile", "repository": { "type": "git", "url": "git+https://github.com/npm/lockfile.git" }, "scripts": { "changelog": "bash gen-changelog.sh", "postversion": "npm run changelog && git add CHANGELOG.md && git commit -m 'update changelog - '${npm_package_version}", "test": "tap test/*.js --cov -J" }, "version": "1.0.4" } PK!k   tokenizer.rbnu[# frozen_string_literal: true require 'rubygems/request_set/lockfile/parser' class Gem::RequestSet::Lockfile::Tokenizer Token = Struct.new :type, :value, :column, :line EOF = Token.new :EOF def self.from_file file new File.read(file), file end def initialize input, filename = nil, line = 0, pos = 0 @line = line @line_pos = pos @tokens = [] @filename = filename tokenize input end def make_parser set, platforms Gem::RequestSet::Lockfile::Parser.new self, set, platforms, @filename end def to_a @tokens.map { |token| [token.type, token.value, token.column, token.line] } end def skip type @tokens.shift while not @tokens.empty? and peek.type == type end ## # Calculates the column (by byte) and the line of the current token based on # +byte_offset+. def token_pos byte_offset # :nodoc: [byte_offset - @line_pos, @line] end def empty? @tokens.empty? end def unshift token @tokens.unshift token end def next_token @tokens.shift end alias :shift :next_token def peek @tokens.first || EOF end private def tokenize input require 'strscan' s = StringScanner.new input until s.eos? do pos = s.pos pos = s.pos if leading_whitespace = s.scan(/ +/) if s.scan(/[<|=>]{7}/) then message = "your #{@filename} contains merge conflict markers" column, line = token_pos pos raise Gem::RequestSet::Lockfile::ParseError.new message, column, line, @filename end @tokens << case when s.scan(/\r?\n/) then token = Token.new(:newline, nil, *token_pos(pos)) @line_pos = s.pos @line += 1 token when s.scan(/[A-Z]+/) then if leading_whitespace then text = s.matched text += s.scan(/[^\s)]*/).to_s # in case of no match Token.new(:text, text, *token_pos(pos)) else Token.new(:section, s.matched, *token_pos(pos)) end when s.scan(/([a-z]+):\s/) then s.pos -= 1 # rewind for possible newline Token.new(:entry, s[1], *token_pos(pos)) when s.scan(/\(/) then Token.new(:l_paren, nil, *token_pos(pos)) when s.scan(/\)/) then Token.new(:r_paren, nil, *token_pos(pos)) when s.scan(/<=|>=|=|~>|<|>|!=/) then Token.new(:requirement, s.matched, *token_pos(pos)) when s.scan(/,/) then Token.new(:comma, nil, *token_pos(pos)) when s.scan(/!/) then Token.new(:bang, nil, *token_pos(pos)) when s.scan(/[^\s),!]*/) then Token.new(:text, s.matched, *token_pos(pos)) else raise "BUG: can't create token for: #{s.string[s.pos..-1].inspect}" end end @tokens end end PK!8㜕 parser.rbnu[# frozen_string_literal: true class Gem::RequestSet::Lockfile::Parser ### # Parses lockfiles def initialize tokenizer, set, platforms, filename = nil @tokens = tokenizer @filename = filename @set = set @platforms = platforms end def parse until @tokens.empty? do token = get case token.type when :section then @tokens.skip :newline case token.value when 'DEPENDENCIES' then parse_DEPENDENCIES when 'GIT' then parse_GIT when 'GEM' then parse_GEM when 'PATH' then parse_PATH when 'PLATFORMS' then parse_PLATFORMS else token = get until @tokens.empty? or peek.first == :section end else raise "BUG: unhandled token #{token.type} (#{token.value.inspect}) at line #{token.line} column #{token.column}" end end end ## # Gets the next token for a Lockfile def get expected_types = nil, expected_value = nil # :nodoc: token = @tokens.shift if expected_types and not Array(expected_types).include? token.type then unget token message = "unexpected token [#{token.type.inspect}, #{token.value.inspect}], " + "expected #{expected_types.inspect}" raise Gem::RequestSet::Lockfile::ParseError.new message, token.column, token.line, @filename end if expected_value and expected_value != token.value then unget token message = "unexpected token [#{token.type.inspect}, #{token.value.inspect}], " + "expected [#{expected_types.inspect}, " + "#{expected_value.inspect}]" raise Gem::RequestSet::Lockfile::ParseError.new message, token.column, token.line, @filename end token end def parse_DEPENDENCIES # :nodoc: while not @tokens.empty? and :text == peek.type do token = get :text requirements = [] case peek[0] when :bang then get :bang requirements << pinned_requirement(token.value) when :l_paren then get :l_paren loop do op = get(:requirement).value version = get(:text).value requirements << "#{op} #{version}" break unless peek.type == :comma get :comma end get :r_paren if peek[0] == :bang then requirements.clear requirements << pinned_requirement(token.value) get :bang end end @set.gem token.value, *requirements skip :newline end end def parse_GEM # :nodoc: sources = [] while [:entry, 'remote'] == peek.first(2) do get :entry, 'remote' data = get(:text).value skip :newline sources << Gem::Source.new(data) end sources << Gem::Source.new(Gem::DEFAULT_HOST) if sources.empty? get :entry, 'specs' skip :newline set = Gem::Resolver::LockSet.new sources last_specs = nil while not @tokens.empty? and :text == peek.type do token = get :text name = token.value column = token.column case peek[0] when :newline then last_specs.each do |spec| spec.add_dependency Gem::Dependency.new name if column == 6 end when :l_paren then get :l_paren token = get [:text, :requirement] type = token.type data = token.value if type == :text and column == 4 then version, platform = data.split '-', 2 platform = platform ? Gem::Platform.new(platform) : Gem::Platform::RUBY last_specs = set.add name, version, platform else dependency = parse_dependency name, data last_specs.each do |spec| spec.add_dependency dependency end end get :r_paren else raise "BUG: unknown token #{peek}" end skip :newline end @set.sets << set end def parse_GIT # :nodoc: get :entry, 'remote' repository = get(:text).value skip :newline get :entry, 'revision' revision = get(:text).value skip :newline type = peek.type value = peek.value if type == :entry and %w[branch ref tag].include? value then get get :text skip :newline end get :entry, 'specs' skip :newline set = Gem::Resolver::GitSet.new set.root_dir = @set.install_dir last_spec = nil while not @tokens.empty? and :text == peek.type do token = get :text name = token.value column = token.column case peek[0] when :newline then last_spec.add_dependency Gem::Dependency.new name if column == 6 when :l_paren then get :l_paren token = get [:text, :requirement] type = token.type data = token.value if type == :text and column == 4 then last_spec = set.add_git_spec name, data, repository, revision, true else dependency = parse_dependency name, data last_spec.add_dependency dependency end get :r_paren else raise "BUG: unknown token #{peek}" end skip :newline end @set.sets << set end def parse_PATH # :nodoc: get :entry, 'remote' directory = get(:text).value skip :newline get :entry, 'specs' skip :newline set = Gem::Resolver::VendorSet.new last_spec = nil while not @tokens.empty? and :text == peek.first do token = get :text name = token.value column = token.column case peek[0] when :newline then last_spec.add_dependency Gem::Dependency.new name if column == 6 when :l_paren then get :l_paren token = get [:text, :requirement] type = token.type data = token.value if type == :text and column == 4 then last_spec = set.add_vendor_gem name, directory else dependency = parse_dependency name, data last_spec.dependencies << dependency end get :r_paren else raise "BUG: unknown token #{peek}" end skip :newline end @set.sets << set end def parse_PLATFORMS # :nodoc: while not @tokens.empty? and :text == peek.first do name = get(:text).value @platforms << name skip :newline end end ## # Parses the requirements following the dependency +name+ and the +op+ for # the first token of the requirements and returns a Gem::Dependency object. def parse_dependency name, op # :nodoc: return Gem::Dependency.new name, op unless peek[0] == :text version = get(:text).value requirements = ["#{op} #{version}"] while peek.type == :comma do get :comma op = get(:requirement).value version = get(:text).value requirements << "#{op} #{version}" end Gem::Dependency.new name, requirements end private def skip type # :nodoc: @tokens.skip type end ## # Peeks at the next token for Lockfile def peek # :nodoc: @tokens.peek end if [].respond_to? :flat_map def pinned_requirement name # :nodoc: requirement = Gem::Dependency.new name specification = @set.sets.flat_map { |set| set.find_all(requirement) }.compact.first specification && specification.version end else # FIXME: remove when 1.8 is dropped def pinned_requirement name # :nodoc: requirement = Gem::Dependency.new name specification = @set.sets.map { |set| set.find_all(requirement) }.flatten(1).compact.first specification && specification.version end end ## # Ungets the last token retrieved by #get def unget token # :nodoc: @tokens.unshift token end end PK!#$$ __init__.pynu[PK!Ǟ+P/P/ $__init__.pyonu[PK!!&~  bTmkdirlockfile.pynu[PK!|`pidlockfile.pycnu[PK!iY] ] xlinklockfile.pyonu[PK!_] symlinklockfile.pycnu[PK!_] symlinklockfile.pyonu[PK!6$hb b Cmkdirlockfile.pyonu[PK!6$hb b mkdirlockfile.pycnu[PK!g}Ha__sqlitelockfile.pyonu[PK!# 8 8 *symlinklockfile.pynu[PK!