lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 0.9-24-g256aa49

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

python-stdnum branch master updated. 0.9-24-g256aa49



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  256aa49be625314bc7837df22b3a70d32269e088 (commit)
       via  2cc50e2e561613b9a0814fbd048b003cf03cce10 (commit)
      from  e2948bb6bd0ebf7b3828ac989a56d0e61982c545 (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=256aa49be625314bc7837df22b3a70d32269e088

commit 256aa49be625314bc7837df22b3a70d32269e088
Author: Denis Krienb├╝hl <denis@href.ch>
Date:   Mon Oct 13 16:15:03 2014 +0200

    Adds the Swiss social security number
    
    Also known as "Sozialversicherungsnummer" / "Neue AHV Nummer".

diff --git a/stdnum/ch/__init__.py b/stdnum/ch/__init__.py
new file mode 100644
index 0000000..cea3564
--- /dev/null
+++ b/stdnum/ch/__init__.py
@@ -0,0 +1,21 @@
+# __init__.py - collection of Swiss numbers
+# coding: utf-8
+#
+# Copyright (C) 2014 Denis Krienbuehl
+#
+# 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
+
+"""Collection of Swiss numbers."""
diff --git a/stdnum/ch/ssn.py b/stdnum/ch/ssn.py
new file mode 100644
index 0000000..548ffa1
--- /dev/null
+++ b/stdnum/ch/ssn.py
@@ -0,0 +1,72 @@
+# vat.py - functions for handling Swiss social security numbers
+#
+# Copyright (C) 2014 Denis Krienbuehl
+#
+# 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
+
+"""Swiss social security number ("Sozialversicherungsnummer").
+
+Also known as "Neue AHV Nummer".
+
+The Swiss Sozialversicherungsnummer is used to identify indivduals for taxation
+and pension purposes.
+
+The number is validated using EAN-13, though dashes are substitued for dots.
+
+>>> compact('756.9217.0769.85')
+'7569217076985'
+>>> format('7569217076985')
+'756.9217.0769.85'
+>>> validate('7569217076985')
+'7569217076985'
+>>> validate('756.9217.0769.85')
+'7569217076985'
+>>> validate('756.9217.0769.84')
+Traceback (most recent call last):
+    ...
+InvalidChecksum: ...
+"""
+
+from stdnum.exceptions import ValidationError
+from stdnum import ean
+from stdnum.util import clean
+
+
+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 format(number):
+    """Reformat the passed number to the standard format."""
+    number = compact(number)
+    return '.'.join((number[:3], number[3:7], number[7:11], number[11:]))
+
+
+def validate(number):
+    """Checks to see if the number provided is a valid
+    Swiss Sozialversicherungsnummer."""
+    return ean.validate(compact(number))
+
+
+def is_valid(number):
+    """Checks to see if the number provided is a valid
+    Sozialversicherungsnummer."""
+    try:
+        return bool(validate(number))
+    except ValidationError:
+        return False

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

commit 2cc50e2e561613b9a0814fbd048b003cf03cce10
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sat Oct 18 12:47:27 2014 +0200

    Only catch Exception

diff --git a/stdnum/eu/at_02.py b/stdnum/eu/at_02.py
index dc1fa18..d436308 100644
--- a/stdnum/eu/at_02.py
+++ b/stdnum/eu/at_02.py
@@ -61,7 +61,7 @@ def validate(number):
     number = compact(number)
     try:
         test_number = _to_base10(number)
-    except:
+    except Exception:
         raise InvalidFormat()
     # ensure that checksum is valid
     mod_97_10.validate(test_number)
diff --git a/stdnum/iban.py b/stdnum/iban.py
index bab80b9..fe3b093 100644
--- a/stdnum/iban.py
+++ b/stdnum/iban.py
@@ -87,7 +87,7 @@ def validate(number):
     number = compact(number)
     try:
         test_number = _to_base10(number)
-    except:
+    except Exception:
         raise InvalidFormat()
     # ensure that checksum is valid
     mod_97_10.validate(test_number)
diff --git a/stdnum/imei.py b/stdnum/imei.py
index 33d38c5..1fad6c3 100644
--- a/stdnum/imei.py
+++ b/stdnum/imei.py
@@ -72,7 +72,7 @@ def imei_type(number):
     invalid) for checking the type of number passed."""
     try:
         number = validate(number)
-    except:
+    except Exception:
         return None
     if len(number) in (14, 15):
         return 'IMEI'
diff --git a/stdnum/iso7064/mod_11_10.py b/stdnum/iso7064/mod_11_10.py
index 4b691ff..690682b 100644
--- a/stdnum/iso7064/mod_11_10.py
+++ b/stdnum/iso7064/mod_11_10.py
@@ -56,7 +56,7 @@ def validate(number):
     """Checks whether the check digit is valid."""
     try:
         valid = checksum(number) == 1
-    except:
+    except Exception:
         raise InvalidFormat()
     if not valid:
         raise InvalidChecksum()
diff --git a/stdnum/iso7064/mod_11_2.py b/stdnum/iso7064/mod_11_2.py
index 69a1595..9d7c253 100644
--- a/stdnum/iso7064/mod_11_2.py
+++ b/stdnum/iso7064/mod_11_2.py
@@ -59,7 +59,7 @@ def validate(number):
     """Checks whether the check digit is valid."""
     try:
         valid = checksum(number) == 1
-    except:
+    except Exception:
         raise InvalidFormat()
     if not valid:
         raise InvalidChecksum()
diff --git a/stdnum/iso7064/mod_37_2.py b/stdnum/iso7064/mod_37_2.py
index ecdf125..ece48cb 100644
--- a/stdnum/iso7064/mod_37_2.py
+++ b/stdnum/iso7064/mod_37_2.py
@@ -63,7 +63,7 @@ def validate(number, 
alphabet='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*'):
     """Checks whether the check digit is valid."""
     try:
         valid = checksum(number, alphabet) == 1
-    except:
+    except Exception:
         raise InvalidFormat()
     if not valid:
         raise InvalidChecksum()
diff --git a/stdnum/iso7064/mod_37_36.py b/stdnum/iso7064/mod_37_36.py
index 6a153e0..0787e5a 100644
--- a/stdnum/iso7064/mod_37_36.py
+++ b/stdnum/iso7064/mod_37_36.py
@@ -61,7 +61,7 @@ def validate(number, 
alphabet='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'):
     """Checks whether the check digit is valid."""
     try:
         valid = checksum(number, alphabet) == 1
-    except:
+    except Exception:
         raise InvalidFormat()
     if not valid:
         raise InvalidChecksum()
diff --git a/stdnum/iso7064/mod_97_10.py b/stdnum/iso7064/mod_97_10.py
index 8696d3c..618fbc7 100644
--- a/stdnum/iso7064/mod_97_10.py
+++ b/stdnum/iso7064/mod_97_10.py
@@ -52,7 +52,7 @@ def validate(number):
     """Checks whether the check digit is valid."""
     try:
         valid = checksum(number) == 1
-    except:
+    except Exception:
         raise InvalidFormat()
     if not valid:
         raise InvalidChecksum()
diff --git a/stdnum/luhn.py b/stdnum/luhn.py
index bc1b5ac..5a11a0d 100644
--- a/stdnum/luhn.py
+++ b/stdnum/luhn.py
@@ -64,7 +64,7 @@ def validate(number, alphabet='0123456789'):
         raise InvalidFormat()
     try:
         valid = checksum(number, alphabet) == 0
-    except:
+    except Exception:
         raise InvalidFormat()
     if not valid:
         raise InvalidChecksum()
diff --git a/stdnum/util.py b/stdnum/util.py
index a832f42..420d363 100644
--- a/stdnum/util.py
+++ b/stdnum/util.py
@@ -106,7 +106,7 @@ def clean(number, deletechars=''):
     """
     try:
         number = ''.join(x for x in number)
-    except:
+    except Exception:
         raise InvalidFormat()
     if sys.version < '3' and isinstance(number, str):  # pragma: no cover 
(Python 2/3 specific code)
         try:
diff --git a/stdnum/verhoeff.py b/stdnum/verhoeff.py
index 4fb9315..00037e0 100644
--- a/stdnum/verhoeff.py
+++ b/stdnum/verhoeff.py
@@ -81,7 +81,7 @@ def validate(number):
         raise InvalidFormat()
     try:
         valid = checksum(number) == 0
-    except:
+    except Exception:
         raise InvalidFormat()
     if not valid:
         raise InvalidChecksum()

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

Summary of changes:
 stdnum/{gr => ch}/__init__.py   |    6 ++--
 stdnum/{fi/alv.py => ch/ssn.py} |   59 ++++++++++++++++++++-------------------
 stdnum/eu/at_02.py              |    2 +-
 stdnum/iban.py                  |    2 +-
 stdnum/imei.py                  |    2 +-
 stdnum/iso7064/mod_11_10.py     |    2 +-
 stdnum/iso7064/mod_11_2.py      |    2 +-
 stdnum/iso7064/mod_37_2.py      |    2 +-
 stdnum/iso7064/mod_37_36.py     |    2 +-
 stdnum/iso7064/mod_97_10.py     |    2 +-
 stdnum/luhn.py                  |    2 +-
 stdnum/util.py                  |    2 +-
 stdnum/verhoeff.py              |    2 +-
 13 files changed, 44 insertions(+), 43 deletions(-)
 copy stdnum/{gr => ch}/__init__.py (86%)
 copy stdnum/{fi/alv.py => ch/ssn.py} (51%)


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/