python-stdnum branch master updated. 1.6-15-ga71a1ac
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum branch master updated. 1.6-15-ga71a1ac
- From: Commits of the python-stdnum project <python-stdnum-commits [at] lists.arthurdejong.org>
- To: python-stdnum-commits [at] lists.arthurdejong.org
- Reply-to: python-stdnum-users [at] lists.arthurdejong.org
- Subject: python-stdnum branch master updated. 1.6-15-ga71a1ac
- Date: Wed, 30 Aug 2017 23:35:01 +0200 (CEST)
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "python-stdnum".
The branch, master has been updated
via a71a1acedaa81c95042337856e4f5ecef84dfdd6 (commit)
from 8f6fa7db038a29941b70862386ae4120499637d2 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
https://arthurdejong.org/git/python-stdnum/commit/?id=a71a1acedaa81c95042337856e4f5ecef84dfdd6
commit a71a1acedaa81c95042337856e4f5ecef84dfdd6
Author: Arthur de Jong <arthur@arthurdejong.org>
Date: Wed Aug 30 22:32:17 2017 +0200
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.
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])
diff --git a/tests/test_isbn.doctest b/tests/test_isbn.doctest
index 954e519..91f4863 100644
--- a/tests/test_isbn.doctest
+++ b/tests/test_isbn.doctest
@@ -25,7 +25,7 @@ really useful as module documentation.
>>> from stdnum import isbn
-Tests for mangling and incorect check digits.
+Tests for mangling and incorrect check digits.
>>> isbn.validate('08515x-629-2') # added X in the middle
Traceback (most recent call last):
@@ -43,6 +43,10 @@ InvalidFormat: ...
Traceback (most recent call last):
...
InvalidLength: ...
+>>> isbn.validate('7501031311309') # valid EAN, unknown bookland code
+Traceback (most recent call last):
+ ...
+InvalidComponent: ...
See if ISBN10 to 13 conversion works.
@@ -88,7 +92,7 @@ InvalidFormat: ...
>>> isbn.to_isbn10('9791843123391')
Traceback (most recent call last):
...
-InvalidFormat: ...
+InvalidComponent: ...
Regrouping tests.
@@ -99,7 +103,7 @@ Regrouping tests.
('', '99996', '', '7827', '0')
>>> isbn.split('979-20-1234567-8')
('979', '', '', '201234567', '8')
->>> isbn.split('5413170121522') # valid checkdigit, unknown prefix
+>>> isbn.split('5413170121522') # valid check digit, unknown prefix
('', '', '', '541317012152', '2')
-----------------------------------------------------------------------
Summary of changes:
stdnum/isbn.py | 4 +++-
tests/test_isbn.doctest | 10 +++++++---
2 files changed, 10 insertions(+), 4 deletions(-)
hooks/post-receive
--
python-stdnum
--
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
https://lists.arthurdejong.org/python-stdnum-commits/
- python-stdnum branch master updated. 1.6-15-ga71a1ac,
Commits of the python-stdnum project