Beispiel #1
0
    def process(self, baton):
        xml = util.dict_get_path(baton, self.xml_path)
        e = etree.XML(xml)

        for xpath, output_path in self.xpaths.items():
            result = e.xpath(xpath)
            util.dict_setdefault_path(baton, output_path, []).extend(result)

        return baton
Beispiel #2
0
    def test_setdefault_through_attributes(self):
        class Bar(object):
            def __init__(self, wrapped):
                self.wrapped = wrapped

        d = dict(a=Bar(dict(b='c')))
        self.assertEquals(util.dict_setdefault_path(d, 'a.wrapped.b', 'd'), 'c')
        self.assertEquals(util.dict_get_path(d, 'a.wrapped.b'), 'c')
        self.assertEquals(util.dict_setdefault_path(d, 'a.wrapped.c', 'd'), 'd')
        self.assertEquals(util.dict_get_path(d, 'a.wrapped.c'), 'd')
Beispiel #3
0
    def setdefault(self, path, value):
        """ Sets the configuration key specified by *path* to *value*,
        unless a value is already defined for that path. Returns the
        value of *path* --- i.e. either *value* or the already
        existing value.

        .. :seealso: ::

            :ref:`~piped.util.dict_setdefault_path`
                for more on the behaviour of setting with key paths.
        """
        return util.dict_setdefault_path(self._config, path, value)
Beispiel #4
0
 def test_setdefault(self):
     d = dict(a=dict(b='c'))
     self.assertEquals(util.dict_setdefault_path(d, 'a.b', 'd'), 'c')
     self.assertEquals(d, dict(a=dict(b='c')))
     self.assertEquals(util.dict_setdefault_path(d, 'a.c', 'd'), 'd')
     self.assertEquals(d, dict(a=dict(b='c', c='d')))