lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.1-11-g0cbba6e

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

python-stdnum branch master updated. 1.1-11-g0cbba6e



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  0cbba6e73ff63ff03407789a7de884fe0edc4b22 (commit)
       via  320326e473da582a4e1e76db279a654f2cf384ad (commit)
       via  37f7fa632ed2d80c0d30af78d17a85ce6c526316 (commit)
       via  db2474654d20f331585b60074ec0a87b755010d0 (commit)
       via  8d309929fb4e198472e74dd4849795c265293b28 (commit)
      from  e107457287328afb8800b521db0939c67c0035af (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=0cbba6e73ff63ff03407789a7de884fe0edc4b22

commit 0cbba6e73ff63ff03407789a7de884fe0edc4b22
Merge: e107457 320326e
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sun Jul 12 15:57:19 2015 +0200

    Merge Finnish numbers provided by Holvi
    
    This merges the Finnish numbers provided by Holvi Payment Services Oy as
    found here: https://github.com/holvi/python-stdnum


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

commit 320326e473da582a4e1e76db279a654f2cf384ad
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sun Jul 12 15:52:05 2015 +0200

    Split out format() function
    
    This uses the stdnum.fi.alv module more extensively and ensures that
    validate() returns a compact representation and a separate format()
    function is available.

diff --git a/stdnum/fi/ytunnus.py b/stdnum/fi/ytunnus.py
index 13acd29..10114eb 100644
--- a/stdnum/fi/ytunnus.py
+++ b/stdnum/fi/ytunnus.py
@@ -2,7 +2,7 @@
 # coding: utf-8
 #
 # Copyright (C) 2015 Holvi Payment Services Oy
-# Copyright (C) 2012, 2013 Arthur de Jong
+# Copyright (C) 2015 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
@@ -19,42 +19,46 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 # 02110-1301 USA
 
-"""Y-tunnus (Finnish business identifier)
+"""Y-tunnus (Finnish business identifier).
 
 The number is an 8-digit code with a weighted checksum.
 
 >>> validate('2077474-0')
-'2077474-0'
+'20774740'
 >>> validate('2077474-1')  # invalid check digit
 Traceback (most recent call last):
     ...
 InvalidChecksum: ...
+>>> format('2077474-0')
+'2077474-0'
 """
 
 from stdnum.exceptions import *
-from stdnum.util import clean
 from stdnum.fi import alv
 
 
 def compact(number):
     """Convert the number to the minimal representation. This strips the
     number of any valid separators and removes surrounding whitespace."""
-    number = clean(number, ' -').upper().strip()
-    return number
+    return alv.compact(number)
 
 
 def validate(number):
-    """Checks to see if the number provided is a valid business identifier. 
This
-    checks the length, formatting and check digit."""
-    number = compact(number)
-    number = alv.validate(number)
-    return "%s-%s" % (number[:7], number[7:])
+    """Checks to see if the number provided is a valid business identifier.
+    This checks the length, formatting and check digit."""
+    return alv.validate(number)
 
 
 def is_valid(number):
-    """Checks to see if the number provided is a valid business identifier. 
This
-    checks the length, formatting and check digit."""
+    """Checks to see if the number provided is a valid business identifier.
+    This checks the length, formatting and check digit."""
     try:
         return bool(validate(number))
     except ValidationError:
         return False
+
+
+def format(number):
+    """Reformat the passed number to the standard format."""
+    number = compact(number)
+    return number[:7] + '-' + number[7:]

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

commit 37f7fa632ed2d80c0d30af78d17a85ce6c526316
Author: Lari Haataja <lari@holvi.com>
Date:   Tue Jun 23 11:29:08 2015 +0200

    Add validation for Finnish y-tunnus (business identifier)

diff --git a/stdnum/fi/__init__.py b/stdnum/fi/__init__.py
index 3bcd521..54f89b9 100644
--- a/stdnum/fi/__init__.py
+++ b/stdnum/fi/__init__.py
@@ -22,3 +22,4 @@
 
 # provide vat as an alias
 from stdnum.fi import alv as vat
+from stdnum.fi import ytunnus as businessid
diff --git a/stdnum/fi/ytunnus.py b/stdnum/fi/ytunnus.py
new file mode 100644
index 0000000..13acd29
--- /dev/null
+++ b/stdnum/fi/ytunnus.py
@@ -0,0 +1,60 @@
+# ytunnus.py - functions for handling Finnish business identifiers (y-tunnus)
+# coding: utf-8
+#
+# Copyright (C) 2015 Holvi Payment Services Oy
+# Copyright (C) 2012, 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
+
+"""Y-tunnus (Finnish business identifier)
+
+The number is an 8-digit code with a weighted checksum.
+
+>>> validate('2077474-0')
+'2077474-0'
+>>> validate('2077474-1')  # invalid check digit
+Traceback (most recent call last):
+    ...
+InvalidChecksum: ...
+"""
+
+from stdnum.exceptions import *
+from stdnum.util import clean
+from stdnum.fi import alv
+
+
+def compact(number):
+    """Convert the number to the minimal representation. This strips the
+    number of any valid separators and removes surrounding whitespace."""
+    number = clean(number, ' -').upper().strip()
+    return number
+
+
+def validate(number):
+    """Checks to see if the number provided is a valid business identifier. 
This
+    checks the length, formatting and check digit."""
+    number = compact(number)
+    number = alv.validate(number)
+    return "%s-%s" % (number[:7], number[7:])
+
+
+def is_valid(number):
+    """Checks to see if the number provided is a valid business identifier. 
This
+    checks the length, formatting and check digit."""
+    try:
+        return bool(validate(number))
+    except ValidationError:
+        return False

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

commit db2474654d20f331585b60074ec0a87b755010d0
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sun Jul 12 15:31:43 2015 +0200

    Add a whitelist for short numbers and fix API
    
    This implements separate functions compact() and format() and fixes the
    doctests. This also implements a whitelist of registered short numbers
    to avoid accidentally validating just any number.

diff --git a/stdnum/fi/associationid.py b/stdnum/fi/associationid.py
index 7796d70..7af46c9 100644
--- a/stdnum/fi/associationid.py
+++ b/stdnum/fi/associationid.py
@@ -2,6 +2,7 @@
 # coding: utf-8
 #
 # Copyright (C) 2015 Holvi Payment Services Oy
+# Copyright (C) 2015 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
@@ -18,34 +19,46 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 # 02110-1301 USA
 
-""" Finnish Association Identifier
+"""Finnish Association Identifier.
 
 The number consists of 1 to 6 digits that are normally separated with a dot
-in groups of 0-3 and 0-3 numbers. E.g. 123.123, 12.123, 1.123, 123 or 1
+in groups of 0-3 and 0-3 numbers. E.g. 123.123, 12.123, 1.123, 123 or 1.
 
->>> businessid.validate('123.123')
-u'123.123'
-
->>> businessid.validate('1123')
-u'1.123'
-
->>> businessid.validate('123123123')
+>>> validate('123.123')
+'123123'
+>>> validate('1123')
+'1123'
+>>> validate('123123123')
 Traceback (most recent call last):
   ...
 stdnum.exceptions.InvalidLength: The number has an invalid length.
-
->>> businessid.validate('12df')
+>>> validate('12df')
 Traceback (most recent call last):
   ...
 stdnum.exceptions.InvalidFormat: The number has an invalid format.
-
+>>> format('123')
+'123'
+>>> format('1234')
+'1.234'
 """
 
-import re
 from stdnum.exceptions import *
 from stdnum.util import clean
 
 
+# a collection of all registered numbers with 2 or less digits
+_lownumbers = set((
+    1, 6, 7, 9, 12, 14, 15, 16, 18, 22, 23, 24, 27, 28, 29, 35, 36, 38, 40,
+    41, 42, 43, 45, 46, 50, 52, 55, 58, 60, 64, 65, 68, 72, 75, 76, 77, 78,
+    83, 84, 85, 89, 92))
+
+
+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):
     """
     Validate the format of a Finnish association register number.
@@ -53,24 +66,29 @@ def validate(number):
     First strip all separators and spaces from the number and then checks
     that it has a correct length and is only numeric.
     """
-    number = clean(number, ' -._+').strip()
-
+    number = compact(number)
     if not number.isdigit():
         raise InvalidFormat()
-
     if len(number) < 1 or len(number) > 6:
         raise InvalidLength()
-
-    if len(number) < 4:
-        return number
-    else:
-        return "%s.%s" % (number[:-3], number[-3:])
+    if len(number) < 3 and int(number) not in _lownumbers:
+        raise InvalidComponent()
+    return number
 
 
 def is_valid(number):
-    """Checks to see if the number provided is a valid association register 
number.
-    This checks that the format is correct."""
+    """Checks to see if the number provided is a valid association register
+    number. This checks that the format is correct."""
     try:
         return bool(validate(number))
     except ValidationError:
         return False
+
+
+def format(number):
+    """Reformat the passed number to the standard format."""
+    number = compact(number)
+    if len(number) <= 3:
+        return number
+    else:
+        return number[:-3] + '.' + number[-3:]

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

commit 8d309929fb4e198472e74dd4849795c265293b28
Author: Lari Haataja <lari@holvi.com>
Date:   Tue Jun 16 16:18:56 2015 +0300

    Validation for Finnish association identifier

diff --git a/stdnum/fi/associationid.py b/stdnum/fi/associationid.py
new file mode 100644
index 0000000..7796d70
--- /dev/null
+++ b/stdnum/fi/associationid.py
@@ -0,0 +1,76 @@
+# associationid.py - functions for handling Finnish association registry id
+# coding: utf-8
+#
+# Copyright (C) 2015 Holvi Payment Services Oy
+#
+# 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
+
+""" Finnish Association Identifier
+
+The number consists of 1 to 6 digits that are normally separated with a dot
+in groups of 0-3 and 0-3 numbers. E.g. 123.123, 12.123, 1.123, 123 or 1
+
+>>> businessid.validate('123.123')
+u'123.123'
+
+>>> businessid.validate('1123')
+u'1.123'
+
+>>> businessid.validate('123123123')
+Traceback (most recent call last):
+  ...
+stdnum.exceptions.InvalidLength: The number has an invalid length.
+
+>>> businessid.validate('12df')
+Traceback (most recent call last):
+  ...
+stdnum.exceptions.InvalidFormat: The number has an invalid format.
+
+"""
+
+import re
+from stdnum.exceptions import *
+from stdnum.util import clean
+
+
+def validate(number):
+    """
+    Validate the format of a Finnish association register number.
+
+    First strip all separators and spaces from the number and then checks
+    that it has a correct length and is only numeric.
+    """
+    number = clean(number, ' -._+').strip()
+
+    if not number.isdigit():
+        raise InvalidFormat()
+
+    if len(number) < 1 or len(number) > 6:
+        raise InvalidLength()
+
+    if len(number) < 4:
+        return number
+    else:
+        return "%s.%s" % (number[:-3], number[-3:])
+
+
+def is_valid(number):
+    """Checks to see if the number provided is a valid association register 
number.
+    This checks that the format is correct."""
+    try:
+        return bool(validate(number))
+    except ValidationError:
+        return False

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

Summary of changes:
 stdnum/fi/__init__.py                 |    1 +
 stdnum/fi/associationid.py            |   94 +++++++++++++++++++++++++++++++++
 stdnum/{no/orgnr.py => fi/ytunnus.py} |   45 ++++++----------
 3 files changed, 110 insertions(+), 30 deletions(-)
 create mode 100644 stdnum/fi/associationid.py
 copy stdnum/{no/orgnr.py => fi/ytunnus.py} (57%)


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/