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