swh.web.utils.identifiers module#

swh.web.utils.identifiers.parse_object_type(object_type: str) ObjectType[source]#
swh.web.utils.identifiers.gen_swhid(object_type: ObjectType, object_id: str, scheme_version: int = 1, metadata: SWHIDContext = {}) str[source]#

Returns the SoftWare Hash 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.utils.identifiers.ResolvedSWHID[source]#

Bases: TypedDict

parsed SWHID with context

swhid_parsed: QualifiedSWHID#

URL to browse object according to SWHID context

browse_url: str | None#
swh.web.utils.identifiers.resolve_swhid(swhid: str, query_params: Mapping[str, str] | None = None) ResolvedSWHID[source]#

Try to resolve a SoftWare Hash IDentifier into an url for browsing the targeted object.

Parameters:
  • swhid – a SoftWare Hash 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.utils.identifiers.get_qualified_swhid(swhid: str) QualifiedSWHID[source]#

Leniently check if a qualified SWHID is valid and return it parsed. This allows a superset of core SWHIDs, which are badly capitalized or quoted.

Parameters:

swhid – a SoftWare Hash IDentifier.

Raises:

BadInputExc – if the provided SWHID cannot be parsed.

Returns:

A parsed SWHID.

swh.web.utils.identifiers.parse_core_swhid(swhid: str) CoreSWHID[source]#

Check if a core SWHID is valid and return it parsed.

Parameters:

swhid – a SoftWare Hash IDentifier.

Raises:

BadInputExc – if the provided SWHID cannot be parsed.

Returns:

A parsed SWHID.

swh.web.utils.identifiers.group_swhids(swhids: Iterable[CoreSWHID]) Dict[ObjectType, List[bytes]][source]#

Groups many SoftWare Hash IDentifiers into a dictionary depending on their type.

Parameters:

swhids – an iterable of SoftWare Hash IDentifier objects

Returns:

keys: object types values: object hashes

Return type:

A dictionary with

swh.web.utils.identifiers.get_swhids_info(swh_objects: Iterable[SWHObjectInfo], snapshot_context: SnapshotContext | None = None, extra_context: Mapping[str, Any] | None = None) List[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