Exemplo n.º 1
0
    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
Exemplo n.º 2
0
 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())
Exemplo n.º 3
0
 def test_removing_unnested(self):
     d = dict(a='b', c='d')
     util.dict_remove_path(d, 'a')
     self.assertEquals(d, dict(c='d'))
Exemplo n.º 4
0
 def test_removing_nonexisting(self):
     d = dict(foo='bar')
     util.dict_remove_path(d, 'bar.baz')
     self.assertEquals(d, dict(foo='bar'))