python-stdnum commit: r15 - in python-stdnum/stdnum: . isbn
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum commit: r15 - in python-stdnum/stdnum: . isbn
- 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: r15 - in python-stdnum/stdnum: . isbn
- Date: Tue, 27 Jul 2010 22:13:27 +0200 (CEST)
Author: arthur
Date: Tue Jul 27 22:13:25 2010
New Revision: 15
URL: http://arthurdejong.org/viewvc/python-stdnum?view=rev&revision=15
Log:
handle wrong types passed to validate() more gracefully
Modified:
python-stdnum/stdnum/bsn.py
python-stdnum/stdnum/isbn/__init__.py
python-stdnum/stdnum/issn.py
Modified: python-stdnum/stdnum/bsn.py
==============================================================================
--- python-stdnum/stdnum/bsn.py Mon Jul 26 22:46:29 2010 (r14)
+++ python-stdnum/stdnum/bsn.py Tue Jul 27 22:13:25 2010 (r15)
@@ -45,7 +45,10 @@
def validate(number):
"""Checks to see if the number provided is a valid BSN. This checks
the length and whether the check digit is correct."""
- number = compact(number)
+ try:
+ number = compact(number)
+ except:
+ return False
return len(number) == 9 and \
number.isdigit() and \
int(number) > 0 and \
Modified: python-stdnum/stdnum/isbn/__init__.py
==============================================================================
--- python-stdnum/stdnum/isbn/__init__.py Mon Jul 26 22:46:29 2010
(r14)
+++ python-stdnum/stdnum/isbn/__init__.py Tue Jul 27 22:13:25 2010
(r15)
@@ -62,7 +62,10 @@
def isbn_type(number):
"""Check the passed number and returns 'ISBN13', 'ISBN10' or None (for
invalid) for checking the type of number passed."""
- number = compact(number)
+ try:
+ number = compact(number)
+ except:
+ return None
if len(number) == 10:
if not number[:-1].isdigit():
return None
Modified: python-stdnum/stdnum/issn.py
==============================================================================
--- python-stdnum/stdnum/issn.py Mon Jul 26 22:46:29 2010 (r14)
+++ python-stdnum/stdnum/issn.py Tue Jul 27 22:13:25 2010 (r15)
@@ -46,7 +46,10 @@
def validate(number):
"""Checks to see if the number provided is a valid ISSN. This checks
the length and whether the check digit is correct."""
- number = compact(number)
+ try:
+ number = compact(number)
+ except:
+ return False
return len(number) == 8 and \
number[:-1].isdigit() and \
_calc_check_digit(number[:-1]) == number[-1]
--
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: r15 - in python-stdnum/stdnum: . isbn,
Commits of the python-stdnum project.