How to use the isbnlib.notisbn function in isbnlib

To help you get started, we’ve selected a few isbnlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github manubot / manubot / manubot / cite / citekey.py View on Github external
"Double check the DOI."
                )
        elif identifier.startswith("10/"):
            # shortDOI, see http://shortdoi.org
            if not regexes["shortdoi"].fullmatch(identifier):
                return (
                    "Identifier does not conform to the shortDOI regex. "
                    "Double check the shortDOI."
                )
        else:
            return "DOIs must start with '10.' (or '10/' for shortDOIs)."

    if source == "isbn":
        import isbnlib

        fail = isbnlib.notisbn(identifier, level="strict")
        if fail:
            return f"identifier violates the ISBN syntax according to isbnlib v{isbnlib.__version__}"

    if source == "wikidata":
        # https://www.wikidata.org/wiki/Wikidata:Identifiers
        if not identifier.startswith("Q"):
            return "Wikidata item IDs must start with 'Q'."
        elif not regexes["wikidata"].fullmatch(identifier):
            return (
                "Identifier does not conform to the Wikidata regex. "
                "Double check the entity ID."
            )

    return None
github wikimedia / pywikibot / scripts / isbn.py View on Github external
try:
            stdnum.isbn.validate(isbn)
        except stdnum.isbn.InvalidFormat as e:
            raise InvalidIsbnException(str(e))
        except stdnum.isbn.InvalidChecksum as e:
            raise InvalidIsbnException(str(e))
        except stdnum.isbn.InvalidLength as e:
            raise InvalidIsbnException(str(e))
        return True

    try:
        isbnlib
    except NameError:
        pass
    else:
        if isbnlib.notisbn(isbn):
            raise InvalidIsbnException('Invalid ISBN found')
        return True

    getIsbn(isbn)
    return True
github JackPotte / JackBot / core / scripts / isbn.py View on Github external
try:
            stdnum.isbn.validate(isbn)
        except stdnum.isbn.InvalidFormat as e:
            raise InvalidIsbnException(str(e))
        except stdnum.isbn.InvalidChecksum as e:
            raise InvalidIsbnException(str(e))
        except stdnum.isbn.InvalidLength as e:
            raise InvalidIsbnException(str(e))
        return True

    try:
        isbnlib
    except NameError:
        pass
    else:
        if isbnlib.notisbn(isbn):
            raise InvalidIsbnException('Invalid ISBN found')
        return True

    getIsbn(isbn)
    return True
github Phyks / libbmc / libbmc / isbn.py View on Github external
False

    >>> is_valid("0136091814")
    True

    >>> is_valid("0136091812")
    False

    >>> is_valid("9780136091817")
    False

    >>> is_valid("123456789X")
    True
    """
    return (
        (not isbnlib.notisbn(isbn_id)) and (
            isbnlib.get_canonical_isbn(isbn_id) == isbn_id or
            isbnlib.mask(isbnlib.get_canonical_isbn(isbn_id)) == isbn_id)
    )