def _dict_to_etree(self, parent, d): for key, value in d.items(): tag = re.sub('\W', '', snake_to_camel(key)) # TODO: any other dict class? if isinstance(value, (dict, DictMixin)): elem = SubElement(parent, tag) self._dict_to_etree(elem, value) else: SubElement(parent, tag).text = value
def _dict_to_etree(self, parent, d): for key, value in d.items(): tag = re.sub('\W', '', snake_to_camel(key)) elem = SubElement(parent, tag) if isinstance(value, (dict, DictMixin)): self._dict_to_etree(elem, value) else: try: elem.text = str(value) except ValueError: # We set an invalid string for XML. elem.text = '(invalid string)'
def test_snake_to_camel(self): for s1, s2 in strs: self.assertEquals(s1, utils.snake_to_camel(s2))