lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.6-5-g57c12d8

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-stdnum branch master updated. 1.6-5-g57c12d8



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  57c12d816bcf324b14cb2dc7f8b284400c075591 (commit)
       via  6fb2e899537564194bb44e71f96505b7eea903e4 (commit)
      from  5604d91be8e92f12b0bf2c599bb858e8f3704143 (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=57c12d816bcf324b14cb2dc7f8b284400c075591

commit 57c12d816bcf324b14cb2dc7f8b284400c075591
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sat Apr 15 21:20:05 2017 +0200

    An ISMN can only be 10 or 13 digits
    
    This also adds the test that an ISMN should start with 9790.

diff --git a/stdnum/ismn.py b/stdnum/ismn.py
index 3de83f1..b04c763 100644
--- a/stdnum/ismn.py
+++ b/stdnum/ismn.py
@@ -1,6 +1,6 @@
 # ismn.py - functions for handling ISMNs
 #
-# Copyright (C) 2010, 2011, 2012, 2013 Arthur de Jong
+# Copyright (C) 2010-2017 Arthur de Jong
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -62,8 +62,12 @@ def validate(number):
         if number[0] != 'M':
             raise InvalidFormat()
         ean.validate('9790' + number[1:])
-    else:
+    elif len(number) == 13:
+        if not number.startswith('9790'):
+            raise InvalidComponent()
         ean.validate(number)
+    else:
+        raise InvalidLength()
     return number
 
 
diff --git a/tests/test_ismn.doctest b/tests/test_ismn.doctest
index c3d46b6..23eb5f2 100644
--- a/tests/test_ismn.doctest
+++ b/tests/test_ismn.doctest
@@ -1,6 +1,6 @@
 test_ismn.doctest - more detailed doctests for stdnum.ismn module
 
-Copyright (C) 2010, 2011, 2012, 2013 Arthur de Jong
+Copyright (C) 2010-2017 Arthur de Jong
 
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
@@ -41,7 +41,7 @@ These are normal variations that should just work.
 '9790260000438'
 
 
-Tests for mangling and incorect check digits.
+Tests for mangling and incorrect check digits.
 
 >>> ismn.validate('979-0-3217-6543-x')
 Traceback (most recent call last):
@@ -54,7 +54,7 @@ InvalidChecksum: ...
 >>> ismn.validate('979M321765450')
 Traceback (most recent call last):
     ...
-InvalidFormat: ...
+InvalidComponent: ...
 >>> ismn.validate('Z-3217-6546-8')
 Traceback (most recent call last):
     ...
@@ -72,6 +72,7 @@ See if 10 to 13 digit conversion works.
 
 
 Test the ismn_type() function
+
 >>> ismn.ismn_type('M-3217-6546-7')
 'ISMN10'
 >>> ismn.ismn_type('BAD')
@@ -85,3 +86,16 @@ Regrouping tests.
 '979-0-3217-6546-7'
 >>> ismn.format('9790321765450')
 '979-0-3217-6545-0'
+
+
+While an EAN can also be less than 13 digits and ISMN should always be
+13 digits (when not 10 digits) and start with 9790.
+
+>>> ismn.validate('979023456784')
+Traceback (most recent call last):
+    ...
+InvalidLength: ...
+>>> ismn.validate('9781234567866')
+Traceback (most recent call last):
+    ...
+InvalidComponent: ...

https://arthurdejong.org/git/python-stdnum/commit/?id=6fb2e899537564194bb44e71f96505b7eea903e4

commit 6fb2e899537564194bb44e71f96505b7eea903e4
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sat Apr 15 14:32:45 2017 +0200

    Fix conversion of 9 digit ISBN to ISBN13

diff --git a/stdnum/isbn.py b/stdnum/isbn.py
index b511c4c..2f42a45 100644
--- a/stdnum/isbn.py
+++ b/stdnum/isbn.py
@@ -1,6 +1,6 @@
 # isbn.py - functions for handling ISBNs
 #
-# Copyright (C) 2010-2015 Arthur de Jong
+# Copyright (C) 2010-2017 Arthur de Jong
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -134,9 +134,11 @@ def is_valid(number):
 def to_isbn13(number):
     """Convert the number to ISBN-13 format."""
     number = number.strip()
-    min_number = compact(number, convert=False)
+    min_number = clean(number, ' -')
     if len(min_number) == 13:
         return number  # nothing to do, already ISBN-13
+    if len(min_number) == 9:
+        number = '0' + number  # convert from 9 to 10 digits
     # put new check digit in place
     number = number[:-1] + ean.calc_check_digit('978' + min_number[:-1])
     # add prefix
diff --git a/tests/test_isbn.doctest b/tests/test_isbn.doctest
index d38d51f..7d0c7f6 100644
--- a/tests/test_isbn.doctest
+++ b/tests/test_isbn.doctest
@@ -1,6 +1,6 @@
 test_isbn.doctest - more detailed doctests for stdnum.isbn module
 
-Copyright (C) 2010, 2011, 2013 Arthur de Jong
+Copyright (C) 2010-2017 Arthur de Jong
 
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
@@ -63,6 +63,14 @@ See if ISBN10 to 13 conversion works.
 '9781857982183'
 
 
+Conversion of 9 digit ISBN to ISBN13 also works.
+
+>>> isbn.is_valid('12-345678-9')
+True
+>>> isbn.validate(isbn.to_isbn13('12-345678-9'))
+'9780123456786'
+
+
 See if ISBN13 to 10 conversion works.
 
 >>> isbn.to_isbn10('1-85798-218-5')  # ISBN10 should stay ISBN10

-----------------------------------------------------------------------

Summary of changes:
 stdnum/isbn.py          |  6 ++++--
 stdnum/ismn.py          |  8 ++++++--
 tests/test_isbn.doctest | 10 +++++++++-
 tests/test_ismn.doctest | 20 +++++++++++++++++---
 4 files changed, 36 insertions(+), 8 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/