src/pds_doi_service/core/outputs/doi_validator.py
def _check_lidvid_field(self, doi: Doi):
        """
        Checks the pds_identifier field of a Doi to ensure it conforms
        to the LIDVID format.

        Parameters
        ----------
        doi : Doi
            The parsed Doi object to validate

        Raises
        ------
        InvalidIdentifierException
            If the PDS identifier field of the DOI does not conform to
            the LIDVID format. These exceptions should be able to be bypassed
            when the --force flag is provided.

        """

        vid: Optional[str]
        if "::" in doi.pds_identifier:
            lid, vid = doi.pds_identifier.split("::")
        else:
            lid = doi.pds_identifier
            vid = None

        lid_tokens = lid.split(":")

        try:
            # Make sure we got a URN
            if lid_tokens[0] != "urn":
                raise InvalidIdentifierException('LIDVID must start with "urn"')

            # Make sure we got the minimum number of fields, and that
            # the number of fields is consistent with the product type
            if not MIN_LID_FIELDS <= len(lid_tokens) <= MAX_LID_FIELDS:
                raise InvalidIdentifierException(
                    f"LIDVID must contain only between {MIN_LID_FIELDS} "
                    f"and {MAX_LID_FIELDS} colon-delimited fields, "
                    f"got {len(lid_tokens)} field(s)"
                )

            # Now check each field for the expected set of characters
            token_regex = re.compile(r"[a-z0-9][a-z0-9-._]{0,31}")

            for index, token in enumerate(lid_tokens):
                if not token_regex.fullmatch(token):
                    raise InvalidIdentifierException(
                        f"LIDVID field {index + 1} ({token}) is invalid. "
                        f"Fields must begin with a letter or digit, and only "
                        f"consist of letters, digits, hyphens (-), underscores (_) "
                        f"or periods (.)"
                    )

            # Finally, make sure the VID conforms to a version number
            version_regex = re.compile(r"^\d+\.\d+$")

            if vid and not version_regex.fullmatch(vid):
                raise InvalidIdentifierException(
                    f"Parsed VID ({vid}) does not conform to a valid version identifier. "
                    "Version identifier must consist only of a major and minor version "
                    "joined with a period (ex: 1.0)"
                )
        except InvalidIdentifierException as err:
            raise InvalidIdentifierException(
                f"The record identifier {doi.pds_identifier} (DOI {doi.doi}) "
                f"does not conform to a valid LIDVID format.\n"
                f"Reason: {str(err)}\n"
                "If the identifier is not intended to be a LIDVID, use the "
                "--force option to bypass the results of this check."
            )

        Checks the pds_identifier field of a Doi to ensure it conforms
        to the LIDVID format.

        Parameters
        ----------
        doi : Doi
            The parsed Doi object to validate

        Raises
        ------
        InvalidIdentifierException
            If the PDS identifier field of the DOI does not conform to
            the LIDVID format. These exceptions should be able to be bypassed
            when the --force flag is provided.

        
Checks the pds_identifier field of a Doi to ensure it conforms
to the LIDVID format.

Parameters

doi : Doi
The parsed Doi object to validate

Raises

InvalidIdentifierException
If the PDS identifier field of the DOI does not conform to
the LIDVID format. These exceptions should be able to be bypassed
when the --force flag is provided.
Checks the pds_identifier field of a Doi to ensure it conforms to the LIDVID format . Parameters doi : Doi The parsed Doi object to validate Raises InvalidIdentifierException If the PDS identifier field of the DOI does not conform to the LIDVID format . These exceptions should be able to be bypassed when the -- force flag is provided .
def _check_lidvid_field(self, doi: Doi):
        vid: Optional[str]
        if "::" in doi.pds_identifier:
            lid, vid = doi.pds_identifier.split("::")
        else:
            lid = doi.pds_identifier
            vid = None
        lid_tokens = lid.split(":")
        try:
            if lid_tokens[0] != "urn":
                raise InvalidIdentifierException('LIDVID must start with "urn"')
            if not MIN_LID_FIELDS <= len(lid_tokens) <= MAX_LID_FIELDS:
                raise InvalidIdentifierException(
                    f"LIDVID must contain only between {MIN_LID_FIELDS} "
                    f"and {MAX_LID_FIELDS} colon-delimited fields, "
                    f"got {len(lid_tokens)} field(s)"
                )
            token_regex = re.compile(r"[a-z0-9][a-z0-9-._]{0,31}")
            for index, token in enumerate(lid_tokens):
                if not token_regex.fullmatch(token):
                    raise InvalidIdentifierException(
                        f"LIDVID field {index + 1} ({token}) is invalid. "
                        f"Fields must begin with a letter or digit, and only "
                        f"consist of letters, digits, hyphens (-), underscores (_) "
                        f"or periods (.)"
                    )
            version_regex = re.compile(r"^\d+\.\d+$")
            if vid and not version_regex.fullmatch(vid):
                raise InvalidIdentifierException(
                    f"Parsed VID ({vid}) does not conform to a valid version identifier. "
                    "Version identifier must consist only of a major and minor version "
                    "joined with a period (ex: 1.0)"
                )
        except InvalidIdentifierException as err:
            raise InvalidIdentifierException(
                f"The record identifier {doi.pds_identifier} (DOI {doi.doi}) "
                f"does not conform to a valid LIDVID format.\n"
                f"Reason: {str(err)}\n"
                "If the identifier is not intended to be a LIDVID, use the "
                "--force option to bypass the results of this check."
            )
def _check_lidvid_field ( self , doi : Doi ) : vid : Optional [ str ] if "::" in doi . pds_identifier : lid , vid = doi . pds_identifier . split ( "::" ) else : lid = doi . pds_identifier vid = None lid_tokens = lid . split ( ":" ) try : if lid_tokens [ 0 ] != "urn" : raise InvalidIdentifierException ( 'LIDVID must start with "urn"' ) if not MIN_LID_FIELDS <= len ( lid_tokens ) <= MAX_LID_FIELDS : raise InvalidIdentifierException ( f"LIDVID must contain only between {MIN_LID_FIELDS} " f"and {MAX_LID_FIELDS} colon-delimited fields, " f"got {len(lid_tokens)} field(s)" ) token_regex = re . compile ( r"[a-z0-9][a-z0-9-._]{0,31}" ) for index , token in enumerate ( lid_tokens ) : if not token_regex . fullmatch ( token ) : raise InvalidIdentifierException ( f"LIDVID field {index + 1} ({token}) is invalid. " f"Fields must begin with a letter or digit, and only " f"consist of letters, digits, hyphens (-), underscores (_) " f"or periods (.)" ) version_regex = re . compile ( r"^\d+\.\d+$" ) if vid and not version_regex . fullmatch ( vid ) : raise InvalidIdentifierException ( f"Parsed VID ({vid}) does not conform to a valid version identifier. " "Version identifier must consist only of a major and minor version " "joined with a period (ex: 1.0)" ) except InvalidIdentifierException as err : raise InvalidIdentifierException ( f"The record identifier {doi.pds_identifier} (DOI {doi.doi}) " f"does not conform to a valid LIDVID format.\n" f"Reason: {str(err)}\n" "If the identifier is not intended to be a LIDVID, use the " "--force option to bypass the results of this check." )
Checks the pds_identifier field of a Doi to ensure it conforms
to the LIDVID format.
Checks the pds_identifier field of a Doi to ensure it conforms to the LIDVID format .
"""
        Checks the pds_identifier field of a Doi to ensure it conforms
        to the LIDVID format.

        Parameters
        ----------
        doi : Doi
            The parsed Doi object to validate

        Raises
        ------
        InvalidIdentifierException
            If the PDS identifier field of the DOI does not conform to
            the LIDVID format. These exceptions should be able to be bypassed
            when the --force flag is provided.

        """ # Make sure we got a URN # Make sure we got the minimum number of fields, and that # the number of fields is consistent with the product type # Now check each field for the expected set of characters # Finally, make sure the VID conforms to a version number
self
doi
Doi