update shared dependencies

This commit is contained in:
j 2016-02-23 11:36:55 +05:30
commit 736cd598a8
521 changed files with 45146 additions and 22574 deletions

View file

@ -31,6 +31,8 @@ Traceback (most recent call last):
InvalidFormat: ...
>>> format('123456789')
'123-45-6789'
>>> format('123') # unknown formatting is left alone
'123'
"""
import re
@ -40,7 +42,7 @@ from stdnum.util import clean
# regular expression for matching ATINs
_atin_re = re.compile('^[0-9]{3}-?[0-9]{2}-?[0-9]{4}$')
_atin_re = re.compile(r'^[0-9]{3}-?[0-9]{2}-?[0-9]{4}$')
def compact(number):

View file

@ -38,6 +38,8 @@ Traceback (most recent call last):
InvalidComponent: ...
>>> format('042103594')
'04-2103594'
>>> format('123') # unknown formatting is left alone
'123'
"""
import re
@ -47,7 +49,7 @@ from stdnum.util import clean
# regular expression for matching EINs
_ein_re = re.compile('^(?P<area>[0-9]{2})-?(?P<group>[0-9]{7})$')
_ein_re = re.compile(r'^(?P<area>[0-9]{2})-?(?P<group>[0-9]{7})$')
def compact(number):

View file

@ -45,6 +45,8 @@ InvalidComponent: ...
'123456789'
>>> format('111223333')
'111-22-3333'
>>> format('123') # unknown formatting is left alone
'123'
"""
import re
@ -54,7 +56,7 @@ from stdnum.util import clean
# regular expression for matching ITINs
_itin_re = re.compile('^(?P<area>[0-9]{3})-?(?P<group>[0-9]{2})-?[0-9]{4}$')
_itin_re = re.compile(r'^(?P<area>[0-9]{3})-?(?P<group>[0-9]{2})-?[0-9]{4}$')
# allowed group digits

View file

@ -40,7 +40,7 @@ from stdnum.util import clean
# regular expression for matching PTINs
_ptin_re = re.compile('^P[0-9]{8}$')
_ptin_re = re.compile(r'^P[0-9]{8}$')
def compact(number):

View file

@ -0,0 +1,87 @@
# rtn.py - functions for handling banking routing transit numbers
#
# Copyright (C) 2014 Lifealike Ltd
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA
"""RTN (Routing transport number).
The routing transport number is a nine digit number used in the US banking
system for processing deposits between banks.
The last digit is a checksum.
>>> calc_check_digit('11100002')
'5'
>>> validate('111000025')
'111000025'
>>> validate('11100002') # Not nine digits
Traceback (most recent call last):
...
InvalidLength: ..
>>> validate('11100002B') # Not all numeric
Traceback (most recent call last):
...
InvalidFormat: ..
>>> validate('112000025') # bad checksum
Traceback (most recent call last):
...
InvalidChecksum: ..
"""
from stdnum.exceptions import *
from stdnum.util import clean
def compact(number):
"""Convert the number to the minimal representation. This strips the
number of any surrounding whitespace."""
number = clean(number).strip()
return number
def calc_check_digit(number):
"""Calculate the check digit. The number passed should not have the
check digit included."""
digits = [int(c) for c in number]
checksum = (
7 * (digits[0] + digits[3] + digits[6]) +
3 * (digits[1] + digits[4] + digits[7]) +
9 * (digits[2] + digits[5])
) % 10
return str(checksum)
def validate(number):
"""Checks to see if the number provided is a valid routing number. This
checks the length and check digit."""
number = compact(number)
if not number.isdigit():
raise InvalidFormat()
if len(number) != 9:
raise InvalidLength()
if calc_check_digit(number[:-1]) != number[-1]:
raise InvalidChecksum()
return number
def is_valid(number):
"""Checks to see if the number provided is a valid RTN. This checks the
length and check digit."""
try:
return bool(validate(number))
except ValidationError:
return False

View file

@ -49,7 +49,8 @@ from stdnum.util import clean
# regular expression for matching SSN
_ssn_re = re.compile('^(?P<area>[0-9]{3})-?(?P<group>[0-9]{2})-?(?P<serial>[0-9]{4})$')
_ssn_re = re.compile(
r'^(?P<area>[0-9]{3})-?(?P<group>[0-9]{2})-?(?P<serial>[0-9]{4})$')
# blacklist of SSNs
_ssn_blacklist = set(('078-05-1120', '457-55-5462', '219-09-9999'))