Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/identifiers.py
Show First 20 Lines • Show All 227 Lines • ▼ Show 20 Lines | """Check if a SWHID is valid and return it parsed. | ||||
Raises: | Raises: | ||||
BadInputExc: if the provided SWHID can not be parsed. | BadInputExc: if the provided SWHID can not be parsed. | ||||
Return: | Return: | ||||
A parsed SWHID. | A parsed SWHID. | ||||
""" | """ | ||||
try: | try: | ||||
# ensure core part of SWHID is in lower case to avoid parsing error | |||||
qualifiers_pos = swhid.find(";") | |||||
if qualifiers_pos == -1: | |||||
swhid = swhid.lower() | |||||
else: | |||||
swhid = swhid[:qualifiers_pos].lower() + swhid[qualifiers_pos:] | |||||
swhid_parsed = QualifiedSWHID.from_string(swhid) | swhid_parsed = QualifiedSWHID.from_string(swhid) | ||||
except ValidationError as ve: | except ValidationError as ve: | ||||
raise BadInputExc("Error when parsing identifier: %s" % " ".join(ve.messages)) | raise BadInputExc("Error when parsing identifier: %s" % " ".join(ve.messages)) | ||||
else: | else: | ||||
return swhid_parsed | return swhid_parsed | ||||
def group_swhids(swhids: Iterable[QualifiedSWHID],) -> Dict[str, List[bytes]]: | def group_swhids(swhids: Iterable[QualifiedSWHID],) -> Dict[str, List[bytes]]: | ||||
▲ Show 20 Lines • Show All 141 Lines • Show Last 20 Lines |