kid

Pythonic, XML Templating

Kid is a simple, Python-based template language for generating and transforming XML vocabularies. Kid was spawned as a result of a kinky love triangle between XSLT, TAL, and PHP. We believe many of the best features of these languages live on in Kid with much of the limitations and complexity stamped out (well, eventually :).


Attributes

a __email__

'rtomayko@gmail.com'

a output_methods

{'HTML': <kid.serialization.HTMLSerializer object at 0xb7b239cc>,
 'HTML-frameset': <kid.serialization.HTMLSerializer object at 0xb7b239ec>,
 'HTML-frameset-quirks': <kid.serialization.HTMLSerializer object at 0xb7b23a2c>,
 'HTML-quirks': <kid.serialization.HTMLSerializer object at 0xb7b23a0c>,
 'HTML-strict': <kid.serialization.HTMLSerializer object at 0xb7b239ac>,
 'html': <kid.serialization.HTMLSerializer object at 0xb7b3ac2c>,
 'html-frameset': <kid.serialization.HTMLSerializer object at 0xb7b3ac4c>,
 'html-frameset-quirks': <kid.serialization.HTMLSerializer object at 0xb7b2398c>,
 'html-quirks': <kid.serialization.HTMLSerializer object at 0xb7b3ac8c>,
 'html-strict': <kid.serialization.HTMLSerializer object at 0xb7b3ac0c>,
 'plain': <kid.serialization.PlainSerializer object at 0xb7b23a4c>,
 'wml': <kid.serialization.XMLSerializer object at 0xb7b3ab6c>,
 'xhtml': <kid.serialization.XHTMLSerializer object at 0xb7b3abcc>,
 'xhtml-frameset': <kid.serialization.XHTMLSerializer object at 0xb7b3abec>,
 'xhtml-strict': <kid.serialization.XHTMLSerializer object at 0xb7b3ab8c>,
 'xml': <kid.serialization.XMLSerializer object at 0xb7b3aacc>}

a KID_XMLNS

'http://purl.org/kid/ns#'

a output_formats

{'compact': Format(simple_whitespace=True),
 'compact+named': Format(entity_map=True, simple_whitespace=True),
 'compact+named+nice': Format(educate=True, entity_map=True, simple_whitespace=True),
 'compact+nice': Format(educate=True, simple_whitespace=True),
 'default': Format(simple_newlines=True),
 'named': Format(entity_map=True, simple_newlines=True),
 'newlines': Format(indent='', simple_whitespace=True),
 'newlines+named': Format(entity_map=True, indent='', simple_whitespace=True),
 'newlines+named+nice': Format(educate=True, indent='', simple_whitespace=True),
 'newlines+nice': Format(educate=True, indent='', simple_whitespace=True),
 'nice': Format(educate=True, simple_newlines=True),
 'nice+named': Format(educate=True, entity_map=True, simple_newlines=True),
 'pretty': Format(indent=True, simple_whitespace=True),
 'pretty+named': Format(entity_map=True, indent=True, simple_whitespace=True),
 'pretty+named+nice': Format(educate=True, entity_map=True, indent=True, simple_whitespace=True),
 'pretty+nice': Format(educate=True, indent=True, simple_whitespace=True),
 'straight': Format(),
 'ugly': Format(simple_newlines=True, stupefy=True),
 'wrap': Format(indent='', wrap=True),
 'wrap+named': Format(entity_map=True, indent='', wrap=True),
 'wrap+named+nice': Format(educate=True, entity_map=True, indent='', wrap=True),
 'wrap+nice': Format(educate=True, indent='', wrap=True)}

Functions

f XML(text, fragment=True, encoding=None, xmlns=None, entity_map=None) ...

Convert XML string into an ElementStream.

f enable_import(ext=None, path=None) ...

Enable the kid module loader and import hooks.

This function must be called before importing kid templates if templates are not pre-compiled.

f document(file, encoding=None, filename=None, entity_map=None, debug=False) ...

Convert XML document into an Element stream.

f import_template(name, encoding=None) ...

Import template by name.

This is identical to calling enable_import followed by an import statement. For example, importing a template named foo using the normal import mechanism looks like this:

import kid
kid.enable_import()
import foo

This function can be used to achieve the same result as follows:

import kid
foo = kid.import_template('foo')

This is sometimes useful when the name of the template is available only as a string.

f SubElement(parent, tag, attrib={}) ...

f load_template(file, name='', cache=True, encoding=None, ns={}, entity_map=None, exec_module=None) ...

Bypass import machinery and load a template module directly.

This can be used as an alternative to accessing templates using the native python import mechanisms.

file
Can be a filename, a kid template string, or an open file object.
name
Optionally specifies the module name to use for this template. This is a hack to enable relative imports in templates.
cache
Whether to look for a byte-compiled version of the template. If no byte-compiled version is found, an attempt is made to dump a byte-compiled version after compiling. This argument is ignored if file is not a filename.
entity_map
Entity map to be used when parsing the template.
exec_module
If you want full control over how the template module is executed, you can provide this callable that will be called with the template module and the code to be executed as parameters, after the code has been compiled and the module has been created.

f Template(file=None, source=None, name=None, encoding=None) ...

Get a Template class quickly given a module name, file, or string.

This is a convenience function for getting a template in a variety of ways. One and only one of the arguments name or file must be specified.

file:string
The template module is loaded by calling load_template(file, name='', cache=True)
name:string
The kid import hook is enabled and the template module is located using the normal Python import mechanisms.
source:string
string containing the templates source.

Once the template module is obtained, a new instance of the module's Template class is created with the keyword arguments passed to this function.

Classes

C Namespace(...) ...

This class contains 4 members.

C Element(...) ...

A class representing an XML element.

This class contains 10 members.

C Format(...) ...

Formatting details for Serializers.

This class contains 31 members.

C Serializer(...) ...

This class contains 7 members.

C BaseTemplate(...) ...

Base class for compiled Templates.

All kid template modules expose a class named Template that extends from this class making the methods defined here available on all Template subclasses.

This class should not be instantiated directly.

This class contains 13 members.

C XMLSerializer(...) ...

This class contains 10 members.

C HTMLSerializer(...) ...

This class contains 16 members.

C XHTMLSerializer(...) ...

This class contains 14 members.

Modules

The kid module exposes 5 submodules:

filter
Kid tranformations
format
Infoset serialization format styles.
namespace
Namespace handling.
serialization
Infoset serialization formats (XML, XHTML, HTML, etc)
util
Utility functions for Kid.

See the source for more information.