Changeset View
Changeset View
Standalone View
Standalone View
swh/model/model.py
Show First 20 Lines • Show All 534 Lines • ▼ Show 20 Lines | status = attr.ib( | ||||
type=str, | type=str, | ||||
validator=attr.validators.in_(["visible", "hidden"]), | validator=attr.validators.in_(["visible", "hidden"]), | ||||
default="visible", | default="visible", | ||||
) | ) | ||||
data = attr.ib(type=Optional[bytes], validator=type_validator(), default=None) | data = attr.ib(type=Optional[bytes], validator=type_validator(), default=None) | ||||
ctime = attr.ib( | ctime = attr.ib( | ||||
type=Optional[datetime.datetime], validator=type_validator(), default=None | type=Optional[datetime.datetime], | ||||
validator=type_validator(), | |||||
default=None, | |||||
eq=False, | |||||
) | ) | ||||
@length.validator | @length.validator | ||||
def check_length(self, attribute, value): | def check_length(self, attribute, value): | ||||
"""Checks the length is positive.""" | """Checks the length is positive.""" | ||||
if value < 0: | if value < 0: | ||||
raise ValueError("Length must be positive.") | raise ValueError("Length must be positive.") | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | class SkippedContent(BaseContent): | ||||
length = attr.ib(type=Optional[int], validator=type_validator()) | length = attr.ib(type=Optional[int], validator=type_validator()) | ||||
status = attr.ib(type=str, validator=attr.validators.in_(["absent"])) | status = attr.ib(type=str, validator=attr.validators.in_(["absent"])) | ||||
reason = attr.ib(type=Optional[str], validator=type_validator(), default=None) | reason = attr.ib(type=Optional[str], validator=type_validator(), default=None) | ||||
origin = attr.ib(type=Optional[str], validator=type_validator(), default=None) | origin = attr.ib(type=Optional[str], validator=type_validator(), default=None) | ||||
ctime = attr.ib( | ctime = attr.ib( | ||||
type=Optional[datetime.datetime], validator=type_validator(), default=None | type=Optional[datetime.datetime], | ||||
validator=type_validator(), | |||||
default=None, | |||||
eq=False, | |||||
) | ) | ||||
@reason.validator | @reason.validator | ||||
def check_reason(self, attribute, value): | def check_reason(self, attribute, value): | ||||
"""Checks the reason is full if status != absent.""" | """Checks the reason is full if status != absent.""" | ||||
assert self.reason == value | assert self.reason == value | ||||
if value is None: | if value is None: | ||||
raise ValueError("Must provide a reason if content is absent.") | raise ValueError("Must provide a reason if content is absent.") | ||||
Show All 38 Lines |