Wrapper around OrderedDict that allows access via item position or key
| 65 | |
| 66 | |
| 67 | class IndexedDict(Mapping): |
| 68 | """Wrapper around OrderedDict that allows access via item position or key""" |
| 69 | |
| 70 | def __init__(self, *args, **kwargs): |
| 71 | self._od = OrderedDict(*args, **kwargs) |
| 72 | |
| 73 | def __getitem__(self, k): |
| 74 | try: |
| 75 | return list(self._od.values())[k] |
| 76 | except TypeError: |
| 77 | return self._od[k] |
| 78 | |
| 79 | def __len__(self): |
| 80 | return self._od.__len__() |
| 81 | |
| 82 | def __iter__(self): |
| 83 | return self._od.__iter__() |
| 84 | |
| 85 | |
| 86 | class Parser(ast.NodeVisitor): |
no outgoing calls
no test coverage detected