Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjusted ch uid module to also validate stripped numbers without CHE prefix. #437

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions stdnum/ch/uid.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

This module only supports the "new" format that was introduced in 2011 which
completely replaced the "old" 6-digit format in 2014.
Stripped numbers without the CHE prefix are allowed and validated,
but are returned with the prefix prepended.

More information:

Expand All @@ -34,6 +36,8 @@

>>> validate('CHE-100.155.212')
'CHE100155212'
>>> validate('100.155.212')
'CHE100155212'
>>> validate('CHE-100.155.213')
Traceback (most recent call last):
...
Expand Down Expand Up @@ -64,6 +68,8 @@ def validate(number):
"""Check if the number is a valid UID. This checks the length, formatting
and check digit."""
number = compact(number)
if len(number) == 9 and isdigits(number):
number = 'CHE' + number
if len(number) != 12:
raise InvalidLength()
if not number.startswith('CHE'):
Expand Down
Loading