How to use the fastkml.config.etree function in fastkml

To help you get started, we’ve selected a few fastkml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cleder / fastkml / fastkml / test_main.py View on Github external
def test_BaseObject(self):
        bo = base._BaseObject(id='id0')
        self.assertEqual(bo.id, 'id0')
        self.assertEqual(bo.ns, config.NS)
        self.assertEqual(bo.targetId, None)
        self.assertEqual(bo.__name__, None)
        bo.targetId = 'target'
        self.assertEqual(bo.targetId, 'target')
        bo.ns = ''
        bo.id = None
        self.assertEqual(bo.id, None)
        self.assertEqual(bo.ns, '')
        self.assertRaises(NotImplementedError, bo.etree_element)
        element = etree.Element(config.NS + 'Base')
        self.assertRaises(TypeError, bo.from_element)
        self.assertRaises(TypeError, bo.from_element, element)
        bo.__name__ = 'NotABaseObject'
        self.assertRaises(TypeError, bo.from_element, element)
        # Note that we can coax baseclasses not to throw errors
        bo.__name__ = 'Base'
        bo.ns = config.NS
        bo.from_element(element)
        self.assertEqual(bo.id, None)
        self.assertEqual(bo.ns, config.NS)
        self.assertFalse(bo.etree_element(), None)
        self.assertTrue(len(bo.to_string()) > 1)
github cleder / fastkml / fastkml / base.py View on Github external
def etree_element(self):
        if self.__name__:
            element = etree.Element(self.ns + self.__name__)
        else:
            raise NotImplementedError(
                "Call of abstract base class, subclasses implement this!"
            )
        return element
github cleder / fastkml / fastkml / geometry.py View on Github external
def _etree_point(self, point):
        element = etree.Element("%sPoint" % self.ns)
        self._set_extrude(element)
        self._set_altitude_mode(element)
        coords = list(point.coords)
        element.append(self._etree_coordinates(coords))
        return element
github cleder / fastkml / fastkml / atom.py View on Github external
def from_string(self, xml_string):
        self.from_element(etree.XML(xml_string))
github cleder / fastkml / fastkml / atom.py View on Github external
def to_string(self, prettyprint=True):
        """ Return the ATOM Object as serialized xml """
        if LXML and prettyprint:
            return etree.tostring(
                self.etree_element(),
                encoding='utf-8',
                pretty_print=True).decode('UTF-8')
        else:
            return etree.tostring(
                self.etree_element(),
                encoding='utf-8').decode('UTF-8')
github cleder / fastkml / fastkml / styles.py View on Github external
def etree_element(self):
        element = super(StyleMap, self).etree_element()
        if self.normal:
            if isinstance(self.normal, (Style, StyleUrl)):
                pair = etree.SubElement(element, "%sPair" % self.ns)
                key = etree.SubElement(pair, "%skey" % self.ns)
                key.text = 'normal'
                pair.append(self.normal.etree_element())
        if self.highlight:
            if isinstance(self.highlight, (Style, StyleUrl)):
                pair = etree.SubElement(element, "%sPair" % self.ns)
                key = etree.SubElement(pair, "%skey" % self.ns)
                key.text = 'highlight'
                pair.append(self.highlight.etree_element())
        return element
github cleder / fastkml / fastkml / atom.py View on Github external
def etree_element(self):
        element = etree.Element(self.ns + self.__name__.lower())
        if self.href:
            element.set('href', self.href)
        else:
            raise ValueError('required attribute href missing')
        if self.rel:
            element.set('rel', self.rel)
        if self.type:
            element.set('type', self.type)
        if self.hreflang:
            element.set('hreflang', self.hreflang)
        if self.title:
            element.set('title', self.title)
        if self.length:
            element.set('length', self.length)
        return element
github cleder / fastkml / fastkml / styles.py View on Github external
def etree_element(self):
        element = super(PolyStyle, self).etree_element()
        if self.fill is not None:
            fill = etree.SubElement(element, "%sfill" % self.ns)
            fill.text = str(self.fill)
        if self.outline is not None:
            outline = etree.SubElement(element, "%soutline" % self.ns)
            outline.text = str(self.outline)
        return element