def __init__(self, filepath, set_lockstr=None, get_lockstr=None, failure_exc=None, provide_mutex=True): """Create a LockFile object. The 'filepath' argument should be the path to the file that will be used as the lockfile. If the caller may supply the following optional arguments: set_lockstr - A function that returns a string. This is called when the lock operation wants to write implementation specific text into the lock file. get_lockstr - A function that takes a string and returns a dictionary. This function must be able to parse the lock string created by set_lockstr. The dictionary object is passed as **kwargs to 'failure_exc' if the lock is non-blocking and fails. failure_exc - If a non-blocking lock acquisition fails, this exception will be raised. It should allow the caller to specify a kwargs argument, but not all invocations will provide kwargs. provide_mutex - By default, the LockFile object will use a mutex to sychronize access for threads in the current process. If the caller is already providing mutual exclusion to the LockFile object, this should be set to False.""" self._fileobj = None self._filepath = filepath self._set_lockstr = set_lockstr self._get_lockstr = get_lockstr self._provide_mutex = False if failure_exc: self._failure_exc = failure_exc else: self._failure_exc = FileLocked if provide_mutex: self._lock = nrlock.NRLock() self._provide_mutex = True else: self._lock = DummyLock()
def __init__(self, url, engine, ccancel=None): """Create a streaming file object that wraps around a transport engine. This is only necessary if the underlying transport doesn't have its own streaming interface and the repo operation needs a streaming response.""" self.__buf = b"" self.__url = url self.__engine = engine self.__data_callback_invoked = False self.__headers_arrived = False self.__httpmsg = None self.__headers = {} self.__done = False self.__check_cancelation = ccancel self.__lock = DummyLock() self.__uuid = uuidm.uuid4().int # Free buffer on exception. Set to False if caller may # read buffer after exception. Caller should call close() # to cleanup afterwards. self.free_buffer = True