swh.web.utils.query module#
- swh.web.utils.query.parse_hash(q)[source]#
Detect the hash type of a user submitted query string.
- Parameters:
format (query string with the following) – “[HASH_TYPE:]HEX_CHECKSUM”,
optional (where HASH_TYPE is) –
"sha1" (defaults to) –
of (and can be one) –
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.utils.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”
optional (where HASH_TYPE is) –
"sha1" (defaults to) –
of (and can be one) –
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
match. (the query does not) –
- Returns:
A pair (hash_algorithm, byte hash value)
- Raises:
BadInputExc when the inputs is invalid or does not –
validate the accepted algorithms. –