stdnum.exceptions

Collection of exceptions.

The validation functions of stdnum should raise one of the below exceptions when validation of the number fails.

The exceptions are organised hierarchically in the following structure:

ValidationError
 +-- InvalidFormat
 |    +-- InvalidLength
 +-- InvalidChecksum
 +-- InvalidComponent

It is possible to change the exception messages by setting the message class property. This allows localisation and application-specific error messages.

>>> raise InvalidFormat()
Traceback (most recent call last):
    ...
InvalidChecksum: The number has an invalid format.
>>> InvalidFormat.message = 'UNKNOWN'
>>> raise InvalidFormat()
Traceback (most recent call last):
    ...
InvalidChecksum: UNKNOWN
exception stdnum.exceptions.ValidationError

Bases: ValueError

Top-level error for validating numbers.

This exception should normally not be raised, only subclasses of this exception.

exception stdnum.exceptions.InvalidFormat

Bases: ValidationError

Something is wrong with the format of the number.

This generally means characters or delimiters that are not allowed are part of the number or required parts are missing.

exception stdnum.exceptions.InvalidChecksum

Bases: ValidationError

The number’s internal checksum or check digit does not match.

exception stdnum.exceptions.InvalidLength

Bases: InvalidFormat

The length of the number is wrong.

exception stdnum.exceptions.InvalidComponent

Bases: ValidationError

One of the parts of the number has an invalid reference.

Some part of the number refers to some external entity like a country code, a date or a predefined collection of values. The number contains some invalid reference.