py2store.utils.attr_dict¶
a data object layer for object attributes
Functions
|
Returns a Mapping class that routes attribute access to keys of mapping. |
|
Classes
|
A read-only façade for navigating a JSON-like object using attribute notation. |
- class py2store.utils.attr_dict.AttrMap(arg)[source]¶
Bases:
objectA read-only façade for navigating a JSON-like object using attribute notation. Based on Luciano Ramalho’s “Fluent Python” book.
>>> t = AttrMap({'a': {'b': 2, 'foo': 'bar'}, 'b': [1,2,3]}) >>> t AttrMap({'a': {'b': 2, 'foo': 'bar'}, 'b': [1, 2, 3]}) >>> t.a AttrMap({'b': 2, 'foo': 'bar'}) >>> t.a.foo 'bar' >>> t.b [1, 2, 3]
See also
‘AttrDict’ in
dol.sourcesmodule.
- py2store.utils.attr_dict.attr_wrap(cls, name=None)[source]¶
Returns a Mapping class that routes attribute access to keys of mapping.
>>> A = attr_wrap(dict) >>> t = A({'a_special_attr': 'foo', 'another_attr': 2, # valid identifiers ... 42: [1, 2], '$invalid': 'identifier', 'class': 'is a reserved keyword'}) # not valid identifiers >>> # verify that we have the attr we want >>> assert 'a_special_attr' in dir(t) >>> assert 'another_attr' in dir(t) >>> # verify that we DO NOT have the attr we DO NOT want >>> assert 42 not in dir(t) >>> assert '$invalid' not in dir(t) >>> assert 'class' not in dir(t)
See also
‘AttrDict’ in
dol.sourcesmodule.
- py2store.utils.attr_dict.iskeyword()¶
x.__contains__(y) <==> y in x.