Changeset View
Changeset View
Standalone View
Standalone View
swh/model/model.py
Show First 20 Lines • Show All 378 Lines • ▼ Show 20 Lines | def from_dict(cls, d, use_subclass=True): | ||||
else: | else: | ||||
return super().from_dict(d) | return super().from_dict(d) | ||||
def get_hash(self, hash_name): | def get_hash(self, hash_name): | ||||
if hash_name not in DEFAULT_ALGORITHMS: | if hash_name not in DEFAULT_ALGORITHMS: | ||||
raise ValueError('{} is not a valid hash name.'.format(hash_name)) | raise ValueError('{} is not a valid hash name.'.format(hash_name)) | ||||
return getattr(self, hash_name) | return getattr(self, hash_name) | ||||
def hashes(self) -> Dict[str, bytes]: | |||||
"""Returns a dictionary {hash_name: hash_value}""" | |||||
return {algo: getattr(self, algo) for algo in DEFAULT_ALGORITHMS} | |||||
@attr.s(frozen=True) | @attr.s(frozen=True) | ||||
class Content(BaseContent): | class Content(BaseContent): | ||||
sha1 = attr.ib(type=bytes) | sha1 = attr.ib(type=bytes) | ||||
sha1_git = attr.ib(type=Sha1Git) | sha1_git = attr.ib(type=Sha1Git) | ||||
sha256 = attr.ib(type=bytes) | sha256 = attr.ib(type=bytes) | ||||
blake2s256 = attr.ib(type=bytes) | blake2s256 = attr.ib(type=bytes) | ||||
▲ Show 20 Lines • Show All 76 Lines • Show Last 20 Lines |