Пример #1
0
    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)
Пример #2
0
 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)
Пример #3
0
 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)