A Storage object is like a dictionary except `obj.foo` can be used in addition to `obj['foo']`. >>> o = storage(a=1) >>> o.a 1 >>> o['a'] 1 >>> o.a = 2 >>> o['a'] 2 >>> del o.a >>> o.a Traceback (most r
| 72 | |
| 73 | |
| 74 | class Storage(dict): |
| 75 | """ |
| 76 | A Storage object is like a dictionary except `obj.foo` can be used |
| 77 | in addition to `obj['foo']`. |
| 78 | |
| 79 | >>> o = storage(a=1) |
| 80 | >>> o.a |
| 81 | 1 |
| 82 | >>> o['a'] |
| 83 | 1 |
| 84 | >>> o.a = 2 |
| 85 | >>> o['a'] |
| 86 | 2 |
| 87 | >>> del o.a |
| 88 | >>> o.a |
| 89 | Traceback (most recent call last): |
| 90 | ... |
| 91 | AttributeError: 'a' |
| 92 | |
| 93 | """ |
| 94 | |
| 95 | def __getattr__(self, key): |
| 96 | try: |
| 97 | return self[key] |
| 98 | except KeyError as k: |
| 99 | raise AttributeError(k) |
| 100 | |
| 101 | def __setattr__(self, key, value): |
| 102 | self[key] = value |
| 103 | |
| 104 | def __delattr__(self, key): |
| 105 | try: |
| 106 | del self[key] |
| 107 | except KeyError as k: |
| 108 | raise AttributeError(k) |
| 109 | |
| 110 | def __repr__(self): |
| 111 | return "<Storage " + dict.__repr__(self) + ">" |
| 112 | |
| 113 | |
| 114 | storage = Storage |
no outgoing calls
no test coverage detected