File: configuration.rst

package info (click to toggle)
fastkml 1.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,552 kB
  • sloc: python: 18,501; xml: 539; makefile: 16
file content (44 lines) | stat: -rw-r--r-- 1,414 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Configuration
==============

ElementTree configuration
--------------------------

By default, fastkml uses the standard libraries
``xml.etree.ElementTree`` or, if installed, ``lxml.etree``
as its parser, but you can change this by setting the
``fastkml.config.etree`` module variable to a different
implementation.

E.g. if you have lxml installed, but you want to use the
standard ``xml.etree.ElementTree``, you can do this:

.. code-block:: pycon

    >>> import fastkml.config
    >>> import xml.etree.ElementTree
    >>> fastkml.config.set_etree_implementation(xml.etree.ElementTree)
    >>> fastkml.config.set_default_namespaces()

You can pass any module that implements the ``ElementTree`` interface
to the ``set_etree_implementation`` function.

.. code-block:: pycon

    >>> import fastkml.config
    >>> import lxml.etree
    >>> fastkml.config.set_etree_implementation(lxml.etree)

Registering additional namespaces
----------------------------------
The ``fastkml.config.set_default_namespaces`` function registers
the ``kml``, ``gx`` and ``atom`` namespaces with the ``ElementTree``.
You can add any other namespaces you want to use by calling
``fastkml.config.register_namespace`` with the namespace prefix and
the namespace URI.

.. code-block:: pycon

    >>> import fastkml.config
    >>> fastkml.config.register_namespaces(foo="http://foo.com")
    >>> fastkml.config.set_default_namespaces()