def test_get_partial_dict(): eq_( get_partial_dict('prefix', { 'prefix.xyz': 1, 'prefix.zyx': 2, 'xy': 3 }), { 'xyz': 1, 'zyx': 2 })
def __getattr__(self, key): """Our custom attribute getter. Tries to get the attribute off the wrapped object first, if that does not work, tries dictionary lookup, and finally tries to grab all keys that start with the attribute and return sub-dictionaries that can be looked up. """ try: return self.config_proxy.__getattribute__(key) except AttributeError: try: return self.config_proxy.current_conf()[key] except KeyError: return get_partial_dict(key, self.config_proxy.current_conf(), Bunch)
def test_get_partial_dict(): eq_(get_partial_dict('prefix', {'prefix.xyz':1, 'prefix.zyx':2, 'xy':3}), {'xyz':1,'zyx':2})
def __getattr__(self, name): try: return self[name] except KeyError: return get_partial_dict(name, self, Bunch)