@@ -0,0 +1,2428 @@
+# atin.py - functions for handling  ATINs%0A#%0A# Copyright (C) 2013 Arthur de Jong%0A#%0A# This library is free software; you can redistribute it and/or%0A# modify it under the terms of the GNU Lesser General Public%0A# License as published by the Free Software Foundation; either%0A# version 2.1 of the License, or (at your option) any later version.%0A#%0A# This library is distributed in the hope that it will be useful,%0A# but WITHOUT ANY WARRANTY; without even the implied warranty of%0A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU%0A# Lesser General Public License for more details.%0A#%0A# You should have received a copy of the GNU Lesser General Public%0A# License along with this library; if not, write to the Free Software%0A# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA%0A# 02110-1301 USA%0A%0A%22%22%22ATIN (U.S. Adoption Taxpayer Identification Number).%0A%0AAn Adoption Taxpayer Identification Number (ATIN) is a temporary%0Anine-digit number issued by the United States IRS for a child for whom the%0Aadopting parents cannot obtain a Social Security Number.%0A%0A%3E%3E%3E validate('123-45-6789')%0A'123456789'%0A%3E%3E%3E validate('1234-56789')  # dash in the wrong place%0ATraceback (most recent call last):%0A    ...%0AInvalidFormat: ...%0A%3E%3E%3E format('123456789')%0A'123-45-6789'%0A%22%22%22%0A%0Aimport re%0A%0Afrom stdnum.exceptions import *%0Afrom stdnum.util import clean%0A%0A%0A# regular expression for matching ATINs%0A_atin_re = re.compile('%5E%5B0-9%5D%7B3%7D-?%5B0-9%5D%7B2%7D-?%5B0-9%5D%7B4%7D$')%0A%0A%0Adef compact(number):%0A    %22%22%22Convert the number to the minimal representation. This strips the%0A    number of any valid separators and removes surrounding whitespace.%22%22%22%0A    return clean(number, '-').strip()%0A%0A%0Adef validate(number):%0A    %22%22%22Checks to see if the number provided is a valid ATIN. This checks%0A    the length and formatting if it is present.%22%22%22%0A    match = _atin_re.search(clean(number, '').strip())%0A    if not match:%0A        raise InvalidFormat()%0A    # sadly, no more information on ATIN number validation was found%0A    return compact(number)%0A%0A%0Adef is_valid(number):%0A    %22%22%22Checks to see if the number provided is a valid ATIN. This checks%0A    the length and formatting if it is present.%22%22%22%0A    try:%0A        return bool(validate(number))%0A    except ValidationError:%0A        return False%0A%0A%0Adef format(number):%0A    %22%22%22Reformat the passed number to the standard format.%22%22%22%0A    if len(number) == 9:%0A        number = number%5B:3%5D + '-' + number%5B3:5%5D + '-' + number%5B5:%5D%0A    return number%0A

Add a United States ATIN module