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 output_methods
{'html': <kid.serialization.HTMLSerializer object at 0x10ff7b0>, 'html-strict': <kid.serialization.HTMLSerializer object at 0x10ffdd0>, 'plain': <kid.serialization.PlainSerializer object at 0x10ff230>, 'xhtml': <kid.serialization.XHTMLSerializer object at 0x10ff6d0>, 'xhtml-strict': <kid.serialization.XHTMLSerializer object at 0x10ff870>, 'xml': <kid.serialization.XMLSerializer object at 0x10ff670>}
Functions
f Template(file=None, source=None, name=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=1)
- 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.
f enable_import(suffixes=None) ...
Enable the kid module loader and import hooks.
This function must be called before importing kid templates if templates are not pre-compiled.
Note that if your application uses ZODB, you will need to import ZODB before calling this function as ZODB's import hooks have some issues if installed after the kid import hooks.
f import_template(name) ...
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 load_template(file, name='', cache=1, encoding=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.
Classes
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 11 members.
C HTMLSerializer(...) ...
This class contains 11 members.
C Serializer(...) ...
This class contains 5 members.
C XHTMLSerializer(...) ...
This class contains 11 members.
C XMLSerializer(...) ...
This class contains 8 members.
Modules
The kid module exposes 4 submodules:
- filter
- Kid tranformations
- namespace
- serialization
- Infoset serialization formats (XML, XHTML, HTML, etc)
- util
See the source for more information.