python-stdnum commit: r78 - in python-stdnum: stdnum tests
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum commit: r78 - in python-stdnum: stdnum tests
- 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 commit: r78 - in python-stdnum: stdnum tests
- Date: Tue, 20 Sep 2011 22:52:04 +0200 (CEST)
Author: arthur
Date: Tue Sep 20 22:52:03 2011
New Revision: 78
URL: http://arthurdejong.org/viewvc/python-stdnum?revision=78&view=revision
Log:
fix a problem with an ISBN13 with a valid check digit but with an unknown
bookland prefix
Modified:
python-stdnum/stdnum/isbn.py
python-stdnum/tests/test_isbn.doctest
Modified: python-stdnum/stdnum/isbn.py
==============================================================================
--- python-stdnum/stdnum/isbn.py Sun Sep 4 11:23:07 2011 (r77)
+++ python-stdnum/stdnum/isbn.py Tue Sep 20 22:52:03 2011 (r78)
@@ -120,19 +120,18 @@
# clean up number
number = compact(number, convert)
# get Bookland prefix if any
+ delprefix = False
if len(number) == 10:
- oprefix = ''
- prefix = '978'
- else:
- oprefix = prefix = number[:3]
- number = number[3:]
+ number = '978' + number
+ delprefix = True
# split the number
- result = numdb.get('isbn').split(prefix + number[:-1])[1:]
- itemnr = result.pop()
+ result = numdb.get('isbn').split(number[:-1])
+ itemnr = result.pop() if result else ''
+ prefix = result.pop(0) if result else ''
group = result.pop(0) if result else ''
publisher = result.pop(0) if result else ''
# return results
- return (oprefix, group, publisher, itemnr, number[-1])
+ return ('' if delprefix else prefix, group, publisher, itemnr, number[-1])
def format(number, separator='-', convert=False):
Modified: python-stdnum/tests/test_isbn.doctest
==============================================================================
--- python-stdnum/tests/test_isbn.doctest Sun Sep 4 11:23:07 2011
(r77)
+++ python-stdnum/tests/test_isbn.doctest Tue Sep 20 22:52:03 2011
(r78)
@@ -59,3 +59,5 @@
('', '99996', '', '7827', '0')
>>> isbn.split('979-20-1234567-8')
('979', '', '', '201234567', '8')
+>>> isbn.split('5413170121522') # valid checkdigit, unknown prefix
+('', '', '', '541317012152', '2')
--
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/python-stdnum-commits/
- python-stdnum commit: r78 - in python-stdnum: stdnum tests,
Commits of the python-stdnum project