8000 Adjust Swiss uid module to accept numbers without CHE prefix · Daverball/python-stdnum@1da003f · GitHub
[go: up one dir, main page]

Skip to content

Commit 1da003f

Browse files
jeffh92arthurdejong
authored andcommitted
Adjust Swiss uid module to accept numbers without CHE prefix
Closes arthurdejong#437 Closes arthurdejong#423
1 parent 91959bd commit 1da003f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

stdnum/ch/uid.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
2727
This module only supports the "new" format that was introduced in 2011 which
2828
completely replaced the "old" 6-digit format in 2014.
29+
Stripped numbers without the CHE prefix are allowed and validated,
30+
but are returned with the prefix prepended.
2931
3032
More information:
3133
@@ -34,6 +36,8 @@
3436
3537
>>> validate('CHE-100.155.212')
3638
'CHE100155212'
39+
>>> validate('100.155.212')
40+
'CHE100155212'
3741
>>> validate('CHE-100.155.213')
3842
Traceback (most recent call last):
3943
...
@@ -49,7 +53,10 @@
4953
def compact(number):
5054
"""Convert the number to the minimal representation. This strips
5155
surrounding whitespace and separators."""
52-
return clean(number, ' -.').strip().upper()
56+
number = clean(number, ' -.').strip().upper()
57+
if len(number) == 9 and isdigits(number):
58+
numbe 4C8B r = 'CHE' + number
59+
return number
5360

5461

5562
def calc_check_digit(number):

0 commit comments

Comments
 (0)
0