From a71a1acedaa81c95042337856e4f5ecef84dfdd6 Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Wed, 30 Aug 2017 22:32:17 +0200 Subject: Check bookland code in ISBN This ensures that an InvalidComponent() exception is raised when an unknown EAN bookland code is found. It will also raise this exception when using to_isbn10() when not using the 978 code. --- stdnum/isbn.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'stdnum') diff --git a/stdnum/isbn.py b/stdnum/isbn.py index 2f42a45..e80f58a 100644 --- a/stdnum/isbn.py +++ b/stdnum/isbn.py @@ -100,6 +100,8 @@ def validate(number, convert=False): raise InvalidChecksum() elif len(number) == 13: ean.validate(number) + if number[:3] not in ('978', '979'): + raise InvalidComponent() else: raise InvalidLength() if convert: @@ -159,7 +161,7 @@ def to_isbn10(number): elif isbn_type(min_number) != 'ISBN13': raise InvalidFormat('Not a valid ISBN13.') elif not number.startswith('978'): - raise InvalidFormat('Does not use 978 Bookland prefix.') + raise InvalidComponent('Does not use 978 Bookland prefix.') # strip EAN prefix number = number[3:-1].strip().strip('-') digit = _calc_isbn10_check_digit(min_number[3:-1]) -- cgit v1.2.3