from storage.basestorage import BaseStorage
from cStringIO import StringIO
_FAKE_STORAGE_MAP = {}
class FakeStorage(BaseStorage):
def _init_path(self, path=None, create=False):
return path
def get_content(self, path):
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):
_FAKE_STORAGE_MAP[path] = content
def stream_read(self, path):
yield _FAKE_STORAGE_MAP[path]
def stream_read_file(self, path):
return StringIO(_FAKE_STORAGE_MAP[path])
def stream_write(self, path, fp, content_type=None, content_encoding=None):
_FAKE_STORAGE_MAP[path] = fp.read()
def remove(self, path):
_FAKE_STORAGE_MAP.pop(path, None)
def exists(self, path):
return path in _FAKE_STORAGE_MAP
def get_checksum(self, path):