| Total Complexity | 7 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # encoding: utf-8 |
||
| 2 | """ |
||
| 3 | hashtable.py |
||
| 4 | |||
| 5 | Created by Thomas Mangin on 2009-09-06. |
||
| 6 | Copyright (c) 2009-2017 Exa Networks. All rights reserved. |
||
| 7 | License: 3-clause BSD. (See the COPYRIGHT file) |
||
| 8 | """ |
||
| 9 | |||
| 10 | |||
| 11 | def _(key): |
||
| 12 | return key.replace('_', '-') |
||
| 13 | |||
| 14 | |||
| 15 | class HashTable(dict): |
||
| 16 | def __getitem__(self, key): |
||
| 17 | return dict.__getitem__(self, _(key)) |
||
| 18 | |||
| 19 | def __setitem__(self, key, value): |
||
| 20 | return dict.__setitem__(self, _(key), value) |
||
| 21 | |||
| 22 | def __getattr__(self, key): |
||
| 23 | return dict.__getitem__(self, _(key)) |
||
| 24 | |||
| 25 | def __setattr__(self, key, value): |
||
| 26 | return dict.__setitem__(self, _(key), value) |
||
| 27 | |||
| 28 | |||
| 29 | class GlobalHashTable(HashTable): |
||
| 30 | _instance = None |
||
| 31 | |||
| 32 | def __new__(cls): |
||
| 33 | if cls._instance is None: |
||
| 34 | cls._instance = super(GlobalHashTable, cls).__new__(cls) |
||
| 35 | return cls._instance |
||
| 36 |