def process(self, baton): for path in self.remove: util.dict_remove_path(baton, path) if self.keep: keepers = dict() for path in self.keep: value = util.dict_get_path(baton, path, Ellipsis) if value is Ellipsis: continue util.dict_set_path(keepers, path, value) # Modify baton in-place baton.clear() baton.update(keepers) return baton
def test_removing_nested(self): d = dict(a=dict(b='c'), d='e') util.dict_remove_path(d, 'a.b') self.assertEquals(d, dict(a=dict(), d='e')) util.dict_remove_path(d, 'a') self.assertEquals(d, dict(d='e')) util.dict_remove_path(d, 'd') self.assertEquals(d, dict())
def test_removing_unnested(self): d = dict(a='b', c='d') util.dict_remove_path(d, 'a') self.assertEquals(d, dict(c='d'))
def test_removing_nonexisting(self): d = dict(foo='bar') util.dict_remove_path(d, 'bar.baz') self.assertEquals(d, dict(foo='bar'))