| 1 | #!/usr/bin/python |
| 2 | # -*- coding: utf-8 -*- |
| 3 | |
| 4 | # |
| 5 | # petits utilitaires divers |
| 6 | # |
| 7 | |
| 8 | def dict_fetchone(cursor): |
| 9 | """Renvoie le resultat d'un fetchone (db-api 2.0) dans un dictionnaire""" |
| 10 | result = cursor.fetchone() |
| 11 | if result == None: return None |
| 12 | result_dict = {} |
| 13 | for i in range(len(result)): |
| 14 | if isinstance( result[i], str ): |
| 15 | result_dict[cursor.description[i][0]] = result[i].decode('iso-8859-1') |
| 16 | else: |
| 17 | result_dict[cursor.description[i][0]] = result[i] |
| 18 | return result_dict |
| 19 | |
| 20 | |
| 21 | import re |
| 22 | p = re.compile('(dem|com)-(...)-(...)',re.IGNORECASE) |
| 23 | def coda2rest(value): |
| 24 | """Traduit un nom CODA vers la base REST correspondante, |
| 25 | par exemple DEM-LOG-AUF en demlog ou COM-ARE-VN3 en comarevn3""" |
| 26 | m = p.search(value) |
| 27 | if m == None: return value |
| 28 | if m.group(3).lower() == 'auf': |
| 29 | return m.group(1).lower() + m.group(2).lower() |
| 30 | else: |
| 31 | return m.group(1).lower() + m.group(2).lower() + m.group(3).lower() |
| 32 | |