def load_file(self, content_hash, file_name=None): file_path = storage.load_file(content_hash, file_name=file_name) if file_path is None: raise StorageFileMissing(content_hash, file_name=file_name) try: with open(file_path, 'r') as fh: yield fh finally: storage.cleanup_file(content_hash)
def load_file(self, content_hash, file_name=None, read_mode='rb'): file_path = storage.load_file(content_hash, file_name=file_name, temp_path=self.work_path) if file_path is None: yield None else: try: with open(file_path, mode=read_mode) as fh: yield fh finally: storage.cleanup_file(content_hash, temp_path=self.work_path)
def close(self): if self._response is not None: self._response.close() if self._remove_file and os.path.isfile(self._file_path): os.unlink(self._file_path) storage.cleanup_file(self._content_hash)