lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 0.8.1-8-g188d3ea

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-stdnum branch master updated. 0.8.1-8-g188d3ea



This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "python-stdnum".

The branch, master has been updated
       via  188d3eac0f043de8d06ec260a691ef76973b7d9b (commit)
       via  95306354539a7b66bc1e78f982a3195e7414eb03 (commit)
       via  316e3f29dcb38e18273cd123924a36e4302e7740 (commit)
       via  47ea6eab0d224f80caad1cf2bc0cec7081562b52 (commit)
       via  b1c9ba511288484f0b6b531dce8883a23f2dce7b (commit)
       via  19039f7c1467bd7fbc7be8b527d57db1395ff145 (commit)
       via  70b974b2a0c217fcb5addd6ea00d420e34ddc538 (commit)
      from  f122c882ba969846c94dc492016c9d7ef1085266 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://arthurdejong.org/git/python-stdnum/commit/?id=188d3eac0f043de8d06ec260a691ef76973b7d9b

commit 188d3eac0f043de8d06ec260a691ef76973b7d9b
Merge: 70b974b 9530635
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sat Nov 9 15:51:50 2013 +0100

    Add various United States Tax number modules
    
    This adds modules for the Individual Taxpayer Identification Number
    (ITIN), the Employer Identification Number (EIN), Adoption Taxpayer
    Identification Number (ATIN) and Preparer Tax Identification Number
    (PTIN) that together with the Social Security Number (SSN) are valid
    Taxpayer Identification Numbers (TIN)


http://arthurdejong.org/git/python-stdnum/commit/?id=95306354539a7b66bc1e78f982a3195e7414eb03

commit 95306354539a7b66bc1e78f982a3195e7414eb03
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sat Oct 12 16:04:31 2013 +0200

    Add a United States TIN module
    
    The Taxpayer Identification Number is used used for tax purposes in the
    United States. This module uses the SSN, ITIN, EIN, PTIN and ATIN
    modules to determine validitiy of the TIN.

diff --git a/stdnum/us/tin.py b/stdnum/us/tin.py
new file mode 100644
index 0000000..bdac205
--- /dev/null
+++ b/stdnum/us/tin.py
@@ -0,0 +1,97 @@
+# tin.py - functions for handling TINs
+#
+# Copyright (C) 2013 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
+# 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
+
+"""TIN (U.S. Taxpayer Identification Number).
+
+The Taxpayer Identification Number is used used for tax purposes in the
+United States. A TIN may be:
+* a Social Security Number (SSN)
+* an Individual Taxpayer Identification Number (ITIN)
+* an Employer Identification Number (EIN)
+* a Preparer Tax Identification Number (PTIN)
+* an Adoption Taxpayer Identification Number (ATIN)
+
+>>> compact('123-45-6789')
+'123456789'
+>>> validate('123-45-6789')
+'123456789'
+>>> validate('07-3456789')
+Traceback (most recent call last):
+    ...
+InvalidFormat: ...
+>>> guess_type('536-90-4399')
+['ssn', 'atin']
+>>> guess_type('04-2103594')
+['ein']
+>>> guess_type('042103594')
+['ssn', 'ein', 'atin']
+>>> format('042103594')
+'042-10-3594'
+>>> format('123-456')  # invalid numbers are not reformatted
+'123-456'
+"""
+
+from stdnum.exceptions import *
+from stdnum.us import ssn, itin, ein, ptin, atin
+from stdnum.util import clean
+
+_tin_modules = (ssn, itin, ein, ptin, atin)
+
+
+def compact(number):
+    """Convert the number to the minimal representation. This strips the
+    number of any valid separators and removes surrounding whitespace."""
+    return clean(number, '-').strip()
+
+
+def validate(number):
+    """Checks to see if the number provided is a valid TIN. This searches
+    for the proper sub-type and validates using that."""
+    for mod in _tin_modules:
+        try:
+            return mod.validate(number)
+        except ValidationError:
+            pass  # try next module
+    # fallback
+    raise InvalidFormat()
+
+
+def is_valid(number):
+    """Checks to see if the number provided is a valid TIN. This searches
+    for the proper sub-type and validates using that."""
+    try:
+        return bool(validate(number))
+    except ValidationError:
+        return False
+
+
+def guess_type(number):
+    """Return a list of possible TIN types for which this number is
+    valid.."""
+    return [mod.__name__.rsplit('.', 1)[-1]
+            for mod in _tin_modules
+            if mod.is_valid(number)]
+
+
+def format(number):
+    """Reformat the passed number to the standard format."""
+    for mod in _tin_modules:
+        if mod.is_valid(number) and hasattr(mod, 'format'):
+            return mod.format(number)
+    return number

http://arthurdejong.org/git/python-stdnum/commit/?id=316e3f29dcb38e18273cd123924a36e4302e7740

commit 316e3f29dcb38e18273cd123924a36e4302e7740
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Fri Oct 11 23:56:48 2013 +0200

    Add a United States PTIN module
    
    A Preparer Tax Identification Number (PTIN) is United States
    identification number for tax return preparers. It is an eight-digit
    number prefixed with a capital P.

diff --git a/stdnum/us/ptin.py b/stdnum/us/ptin.py
new file mode 100644
index 0000000..48ee2c4
--- /dev/null
+++ b/stdnum/us/ptin.py
@@ -0,0 +1,68 @@
+# ptin.py - functions for handling  PTINs
+#
+# Copyright (C) 2013 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
+# 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
+
+"""PTIN (U.S. Preparer Tax Identification Number).
+
+A Preparer Tax Identification Number (PTIN) is United States
+identification number for tax return preparers. It is an eight-digit
+number prefixed with a capital P.
+
+>>> validate('P-00634642')
+'P00634642'
+>>> validate('P01594846')
+'P01594846'
+>>> validate('00634642')  # missing P
+Traceback (most recent call last):
+    ...
+InvalidFormat: ...
+"""
+
+import re
+
+from stdnum.exceptions import *
+from stdnum.util import clean
+
+
+# regular expression for matching PTINs
+_ptin_re = re.compile('^P[0-9]{8}$')
+
+
+def compact(number):
+    """Convert the number to the minimal representation. This strips the
+    number of any valid separators and removes surrounding whitespace."""
+    return clean(number, '-').strip()
+
+
+def validate(number):
+    """Checks to see if the number provided is a valid PTIN. This checks
+    the length, groups and formatting if it is present."""
+    number = compact(number).upper()
+    if not _ptin_re.search(number):
+        raise InvalidFormat()
+    # sadly, no more information on PTIN number validation was found
+    return number
+
+
+def is_valid(number):
+    """Checks to see if the number provided is a valid ATIN. This checks
+    the length, groups and formatting if it is present."""
+    try:
+        return bool(validate(number))
+    except ValidationError:
+        return False

http://arthurdejong.org/git/python-stdnum/commit/?id=47ea6eab0d224f80caad1cf2bc0cec7081562b52

commit 47ea6eab0d224f80caad1cf2bc0cec7081562b52
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Fri Oct 11 23:23:53 2013 +0200

    Add a United States ATIN module
    
    An Adoption Taxpayer Identification Number (ATIN) is a temporary
    nine-digit number issued by the United States IRS for a child for whom
    the adopting parents cannot obtain a Social Security Number.

diff --git a/stdnum/us/atin.py b/stdnum/us/atin.py
new file mode 100644
index 0000000..b3218db
--- /dev/null
+++ b/stdnum/us/atin.py
@@ -0,0 +1,75 @@
+# atin.py - functions for handling  ATINs
+#
+# Copyright (C) 2013 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
+# 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
+
+"""ATIN (U.S. Adoption Taxpayer Identification Number).
+
+An Adoption Taxpayer Identification Number (ATIN) is a temporary
+nine-digit number issued by the United States IRS for a child for whom the
+adopting parents cannot obtain a Social Security Number.
+
+>>> validate('123-45-6789')
+'123456789'
+>>> validate('1234-56789')  # dash in the wrong place
+Traceback (most recent call last):
+    ...
+InvalidFormat: ...
+>>> format('123456789')
+'123-45-6789'
+"""
+
+import re
+
+from stdnum.exceptions import *
+from stdnum.util import clean
+
+
+# regular expression for matching ATINs
+_atin_re = re.compile('^[0-9]{3}-?[0-9]{2}-?[0-9]{4}$')
+
+
+def compact(number):
+    """Convert the number to the minimal representation. This strips the
+    number of any valid separators and removes surrounding whitespace."""
+    return clean(number, '-').strip()
+
+
+def validate(number):
+    """Checks to see if the number provided is a valid ATIN. This checks
+    the length and formatting if it is present."""
+    match = _atin_re.search(clean(number, '').strip())
+    if not match:
+        raise InvalidFormat()
+    # sadly, no more information on ATIN number validation was found
+    return compact(number)
+
+
+def is_valid(number):
+    """Checks to see if the number provided is a valid ATIN. This checks
+    the length and formatting if it is present."""
+    try:
+        return bool(validate(number))
+    except ValidationError:
+        return False
+
+
+def format(number):
+    """Reformat the passed number to the standard format."""
+    if len(number) == 9:
+        number = number[:3] + '-' + number[3:5] + '-' + number[5:]
+    return number

http://arthurdejong.org/git/python-stdnum/commit/?id=b1c9ba511288484f0b6b531dce8883a23f2dce7b

commit b1c9ba511288484f0b6b531dce8883a23f2dce7b
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Fri Oct 11 22:50:46 2013 +0200

    Add a United States EIN module
    
    The Employer Identification Number (EIN), also known as Federal Employer
    Identification Number (FEIN), is used to identify a business entity in
    the United States. It is issued to anyone that has to pay withholding
    taxes on employees.

diff --git a/stdnum/us/ein.dat b/stdnum/us/ein.dat
new file mode 100644
index 0000000..e1a8e03
--- /dev/null
+++ b/stdnum/us/ein.dat
@@ -0,0 +1,15 @@
+# manually converted from the IRS website
+# 
http://www.irs.gov/Businesses/Small-Businesses-&-Self-Employed/How-EINs-are-Assigned-and-Valid-EIN-Prefixes
+
+01,02,03,04,05,06,11,13,14,16,21,22,23,25,34,51,52,54,55,56,57,58,59,65 
campus="Brookhaven"
+10,12 campus="Andover"
+15,24 campus="Fresno"
+20,26,27,45,46 campus="Internet"
+30,32,35,36,37,38,61 campus="Cincinnati"
+31 campus="Small Business Administration (SBA)"
+33,39,41,42,43,46,48,62,63,64,66,68,71,72,73,74,75,76,77,81,82,83,84,85,86,87,88,91,92,93,98,99
 campus="Philadelphia"
+40,44 campus="Kansas City"
+50,53 campus="Austin"
+60,67 campus="Atlanta"
+80,90 campus="Ogden"
+94,95 campus="Memphis"
diff --git a/stdnum/us/ein.py b/stdnum/us/ein.py
new file mode 100644
index 0000000..ea63b9a
--- /dev/null
+++ b/stdnum/us/ein.py
@@ -0,0 +1,92 @@
+# ein.py - functions for handling EINs
+#
+# Copyright (C) 2013 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
+# 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
+
+"""EIN (U.S. Employer Identification Number).
+
+The Employer Identification Number, also known as Federal Employer
+Identification Number (FEIN), is used to identify a business entity in the
+United States. It is issued to anyone that has to pay withholding taxes on
+employees.
+
+>>> validate('91-1144442')
+'911144442'
+>>> get_campus('04-2103594') == 'Brookhaven'
+True
+>>> validate('911-14-4442')  # dash in the wrong place
+Traceback (most recent call last):
+    ...
+InvalidFormat: ...
+>>> validate('07-1144442')  # wrong prefix
+Traceback (most recent call last):
+    ...
+InvalidComponent: ...
+>>> format('042103594')
+'04-2103594'
+"""
+
+import re
+
+from stdnum.exceptions import *
+from stdnum.util import clean
+
+
+# regular expression for matching EINs
+_ein_re = re.compile('^(?P<area>[0-9]{2})-?(?P<group>[0-9]{7})$')
+
+
+def compact(number):
+    """Convert the number to the minimal representation. This strips the
+    number of any valid separators and removes surrounding whitespace."""
+    return clean(number, '-').strip()
+
+
+def get_campus(number):
+    """Determine the Campus or other location that issued the EIN."""
+    from stdnum import numdb
+    number = compact(number)
+    results = numdb.get('us/ein').info(number)[0][1]
+    if not results:
+        raise InvalidComponent()
+    return results['campus']
+
+
+def validate(number):
+    """Checks to see if the number provided is a valid EIN. This checks
+    the length, groups and formatting if it is present."""
+    match = _ein_re.search(clean(number, '').strip())
+    if not match:
+        raise InvalidFormat()
+    get_campus(number)  # raises exception for unknown campus
+    return compact(number)
+
+
+def is_valid(number):
+    """Checks to see if the number provided is a valid EIN. This checks
+    the length, groups and formatting if it is present."""
+    try:
+        return bool(validate(number))
+    except ValidationError:
+        return False
+
+
+def format(number):
+    """Reformat the passed number to the standard format."""
+    if len(number) == 9:
+        number = number[:2] + '-' + number[2:]
+    return number

http://arthurdejong.org/git/python-stdnum/commit/?id=19039f7c1467bd7fbc7be8b527d57db1395ff145

commit 19039f7c1467bd7fbc7be8b527d57db1395ff145
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Fri Oct 11 22:07:36 2013 +0200

    Add a United States ITIN module
    
    The ITIN (Individual Taxpayer Identification Number) is issued by the
    United States IRS to individuals who are required to have a taxpayer
    identification number but who are not eligible to obtain a Social
    Security Number.

diff --git a/stdnum/us/itin.py b/stdnum/us/itin.py
new file mode 100644
index 0000000..bde97b7
--- /dev/null
+++ b/stdnum/us/itin.py
@@ -0,0 +1,96 @@
+# itin.py - functions for handling ITINs
+#
+# Copyright (C) 2013 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
+# 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
+
+"""ITIN (U.S. Individual Taxpayer Identification Number).
+
+The Individual Taxpayer Identification Number is issued by the United
+States IRS to individuals who are required to have a taxpayer
+identification number but who are not eligible to obtain a Social Security
+Number.
+
+It is a nine-digit number that begins with the number 9 and the
+fourth and fifth digit are expected to be in a certain range.
+
+>>> validate('912-90-3456')
+'912903456'
+>>> validate('9129-03456')  # dash in the wrong place
+Traceback (most recent call last):
+    ...
+InvalidFormat: ...
+>>> validate('123-45-6789')  # wrong start digit
+Traceback (most recent call last):
+    ...
+InvalidComponent: ...
+>>> validate('912-93-4567')  # wrong group
+Traceback (most recent call last):
+    ...
+InvalidComponent: ...
+>>> compact('1234-56-789')
+'123456789'
+>>> format('111223333')
+'111-22-3333'
+"""
+
+import re
+
+from stdnum.exceptions import *
+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}$')
+
+
+# allowed group digits
+_allowed_groups = set((str(x) for x in range(70, 100) if x not in (89, 93)))
+
+
+def compact(number):
+    """Convert the number to the minimal representation. This strips the
+    number of any valid separators and removes surrounding whitespace."""
+    return clean(number, '-').strip()
+
+
+def validate(number):
+    """Checks to see if the number provided is a valid ITIN. This checks
+    the length, groups and formatting if it is present."""
+    match = _itin_re.search(clean(number, '').strip())
+    if not match:
+        raise InvalidFormat()
+    area = match.group('area')
+    group = match.group('group')
+    if area[0] != '9' or group not in _allowed_groups:
+        raise InvalidComponent()
+    return compact(number)
+
+
+def is_valid(number):
+    """Checks to see if the number provided is a valid ITIN. This checks
+    the length, groups and formatting if it is present."""
+    try:
+        return bool(validate(number))
+    except ValidationError:
+        return False
+
+
+def format(number):
+    """Reformat the passed number to the standard format."""
+    if len(number) == 9:
+        number = number[:3] + '-' + number[3:5] + '-' + number[5:]
+    return number

http://arthurdejong.org/git/python-stdnum/commit/?id=70b974b2a0c217fcb5addd6ea00d420e34ddc538

commit 70b974b2a0c217fcb5addd6ea00d420e34ddc538
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Fri Oct 11 17:05:02 2013 +0200

    Remove unused import

diff --git a/stdnum/meid.py b/stdnum/meid.py
index 2ae8488..cd203de 100644
--- a/stdnum/meid.py
+++ b/stdnum/meid.py
@@ -173,7 +173,6 @@ def to_binary(number):
     """Convert the number to it's binary representation (without the check
     digit)."""
     import sys
-    import binascii
     number = compact(number, strip_check_digit=True)
     if sys.version > '3':  # pragma: no cover (Python 2/3 specific code)
         return bytes.fromhex(number)

-----------------------------------------------------------------------

Summary of changes:
 stdnum/meid.py                   |    1 -
 stdnum/{be/vat.py => us/atin.py} |   70 +++++++++++++--------------
 stdnum/us/ein.dat                |   15 ++++++
 stdnum/us/{ssn.py => ein.py}     |   69 +++++++++++++--------------
 stdnum/us/{ssn.py => itin.py}    |   49 ++++++++++---------
 stdnum/{de/vat.py => us/ptin.py} |   51 ++++++++++----------
 stdnum/us/tin.py                 |   97 ++++++++++++++++++++++++++++++++++++++
 7 files changed, 229 insertions(+), 123 deletions(-)
 copy stdnum/{be/vat.py => us/atin.py} (50%)
 create mode 100644 stdnum/us/ein.dat
 copy stdnum/us/{ssn.py => ein.py} (54%)
 copy stdnum/us/{ssn.py => itin.py} (62%)
 copy stdnum/{de/vat.py => us/ptin.py} (55%)
 create mode 100644 stdnum/us/tin.py


hooks/post-receive
-- 
python-stdnum
-- 
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/python-stdnum-commits/