Changeset View
Changeset View
Standalone View
Standalone View
swh/model/model.py
Show First 20 Lines • Show All 443 Lines • ▼ Show 20 Lines | |||||
class RevisionType(Enum): | class RevisionType(Enum): | ||||
GIT = "git" | GIT = "git" | ||||
TAR = "tar" | TAR = "tar" | ||||
DSC = "dsc" | DSC = "dsc" | ||||
SUBVERSION = "svn" | SUBVERSION = "svn" | ||||
MERCURIAL = "hg" | MERCURIAL = "hg" | ||||
def tuplify_extra_headers(value: Iterable) -> Tuple: | def tuplify_extra_headers(value: Iterable): | ||||
return tuple((k, v) for k, v in value) | return tuple((k, v) for k, v in value) | ||||
@attr.s(frozen=True) | @attr.s(frozen=True) | ||||
class Revision(BaseModel, HashableObject): | class Revision(BaseModel, HashableObject): | ||||
object_type: Final = "revision" | object_type: Final = "revision" | ||||
message = attr.ib(type=Optional[bytes], validator=type_validator()) | message = attr.ib(type=Optional[bytes], validator=type_validator()) | ||||
Show All 10 Lines | metadata = attr.ib( | ||||
type=Optional[ImmutableDict[str, object]], | type=Optional[ImmutableDict[str, object]], | ||||
validator=type_validator(), | validator=type_validator(), | ||||
converter=freeze_optional_dict, | converter=freeze_optional_dict, | ||||
default=None, | default=None, | ||||
) | ) | ||||
parents = attr.ib(type=Tuple[Sha1Git, ...], validator=type_validator(), default=()) | parents = attr.ib(type=Tuple[Sha1Git, ...], validator=type_validator(), default=()) | ||||
id = attr.ib(type=Sha1Git, validator=type_validator(), default=b"") | id = attr.ib(type=Sha1Git, validator=type_validator(), default=b"") | ||||
extra_headers = attr.ib( | extra_headers = attr.ib( | ||||
type=Tuple[Tuple[bytes, bytes], ...], # but it makes mypy sad | type=Tuple[Tuple[bytes, bytes], ...], | ||||
validator=type_validator(), | validator=type_validator(), | ||||
converter=tuplify_extra_headers, # type: ignore | converter=tuplify_extra_headers, | ||||
default=(), | default=(), | ||||
) | ) | ||||
def __attrs_post_init__(self): | def __attrs_post_init__(self): | ||||
super().__attrs_post_init__() | super().__attrs_post_init__() | ||||
# ensure metadata is a deep copy of whatever was given, and if needed | # ensure metadata is a deep copy of whatever was given, and if needed | ||||
# extract extra_headers from there | # extract extra_headers from there | ||||
if self.metadata: | if self.metadata: | ||||
▲ Show 20 Lines • Show All 538 Lines • Show Last 20 Lines |