swh.web.common.identifiers module¶
-
swh.web.common.identifiers.
gen_swhid
(object_type: str, object_id: str, scheme_version: int = 1, metadata: swh.web.common.typing.SWHIDContext = {}) → str[source]¶ Returns the SoftWare Heritage persistent IDentifier for a swh object based on:
the object type
the object id
the SWHID scheme version
- Parameters
object_type – the swh object type (content/directory/release/revision/snapshot)
object_id – the swh object id (hexadecimal representation of its hash value)
scheme_version – the scheme version of the SWHIDs
- Returns
the SWHID of the object
- Raises
BadInputExc – if the provided parameters do not enable to generate a valid identifier
-
class
swh.web.common.identifiers.
ResolvedSWHID
(**kwargs)[source]¶ Bases:
dict
parsed SWHID with context
-
swhid_parsed
: swh.model.identifiers.QualifiedSWHID¶ URL to browse object according to SWHID context
-
browse_url
: Optional[str]¶
-
-
swh.web.common.identifiers.
resolve_swhid
(swhid: str, query_params: Optional[Union[Dict[str, Any], django.http.request.QueryDict]] = None) → swh.web.common.identifiers.ResolvedSWHID[source]¶ Try to resolve a SoftWare Heritage persistent IDentifier into an url for browsing the targeted object.
- Parameters
swhid – a SoftWare Heritage persistent IDentifier
query_params – optional dict filled with query parameters to append to the browse url
- Returns
swhid_parsed: the parsed identifier
browse_url: the url for browsing the targeted object
- Return type
a dict with the following keys
-
swh.web.common.identifiers.
get_swhid
(swhid: str) → swh.model.identifiers.QualifiedSWHID[source]¶ Check if a SWHID is valid and return it parsed.
- Parameters
swhid – a SoftWare Heritage persistent IDentifier.
- Raises
BadInputExc – if the provided SWHID can not be parsed.
- Returns
A parsed SWHID.
-
swh.web.common.identifiers.
group_swhids
(swhids: Iterable[swh.model.identifiers.QualifiedSWHID]) → Dict[str, List[bytes]][source]¶ Groups many SoftWare Heritage persistent IDentifiers into a dictionary depending on their type.
- Parameters
swhids – an iterable of SoftWare Heritage persistent IDentifier objects
- Returns
keys: object types values: object hashes
- Return type
A dictionary with
-
swh.web.common.identifiers.
get_swhids_info
(swh_objects: Iterable[swh.web.common.typing.SWHObjectInfo], snapshot_context: Optional[swh.web.common.typing.SnapshotContext] = None, extra_context: Optional[Dict[str, Any]] = None) → List[swh.web.common.typing.SWHIDInfo][source]¶ Returns a list of dict containing info related to SWHIDs of objects.
- Parameters
swh_objects – an iterable of dict describing archived objects
snapshot_context – optional dict parameter describing the snapshot in which the objects have been found
extra_context – optional dict filled with extra contextual info about the objects
- Returns
a list of dict containing SWHIDs info