Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/stdnum
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2017-08-30 22:32:17 +0200
committerArthur de Jong <arthur@arthurdejong.org>2017-08-30 22:32:17 +0200
commita71a1acedaa81c95042337856e4f5ecef84dfdd6 (patch)
treea5c705b523563c5e99363807c259e7f551bc632b /stdnum
parent8f6fa7db038a29941b70862386ae4120499637d2 (diff)
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.
Diffstat (limited to 'stdnum')
-rw-r--r--stdnum/isbn.py4
1 files changed, 3 insertions, 1 deletions
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])