Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"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
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
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
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)
)