Page MenuHomeSoftware Heritage
Paste P636

(An Untitled Masterwork)
ActivePublic

Authored by douardda on Apr 2 2020, 4:22 PM.
@overload
def _get_key(self, object_type: str, object_: Union[Revision, Release, Directory, Snapshot]) -> bytes:
...
@overload
def _get_key(self, object_type: str, object_: Content) -> bytes:
...
@overload
def _get_key(self, object_type: str, object_: SkippedContent) -> Dict[str, bytes]:
...
@overload
def _get_key(self, object_type: str, object_: Origin) -> Dict[str, bytes]:
...
@overload
def _get_key(self, object_type: str, object_: OriginVisit) -> Dict[str, str]:
...
def _get_key(self, object_type: str, object_: BaseModel) -> Union[bytes, Dict]:
if object_type in ("revision", "release", "directory", "snapshot"):
return object_.id
elif object_type == "content":
return object_.sha1 # TODO: use a dict of hashes
elif object_type == "skipped_content":
return {hash: getattr(object_, hash) for hash in DEFAULT_ALGORITHMS}
elif object_type == "origin":
return {"url": object_.url}
elif object_type == "origin_visit":
return {
"origin": object_.origin,
"date": str(object_.date),
}
else:
raise ValueError("Unknown object type: %s." % object_type)