|
1 | 1 | # uid.py - functions for handling Swiss business identifiers
|
2 | 2 | # coding: utf-8
|
3 | 3 | #
|
4 |
| -# Copyright (C) 2015 Arthur de Jong |
| 4 | +# Copyright (C) 2015-2022 Arthur de Jong |
5 | 5 | #
|
6 | 6 | # This library is free software; you can redistribute it and/or
|
7 | 7 | # modify it under the terms of the GNU Lesser General Public
|
|
43 | 43 | """
|
44 | 44 |
|
45 | 45 | from stdnum.exceptions import *
|
46 |
| -from stdnum.util import clean, isdigits |
| 46 | +from stdnum.util import clean, get_soap_client, isdigits |
47 | 47 |
|
48 | 48 |
|
49 | 49 | def compact(number):
|
@@ -88,3 +88,60 @@ def format(number):
|
88 | 88 | number = compact(number)
|
89 | 89 | return number[:3] + '-' + '.'.join(
|
90 | 90 | number[i:i + 3] for i in range(3, len(number), 3))
|
| 91 | + |
| 92 | + |
| 93 | +uid_wsdl = 'https://www.uid-wse.admin.ch/V5.0/PublicServices.svc?wsdl' |
| 94 | + |
| 95 | + |
| 96 | +def check_uid(number, timeout=30): # pragma: no cover |
| 97 | + """Look up information via the Swiss Federal Statistical Office web service. |
| 98 | +
|
| 99 | + This uses the UID registry web service run by the the Swiss Federal |
| 100 | + Statistical Office to provide more details on the provided number. |
| 101 | +
|
| 102 | + Returns a dict-like object for valid numbers with the following structure:: |
| 103 | +
|
| 104 | + { |
| 105 | + 'organisation': { |
| 106 | + 'organisationIdentification': { |
| 107 | + 'uid': {'uidOrganisationIdCategorie': 'CHE', 'uidOrganisationId': 113690319}, |
| 108 | + 'OtherOrganisationId': [ |
| 109 | + {'organisationIdCategory': 'CH.ESTVID', 'organisationId': '052.0111.1006'}, |
| 110 | + ], |
| 111 | + 'organisationName': 'Staatssekretariat für Migration SEM Vermietung von Parkplätzen', |
| 112 | + 'legalForm': '0220', |
| 113 | + }, |
| 114 | + 'address': [ |
| 115 | + { |
| 116 | + 'addressCategory': 'LEGAL', |
| 117 | + 'street': 'Quellenweg', |
| 118 | + 'houseNumber': '6', |
| 119 | + 'town': 'Wabern', |
| 120 | + 'countryIdISO2': 'CH', |
| 121 | + }, |
| 122 | + ], |
| 123 | + }, |
| 124 | + 'uidregInformation': { |
| 125 | + 'uidregStatusEnterpriseDetail': '3', |
| 126 | + ... |
| 127 | + }, |
| 128 | + 'vatRegisterInformation': { |
| 129 | + 'vatStatus': '2', |
| 130 | + 'vatEntryStatus': '1', |
| 131 | + ... |
| 132 | + }, |
| 133 | + } |
| 134 | +
|
| 135 | + See the following document for more details on the GetByUID return value |
| 136 | + https://www.bfs.admin.ch/bfs/en/home/registers/enterprise-register/enterprise-identification/uid-register/uid-interfaces.html |
| 137 | + """ |
| 138 | + # this function isn't always tested because it would require network access |
| 139 | + # for the tests and might unnecessarily load the web service |
| 140 | + number = compact(number) |
| 141 | + client = get_soap_client(uid_wsdl, timeout) |
| 142 | + try: |
| 143 | + return client.GetByUID(uid={'uidOrganisationIdCategorie': number[:3], 'uidOrganisationId': number[3:]})[0] |
| 144 | + except Exception: # noqa: B902 (excpetion type depends on SOAP client) |
| 145 | + # Error responses by the server seem to result in exceptions raised |
| 146 | + # by the SOAP client implementation |
| 147 | + return |
0 commit comments