Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/validate.py
Show All 10 Lines | from swh.model.model import ( | ||||
BaseModel, SkippedContent, Content, Directory, Revision, Release, Snapshot, | BaseModel, SkippedContent, Content, Directory, Revision, Release, Snapshot, | ||||
OriginVisit, Origin | OriginVisit, Origin | ||||
) | ) | ||||
from . import get_storage | from . import get_storage | ||||
from .exc import StorageArgumentException | from .exc import StorageArgumentException | ||||
VALIDATION_EXCEPTIONS = ( | VALIDATION_EXCEPTIONS = [ | ||||
KeyError, | KeyError, | ||||
TypeError, | TypeError, | ||||
ValueError, | ValueError, | ||||
) | ] | ||||
@contextlib.contextmanager | @contextlib.contextmanager | ||||
def convert_validation_exceptions(): | def convert_validation_exceptions(): | ||||
"""Catches validation errors arguments, and re-raises a | """Catches validation errors arguments, and re-raises a | ||||
StorageArgumentException.""" | StorageArgumentException.""" | ||||
try: | try: | ||||
yield | yield | ||||
except VALIDATION_EXCEPTIONS as e: | except tuple(VALIDATION_EXCEPTIONS) as e: | ||||
raise StorageArgumentException(*e.args) | raise StorageArgumentException(*e.args) | ||||
class ValidatingProxyStorage: | class ValidatingProxyStorage: | ||||
"""Storage implementation converts dictionaries to swh-model objects | """Storage implementation converts dictionaries to swh-model objects | ||||
before calling its backend, and back to dicts before returning results | before calling its backend, and back to dicts before returning results | ||||
""" | """ | ||||
▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines |