lists.arthurdejong.org
RSS feed

python-stdnum commit: r176 - python-stdnum/stdnum

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

python-stdnum commit: r176 - python-stdnum/stdnum



Author: arthur
Date: Sat Sep 22 17:40:03 2012
New Revision: 176
URL: http://arthurdejong.org/viewvc/python-stdnum?revision=176&view=revision

Log:
generate part of the stdnum docstring based on introspection of the modules

Modified:
   python-stdnum/stdnum/__init__.py
   python-stdnum/stdnum/util.py

Modified: python-stdnum/stdnum/__init__.py
==============================================================================
--- python-stdnum/stdnum/__init__.py    Sat Jun 16 12:42:27 2012        (r175)
+++ python-stdnum/stdnum/__init__.py    Sat Sep 22 17:40:03 2012        (r176)
@@ -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())

Modified: python-stdnum/stdnum/util.py
==============================================================================
--- python-stdnum/stdnum/util.py        Sat Jun 16 12:42:27 2012        (r175)
+++ python-stdnum/stdnum/util.py        Sat Sep 22 17:40:03 2012        (r176)
@@ -25,6 +25,11 @@
 """
 
 import pkgutil
+import pydoc
+import re
+
+
+_strip_doctest_re = re.compile('^>>> .*\Z', re.DOTALL | re.MULTILINE)
 
 
 def clean(number, deletechars):
@@ -46,3 +51,23 @@
         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),
+        )
-- 
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/python-stdnum-commits/