literature.validators#
Format-specific validators for the known identifier types, dispatched by validate_identifier.
- normalize_doi(value: str) str[source]#
Return value as a bare DOI when it is written as a doi.org URL or
doi:form.Any other value is returned unchanged for
validate_doi()to judge.- Parameters:
value – The DOI as written in the source.
- normalize_issn(value: str) str[source]#
Return an eight-character ISSN with its hyphen restored.
Any other value is returned unchanged for
validate_issn()to judge, so a number that fails its check digit is still refused.- Parameters:
value – The ISSN as written in the source.
- validate_doi(value: str) None[source]#
Validate a DOI string.
Every validator here raises
ValidationErrorfor an invalid value and returnsNonefor a valid one.validate_identifier()is the single entry pointItemIdentifier.clean()andsave()use, so every write path applies the same rules.A valid DOI starts with
10.followed by at least four digits, a forward slash, and at least one non-whitespace character.- Parameters:
value – The DOI string to validate.
- Raises:
ValidationError – if the value does not match the DOI pattern.
- validate_identifier(identifier_type: str, value: str) None[source]#
Validate value against the format rules for identifier_type.
Unknown identifier types carry no format constraint and pass through unvalidated, so nothing is lost. Delegates to the matching
validate_*function, which raisesValidationErrorfor a malformed value.- Parameters:
identifier_type – The identifier type to look up a validator for.
value – The identifier value to validate.
- Raises:
ValidationError – The matching validator rejected a malformed value.
- validate_isbn(value: str) None[source]#
Validate an ISBN-10 or ISBN-13 value (hyphens and spaces ignored).
A value that matches neither shape at all and a value that matches one shape but carries the wrong check digit are reported apart (FS-012): the latter is the commonest real error — a single mistyped character — and the case a well-formed example helps least with.
- Parameters:
value – The ISBN string to validate.
- Raises:
ValidationError –
invalid_isbn_checksumif value matches an ISBN-10 or ISBN-13 shape but its check digit does not;invalid_isbnif it matches neither shape.
- validate_issn(value: str) None[source]#
Validate an ISSN string (#118).
A valid ISSN has the format
NNNN-NNNXwhereXis a digit or the letter X (check character), and the eight characters together satisfy the standard’s modulo-11 checksum. A value that matches the shape but not the checksum is reported apart from a value that does not match the shape at all — the same distinctionvalidate_isbn()already reports.- Parameters:
value – The ISSN string to validate.
- Raises:
ValidationError –
invalid_issn_checksumif value matches ISSN’s shape but its check digit does not;invalid_issnif it does not match the shape at all.
- validate_pmcid(value: str) None[source]#
Validate a PubMed Central ID (PMCID).
Accepts the canonical NCBI form (
PMCfollowed by digits, e.g.PMC2728067) and a bare digit string, which is how some sources record the same identifier.- Parameters:
value – The PMCID string to validate.
- Raises:
ValidationError – if the value is neither form.