This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/storage/fakestorage.py

32 lines
771 B
Python
Raw Normal View History

from storage.basestorage import BaseStorage
2015-05-29 22:08:17 +00:00
_FAKE_STORAGE_MAP = {}
class FakeStorage(BaseStorage):
def _init_path(self, path=None, create=False):
return path
def get_content(self, path):
2015-05-29 22:08:17 +00:00
if not path in _FAKE_STORAGE_MAP:
raise IOError('Fake file %s not found' % path)
return _FAKE_STORAGE_MAP.get(path)
def put_content(self, path, content):
2015-05-29 22:08:17 +00:00
_FAKE_STORAGE_MAP[path] = content
def stream_read(self, path):
2015-05-29 22:08:17 +00:00
yield _FAKE_STORAGE_MAP[path]
def stream_write(self, path, fp, content_type=None, content_encoding=None):
2015-05-29 22:08:17 +00:00
_FAKE_STORAGE_MAP[path] = fp.read()
def remove(self, path):
2015-05-29 22:08:17 +00:00
_FAKE_STORAGE_MAP.pop(path, None)
def exists(self, path):
2015-05-29 22:08:17 +00:00
return path in _FAKE_STORAGE_MAP
def get_checksum(self, path):
2015-05-29 22:08:17 +00:00
return path