diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2012-09-22 17:40:03 +0200 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2012-09-22 17:40:03 +0200 |
commit | 3f6d52a1aa5489484a83833dc194ad9ed380bf65 (patch) | |
tree | 5ac01c1c1017a3addb6330eacabfbc390bf3ba2a | |
parent | af7e837890541ef2215909b57f88a5e806a4dc45 (diff) |
generate part of the stdnum docstring based on introspection of the modules
git-svn-id: http://arthurdejong.org/svn/python-stdnum/python-stdnum@176 9dea7c4f-944c-4273-ac1a-574ede026edc
-rw-r--r-- | stdnum/__init__.py | 72 | ||||
-rw-r--r-- | stdnum/util.py | 25 |
2 files changed, 33 insertions, 64 deletions
diff --git a/stdnum/__init__.py b/stdnum/__init__.py index 4f42a7e..b014314 100644 --- a/stdnum/__init__.py +++ b/stdnum/__init__.py @@ -23,72 +23,16 @@ This library offers functions for parsing, validating and reformatting standard numbers and codes in various formats. -Currently this package supports the following formats: +Currently this package supports the following formats and algorithms: - * UID (Umsatzsteuer-Identifikationsnummer, Austrian VAT number). - * BTW, TVA, NWSt (Belgian VAT number). - * EGN (ЕГН, Единен граждански номер, Bulgarian personal identity codes). - * PNF (ЛНЧ, Личен номер на чужденец, Bulgarian number of a foreigner). - * VAT (Идентификационен номер по ДДС, Bulgarian VAT number). - * CPF (Cadastro de Pessoas Físicas, Brazillian national identifier). - * Αριθμός Εγγραφής Φ.Π.Α. (Cypriot VAT number). - * DIČ (Daňové identifikační číslo, Czech VAT number). - * RČ (Rodné číslo, the Czech birth number). - * Ust ID Nr. (Umsatzsteur Identifikationnummer, the German VAT number). - * CPR (personnummer, the Danish citizen number). - * CVR (Momsregistreringsnummer, Danish VAT number). - * EAN (International Article Number). - * KMKR (Käibemaksukohuslase, Estonian VAT number). - * CIF (Certificado de Identificación Fiscal, Spanish company tax number). - * DNI (Documento nacional de identidad, Spanish personal identity codes). - * NIE (Número de Identificación de Extranjeros, Spanish foreigner number). - * NIF (Número de Identificación Fiscal, Spanish VAT number). - * VAT (European Union VAT number). - * ALV nro (Arvonlisäveronumero, Finnish VAT number). - * HETU (Henkilötunnus, Finnish personal identity code). - * SIREN (a French company identification number). - * n° TVA (taxe sur la valeur ajoutée, French VAT number). - * VAT (United Kingdom (and Isle of Man) VAT registration number). - * FPA, ΦΠΑ (Foros Prostithemenis Aksias, the Greek VAT number). - * GRid (Global Release Identifier). - * OIB (Osobni identifikacijski broj, Croatian identification number). - * ANUM (Közösségi adószám, Hungarian VAT number). - * IBAN (International Bank Account Number). - * PPS No (Personal Public Service Number, Irish personal number). - * VAT (Irish VAT number). - * IMEI (International Mobile Equipment Identity). - * IMSI (International Mobile Subscriber Identity). - * ISAN (International Standard Audiovisual Number). - * ISBN (International Standard Book Number). - * ISIL (International Standard Identifier for Libraries). - * ISMN (International Standard Music Number). - * ISSN (International Standard Serial Number). - * Partita IVA (Italian VAT number). - * PVM (Pridėtinės vertės mokestis mokėtojo kodas, Lithuanian VAT number). - * TVA (taxe sur la valeur ajoutée, Luxembourgian VAT number). - * PVN (Pievienotās vērtības nodokļa, Latvian VAT number). - * MEID (Mobile Equipment Identifier). - * VAT (Maltese VAT number). - * BSN (Burgerservicenummer, the Dutch national identification number). - * BTW-nummer (Omzetbelastingnummer, the Dutch VAT number). - * Onderwijsnummer (Dutch school number). - * NIP (Numer Identyfikacji Podatkowej, Polish VAT number). - * NIF (Número de identificação fiscal, Portuguese VAT number). - * CF (Cod de înregistrare în scopuri de TVA, Romanian VAT number). - * CNP (Cod Numeric Personal, Romanian Numerical Personal Code). - * VAT (Moms, Mervärdesskatt, Swedish VAT number). - * ID za DDV (Davčna številka, Slovenian VAT number). - * IČ DPH (IČ pre daň z pridanej hodnoty, Slovak VAT number). - * RČ (Rodné číslo, the Slovak birth number). - * SSN (U.S. Social Security Number). - -Furthermore a number of generic check digit algorithms are available: - - * the Verhoeff algorithm - * the Luhn and Luhn mod N algorithms - * some algorithms described in ISO/IEC 7064: Mod 11, 2, Mod 37, 2, - Mod 97, 10, Mod 11, 10 and Mod 37, 36 """ +# this docstring is automatically extended below + # the version number of the library __version__ = '0.7' + + +# extend the docstring with information from the modules +from stdnum.util import get_module_list +__doc__ += '\n'.join(get_module_list()) diff --git a/stdnum/util.py b/stdnum/util.py index c4f1115..451c116 100644 --- a/stdnum/util.py +++ b/stdnum/util.py @@ -25,6 +25,11 @@ stdnum. """ import pkgutil +import pydoc +import re + + +_strip_doctest_re = re.compile('^>>> .*\Z', re.DOTALL | re.MULTILINE) def clean(number, deletechars): @@ -46,3 +51,23 @@ def get_number_modules(base='stdnum'): module = __import__(name, globals(), locals(), [name]) if hasattr(module, 'is_valid'): yield module + + +def get_module_name(module): + """Return the short description of the number.""" + return pydoc.splitdoc(pydoc.getdoc(module))[0] + + +def get_module_description(module): + """Return a description of the number.""" + doc = pydoc.splitdoc(pydoc.getdoc(module))[1] + # remove the doctests + return _strip_doctest_re.sub('', doc[1]).strip(), + + +def get_module_list(): + for module in get_number_modules(): + yield ' * %s: %s' % ( + module.__name__.replace('stdnum.', ''), + get_module_name(module), + ) |