Skip to main content

Fast XML template compiler for Python.

Project description

Overview

Chameleon is an HTML/XML [1] template language compiler.

It includes a feature-complete engine for the Zope Page Templates (ZPT) language.

The software is released on PyPi. To download and install the latest release:

$ easy-install -U Chameleon

Platforms

This library has been successfully tested on the following platforms:

  • Python 2.5, 2.6, 2.7

  • Python 3.1, 3.2

  • PyPy

What’s New in 2.x

The 2.x series is a complete rewrite of the library and supports both Python 2.5+ and Python 3.1+ with a single source code.

For most users it should be an easy upgrade, however note that at present, there is no engine for the Genshi language.

New parser

This series features a new parser, implemented in pure Python. It parses both HTML and XML inputs (the previous parser relied on the expat system library and was more strict about its input).

Language changes

The 2.x engine matches the output of the reference implementation more closely (usually exactly). There are less differences altogether; for instance, the method of escaping TALES expression (usually a semicolon) has been changed to match that of the reference implementation.

This series also introduces a number of new language features:

1) Support for the tal:on-error from the reference specification has been added.

2) Inspired by the Genshi language, a pair of new attributes has been added: tal:switch and tal:case, allowing flexible conditions.

Expression engine

The expression engine has been redesigned to make it easier to understand and extend.

The engine is built on the ast module (available since Python 2.6; backports included for Python 2.5).

Performance

The compiler output has been optimized for complex templates. For most applications, the engine should perform similarly to the 1.x series.

Very simple templates with tight loops (such as that of the “big table” benchmark) will see a decrease in performance. The compiler is optimized for dynamic variable scope and this lowers performance for templates that require only a static scope.

Changes

2.0-rc4 (2011-03-03)

Bugfixes:

  • Fixed an issue where the output of an end-to-end string expression would raise an exception if the expression evaluated to None (it should simply output nothing).

  • The convert function (which is configurable on the template class level) now defaults to the translate function (at run-time).

    This fixes an issue where message objects were not translated (and thus converted to a string) using the a provided translate function.

  • Fixed string interpolation issue where an expression immediately succeeded by a right curly bracket would not parse.

    This fixes issue #5.

  • Fixed error where tal:condition would be evaluated after tal:repeat.

Features:

  • Python expression is now a TALES expression. That means that the pipe operator can be used to chain two or more expressions in a try-except sequence.

    This behavior was ported from the 1.x series. Note that while it’s still possible to use the pipe character (“|”) in an expression, it must now be escaped.

  • The template cache can now be shared by multiple processes.

2.0-rc3 (2011-03-02)

Bugfixes:

  • Fixed atexit handler.

    This fixes issue #3.

  • If a cache directory is specified, it will now be used even when not in debug mode.

  • Allow “comment” attribute in the TAL namespace.

    This fixes an issue in the sense that the reference engine allows any attribute within the TAL namespace. However, only “comment” is in common use.

  • The template constructor now accepts a flag debug which puts the template instance into debug-mode regardless of the global setting.

    This fixes issue #1.

Features:

  • Added exception handler for exceptions raised while evaluating an expression.

    This handler raises (or attempts to) a new exception of the type RenderError, with an additional base class of the original exception class. The string value of the exception is a formatted error message which includes the expression that caused the exception.

    If we are unable to create the exception class, the original exception is re-raised.

2.0-rc2 (2011-02-28)

  • Fixed upload issue.

2.0-rc1 (2011-02-28)

  • Initial public release. See documentation for what’s new in this series.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Chameleon-2.0-rc4.tar.gz (97.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page