etgen.utils

Some utility functions.

(This module’s source code is available here.)

Functions

_test()

compatstr(s)

The python-future package introduces a special helper class newstr which simulates, under Python 2, the behaviour of Python 3 strings.

forcetext(iter)

Resolve any lazy translatable strings.

join_elems(elems[, sep])

Examples:

prettify(s)

pretty_print(elem)

Return a pretty-printed XML string for the Element.

Classes

Namespace([targetNamespace, names, prefix])

An XML namespace.

etgen.utils.join_elems(elems, sep=' ')

Examples:

>>> join_elems([1, 2, 3])
[1, ' ', 2, ' ', 3]
>>> join_elems([1, 2, 3],' / ')
[1, ' / ', 2, ' / ', 3]
>>> join_elems([])
[]
etgen.utils.forcetext(iter)

Resolve any lazy translatable strings. Utility function for lxml element trees.

etgen.utils.pretty_print(elem)

Return a pretty-printed XML string for the Element.

etgen.utils.compatstr(s)

The python-future package introduces a special helper class newstr which simulates, under Python 2, the behaviour of Python 3 strings. But xml.etree.ElementTree in Python 2 doesn’t know about python-future and produces invalid XML when you feed it with such a string.

So this function converts any newstr back to a real newstr.

TODO: Not yet tested under Python 3. At the best it is just unefficient.

class etgen.utils.Namespace(targetNamespace=None, names=None, prefix=None)

Bases: object

An XML namespace. Base class for etgen.html.HtmlNamespace and the namespaces defined in etgen.intervat.

fromstring(s, **kwargs)

Build an element tree from the given XML source string.

This just forwards to the xml.etree.ElementTree.fromstring() library function. See the Parsing XML section of the Python docs.

raw(*args)

Parses the given string into an XML Element.