python-stdnum commit: r71 - python-stdnum/stdnum
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum commit: r71 - python-stdnum/stdnum
- 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: r71 - python-stdnum/stdnum
- Date: Mon, 20 Jun 2011 22:56:00 +0200 (CEST)
Author: arthur
Date: Mon Jun 20 22:55:58 2011
New Revision: 71
URL: http://arthurdejong.org/viewvc/python-stdnum?view=rev&revision=71
Log:
use the ean module for calculating the check digit
Modified:
python-stdnum/stdnum/isbn.py
python-stdnum/stdnum/ismn.py
Modified: python-stdnum/stdnum/isbn.py
==============================================================================
--- python-stdnum/stdnum/isbn.py Mon Jun 20 22:53:35 2011 (r70)
+++ python-stdnum/stdnum/isbn.py Mon Jun 20 22:55:58 2011 (r71)
@@ -1,4 +1,4 @@
-# __init__.py - functions for handling ISBNs
+# isbn.py - functions for handling ISBNs
#
# Copyright (C) 2010, 2011 Arthur de Jong
#
@@ -39,6 +39,8 @@
'978-1-85798-218-3'
"""
+from stdnum import ean
+
def compact(number, convert=False):
"""Convert the ISBN to the minimal representation. This strips the number
@@ -58,11 +60,6 @@
check = sum( (i + 1) * int(n) for i, n in enumerate(number) ) % 11
return 'X' if check == 10 else str(check)
-def _calc_isbn13_check_digit(number):
- """Calculate the ISBN check digit for 13-digit numbers. The number passed
- should not have the check bit included."""
- return str((10 - sum( (2 * (i % 2) + 1) * int(n) for i, n in
enumerate(number))) % 10)
-
def isbn_type(number):
"""Check the passed number and returns 'ISBN13', 'ISBN10' or None (for
invalid) for checking the type of number passed."""
@@ -79,7 +76,7 @@
elif len(number) == 13:
if not number.isdigit():
return None
- if _calc_isbn13_check_digit(number[:-1]) != number[-1]:
+ if ean.calc_check_digit(number[:-1]) != number[-1]:
return None
return 'ISBN13'
else:
@@ -99,7 +96,7 @@
if len(min_number) == 13:
return number # nothing to do, already ISBN-13
# put new check digit in place
- number = number[:-1] + _calc_isbn13_check_digit('978' + min_number[:-1])
+ number = number[:-1] + ean.calc_check_digit('978' + min_number[:-1])
# add prefix
if ' ' in number:
return '978 ' + number
Modified: python-stdnum/stdnum/ismn.py
==============================================================================
--- python-stdnum/stdnum/ismn.py Mon Jun 20 22:53:35 2011 (r70)
+++ python-stdnum/stdnum/ismn.py Mon Jun 20 22:55:58 2011 (r71)
@@ -1,6 +1,6 @@
-# __init__.py - functions for handling ISMNs
+# ismn.py - functions for handling ISMNs
#
-# Copyright (C) 2010 Arthur de Jong
+# Copyright (C) 2010, 2011 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
@@ -38,6 +38,8 @@
'9790230671187'
"""
+from stdnum import ean
+
def compact(number):
"""Convert the ISMN to the minimal representation. This strips the number
@@ -45,11 +47,6 @@
number = number.replace('
','').replace('-','').replace('.','').strip().upper()
return number
-def _calc_check_digit(number):
- """Calculate the ISMN check digit. The number passed should not have
- the check bit included and should be in the 13-digit form."""
- return str((10 - sum( (2 * (i % 2) + 1) * int(n) for i, n in
enumerate(number))) % 10)
-
def is_valid(number):
"""Checks to see if the number provided is a valid ISMN (either a legacy
10-digit one or a 13-digit one). This checks the length and the check
@@ -59,10 +56,10 @@
except:
return False
if len(number) == 10 and number[0] == 'M' and number[1:].isdigit():
- if _calc_check_digit('9790' + number[1:-1]) == number[-1]:
+ if ean.calc_check_digit('9790' + number[1:-1]) == number[-1]:
return True
elif len(number) == 13 and number.isdigit():
- if _calc_check_digit(number[:-1]) == number[-1]:
+ if ean.calc_check_digit(number[:-1]) == number[-1]:
return True
return False
--
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: r71 - python-stdnum/stdnum,
Commits of the python-stdnum project