swh.web.common.query module

swh.web.common.query.parse_hash(q)[source]

Detect the hash type of a user submitted query string.

Parameters
  • string with the following format (query) – “[HASH_TYPE:]HEX_CHECKSUM”,

  • HASH_TYPE is optional, defaults to "sha1", and can be one of (where) –

  • swh.model.hashutil.ALGORITHMS

Returns

A pair (hash_algorithm, byte hash value)

Raises
  • ValueError if the given query string does not correspond to a valid

  • hash value

swh.web.common.query.parse_hash_with_algorithms_or_throws(q, accepted_algo, error_msg)[source]

Parse a query but only accepts accepted_algo. Otherwise, raise the exception with message error_msg.

Parameters
  • q (-) – query string with the following format: “[HASH_TYPE:]HEX_CHECKSUM”

  • HASH_TYPE is optional, defaults to "sha1", and can be one of (where) –

  • swh.model.hashutil.ALGORITHMS.

  • accepted_algo (-) – array of strings representing the names of accepted

  • algorithms.

  • error_msg (-) – error message to raise as BadInputExc if the algo of

  • query does not match. (the) –

Returns

A pair (hash_algorithm, byte hash value)

Raises
  • BadInputExc when the inputs is invalid or does not

  • validate the accepted algorithms.

swh.web.common.query.parse_uuid4(uuid)[source]

Parse an uuid 4 from a string.

Parameters

uuid – String representing an uuid.

Returns

The uuid as is if everything is ok.

Raises

BadInputExc – if the uuid is invalid.