allisbns.errors

Exceptions specific to the package.

exception allisbns.errors.AllISBNsError

Bases: Exception

Base package exception.

class allisbns.errors.InvalidISBNReason(*values)

Bases: StrEnum

Reasons for invalid ISBNs.

Supposed to be used for allisbns.isbn.MaybeISBN and allisbns.isbn.CanonicalISBN.

Examples

While ‘978-0-00-000000-K’ contains the bad check digit (‘K’), we first don’t recognize it as an ISBN with match_isbn(), and therefore NOT_ISBN should be used here. Such reasons (along with bad length, bad characters, etc.) could be taken out into a separate enum, say, NotISBNReason, but we don’t go that far.

NOT_ISBN = 'not_isbn'

Not an ISBN.

BAD_GROUP = 'bad_group'

Undefined registration group.

BAD_REGISTRANT = 'bad_registrant'

Undefined registrant.

BAD_CHECK_DIGIT = 'bad_check_digit'

Incorrectly calculated check digit.

exception allisbns.errors.InvalidISBNError(message: str, reason: InvalidISBNReason, isbn: MaybeISBN | CanonicalISBN)

Bases: AllISBNsError, ValueError

Raised when an ISBN is not valid.

__init__(message: str, reason: InvalidISBNReason, isbn: MaybeISBN | CanonicalISBN)

Creates an exception with message and reason for isbn.

exception allisbns.errors.NotISBNError(isbn: MaybeISBN, message: str | None = None)

Bases: InvalidISBNError

Raised when the value is not an ISBN.

__init__(isbn: MaybeISBN, message: str | None = None)

Creates an exception with message for isbn.

exception allisbns.errors.UndefinedISBNRangeError(message: str, reason: InvalidISBNReason, isbn: CanonicalISBN)

Bases: InvalidISBNError

Raised when the registration group or registrant range are undefined.

__init__(message: str, reason: InvalidISBNReason, isbn: CanonicalISBN)

Creates an exception with message and reason for isbn.

exception allisbns.errors.NotISBN12Error

Bases: AllISBNsError, ValueError

Raised when a value is not an ISBN-12 number.