simpletal package¶
Submodules¶
simpletal.simpleTAL module¶
simpleTAL Interpreter
The classes in this module implement the TAL language, expanding both XML and HTML templates.
-
class
simpletal.simpleTAL.
TemplateInterpreter
[source]¶ Bases:
object
-
cmdDefine
(command, args)[source]¶ args: [(isLocalFlag (Y/n), variableName, variablePath),...] Define variables in either the local or global context
-
cmdCondition
(command, args)[source]¶ args: expression, endTagSymbol Conditionally continues with execution of all content contained by it.
-
cmdRepeat
(command, args)[source]¶ args: (varName, expression, endTagSymbol) Repeats anything in the cmndList
-
cmdContent
(command, args)[source]¶ args: (replaceFlag, structureFlag, expression, endTagSymbol) Expands content
-
cmdAttributes
(command, args)[source]¶ args: [(attributeName, expression)] Add, leave, or remove attributes from the start tag
-
cmdStartScope
(command, args)[source]¶ args: (originalAttributes, currentAttributes) Pushes the current state onto the stack, and sets up the new state
-
-
class
simpletal.simpleTAL.
Template
(commands, macros, symbols, doctype=None)[source]¶ Bases:
object
-
expand
(context, outputFile, outputEncoding=None, interpreter=None)[source]¶ This method will write to the outputFile, using the encoding specified, the expanded version of this template. The context passed in is used to resolve all expressions with the template.
-
-
class
simpletal.simpleTAL.
SubTemplate
(startRange, endRangeSymbol)[source]¶ Bases:
simpletal.simpleTAL.Template
A SubTemplate is part of another template, and is used for the METAL implementation. The two uses for this class are:
1 - metal:define-macro results in a SubTemplate that is the macro 2 - metal:fill-slot results in a SubTemplate that is a parameter to metal:use-macro
-
class
simpletal.simpleTAL.
HTMLTemplate
(commands, macros, symbols, doctype=None, minimizeBooleanAtts=0)[source]¶ Bases:
simpletal.simpleTAL.Template
A specialised form of a template that knows how to output HTML
-
class
simpletal.simpleTAL.
XMLTemplate
(commands, macros, symbols, doctype=None)[source]¶ Bases:
simpletal.simpleTAL.Template
A specialised form of a template that knows how to output XML
-
expand
(context, outputFile, outputEncoding=u'utf-8', docType=None, suppressXMLDeclaration=0, interpreter=None)[source]¶ This method will write to the outputFile, using the encoding specified, the expanded version of this template. The context passed in is used to resolve all expressions with the template.
-
-
class
simpletal.simpleTAL.
TemplateCompiler
[source]¶ Bases:
object
-
addTag
(tag, tagProperties={})[source]¶ Used to add a tag to the stack. Various properties can be passed in the dictionary as being information required by the tag. Currently supported properties are:
‘command’ - The (command,args) tuple associated with this command ‘originalAtts’ - The original attributes that include any metal/tal attributes ‘endTagSymbol’ - The symbol associated with the end tag for this element ‘popFunctionList’ - A list of functions to execute when this tag is popped
‘singletonTag’ - A boolean to indicate that this is a singleton flag
-
-
exception
simpletal.simpleTAL.
TemplateParseException
(location, errorDescription)[source]¶ Bases:
exceptions.Exception
-
class
simpletal.simpleTAL.
HTMLTemplateCompiler
[source]¶ Bases:
simpletal.simpleTAL.TemplateCompiler
,HTMLParser.HTMLParser
-
class
simpletal.simpleTAL.
XMLTemplateCompiler
[source]¶ Bases:
simpletal.simpleTAL.TemplateCompiler
,xml.sax.handler.ContentHandler
,xml.sax.handler.DTDHandler
,simpletal.simpleTAL.LexicalHandler
-
simpletal.simpleTAL.
compileHTMLTemplate
(template, inputEncoding=u'UTF-8-SIG', minimizeBooleanAtts=0)[source]¶ Reads the templateFile and produces a compiled template. To use the resulting template object call:
template.expand (context, outputFile)
simpletal.simpleTALConstants module¶
-
simpletal.simpleTALConstants.
METAL_NAME_URI
= u'http://xml.zope.org/namespaces/metal'¶ METAL namespace URI
-
simpletal.simpleTALConstants.
TAL_NAME_URI
= u'http://xml.zope.org/namespaces/tal'¶ TAL namespace URI
-
simpletal.simpleTALConstants.
TAL_DEFINE
= 1¶ Argument: [(isLocalFlag (Y/n), variableName, variablePath),...]
-
simpletal.simpleTALConstants.
TAL_CONDITION
= 2¶ Argument: expression, endTagSymbol
-
simpletal.simpleTALConstants.
TAL_REPEAT
= 3¶ Argument: (varname, expression, endTagSymbol)
-
simpletal.simpleTALConstants.
TAL_CONTENT
= 4¶ Argument: (replaceFlag, type, expression)
-
simpletal.simpleTALConstants.
TAL_REPLACE
= 5¶ Not used in byte code, only ordering.
-
simpletal.simpleTALConstants.
TAL_ATTRIBUTES
= 6¶ Argument: [(attributeName, expression)]
-
simpletal.simpleTALConstants.
TAL_OMITTAG
= 7¶ Argument: expression
-
simpletal.simpleTALConstants.
TAL_START_SCOPE
= 8¶ Argument: (originalAttributeList, currentAttributeList)
-
simpletal.simpleTALConstants.
TAL_OUTPUT
= 9¶ Argument: String to output
-
simpletal.simpleTALConstants.
TAL_STARTTAG
= 10¶ Argument: None
-
simpletal.simpleTALConstants.
TAL_ENDTAG_ENDSCOPE
= 11¶ Argument: Tag, omitTagFlag
-
simpletal.simpleTALConstants.
TAL_NOOP
= 13¶ Argument: None
-
simpletal.simpleTALConstants.
METAL_USE_MACRO
= 14¶ Argument: expression, slotParams, endTagSymbol
-
simpletal.simpleTALConstants.
METAL_DEFINE_SLOT
= 15¶ Argument: macroName, endTagSymbol
-
simpletal.simpleTALConstants.
METAL_FILL_SLOT
= 16¶ Only used for parsing
-
simpletal.simpleTALConstants.
METAL_DEFINE_MACRO
= 17¶ Only used for parsing
-
simpletal.simpleTALConstants.
HTML4_VOID_ELEMENTS
= frozenset([u'IMG', u'AREA', u'BASEFONT', u'FRAME', u'ISINDEX', u'META', u'PARAM', u'HR', u'BASE', u'LINK', u'BR', u'INPUT', u'COL'])¶ The set of elements in HTML4 that can not have end tags
-
simpletal.simpleTALConstants.
HTML5_VOID_ELEMENTS
= frozenset([u'WBR', u'IMG', u'AREA', u'HR', u'META', u'LINK', u'KEYGEN', u'SOURCE', u'BASE', u'COMMAND', u'PARAM', u'BR', u'INPUT', u'EMBED', u'TRACK', u'COL'])¶ The set of elements in HTML5 that can not have end tags
Source: http://www.w3.org/TR/html-markup/syntax.html#void-element
-
simpletal.simpleTALConstants.
HTML_FORBIDDEN_ENDTAG
= frozenset([u'WBR', u'IMG', u'BASEFONT', u'ISINDEX', u'PARAM', u'BASE', u'LINK', u'SOURCE', u'BR', u'INPUT', u'EMBED', u'COL', u'AREA', u'TRACK', u'FRAME', u'KEYGEN', u'HR', u'META', u'COMMAND'])¶ The set of elements in HTML5 that can not have end tags
-
simpletal.simpleTALConstants.
HTML_BOOLEAN_ATTS
= frozenset([(u'SCRIPT', u'DEFER'), (u'INPUT', u'DISABLED'), (u'TEXTAREA', u'READONLY'), (u'OPTION', u'DISABLED'), (u'INPUT', u'CHECKED'), (u'OPTION', u'SELECTED'), (u'INPUT', u'READONLY'), (u'BUTTON', u'DISABLED'), (u'OPTGROUP', u'DISABLED'), (u'OBJECT', u'DECLARE'), (u'AREA', u'NOHREF'), (u'SELECT', u'DISABLED'), (u'INPUT', u'ISMAP'), (u'SELECT', u'MULTIPLE'), (u'IMG', u'ISMAP'), (u'TEXTAREA', u'DISABLED')])¶ Set of element:attribute pairs that can use minimized form in HTML
simpletal.simpleTALES module¶
simpleTALES Implementation
The classes in this module implement the TALES specification, used by the simpleTAL module.
-
exception
simpletal.simpleTALES.
ContextContentException
[source]¶ Bases:
exceptions.Exception
This is raised when invalid content has been placed into the Context object. For example using non-ascii characters instead of Unicode strings.
-
exception
simpletal.simpleTALES.
RepeatVariable
(sequence)[source]¶ Bases:
simpletal.simpleTALES.ContextVariable
To be written
-
exception
simpletal.simpleTALES.
PathFunctionVariable
(func)[source]¶ Bases:
simpletal.simpleTALES.ContextVariable
This class wraps a callable object (e.g. function) so that it can receive part of a TAL path as it’s argument.
To use this simply create a new instance of the PathFunctionVariable and then place this into the Context (see above). The path passed to the function is that part of the path not already used. For example if the function “helloFunc” is placed in the Context the path “helloFunc/an/example” results in the string “an/example” being passed to the function.
-
exception
simpletal.simpleTALES.
CachedFuncResult
(value=None)[source]¶ Bases:
simpletal.simpleTALES.ContextVariable
This class wraps a callable object (e.g. function) so that the callable is only called once.
In normal SimpleTAL operation any function placed into a Context might be called multiple times during template expansion. To ensure that it is only called once simply wrap in the CachedFuncResult object first.
simpletal.simpleTALUtils module¶
simpleTALUtils
This module is holds utilities that make using SimpleTAL easier. Initially this is just the HTMLStructureCleaner class, used to clean up HTML that can then be used as ‘structure’ content.
-
class
simpletal.simpleTALUtils.
TemplateCache
[source]¶ Bases:
object
A TemplateCache is a multi-thread safe object that caches compiled templates. This cache only works with file based templates, the ctime of the file is checked on each hit, if the file has changed the template is re-compiled.
-
getTemplate
(name, inputEncoding='UTF-8-SIG')[source]¶ Name should be the path of a template file. If self.isHTML(name) it is treated as an HTML Template, otherwise it’s treated as an XML Template. If the template file has changed since the last cache it will be re-compiled.
inputEncoding is only used for HTML templates, and should be the encoding that the template is stored in.
-
-
class
simpletal.simpleTALUtils.
TemplateRoot
(rootPath, loadFunc, templateExt='.html')[source]¶ Bases:
object
-
simpletal.simpleTALUtils.
expandMacros
(context, template, outputFile, outputEncoding='utf-8')[source]¶ This function can be used to expand a template which contains METAL macros, while leaving in place all the TAL and METAL commands.
Doing this makes editing a template which uses METAL macros easier, because the results of the macro can be seen immediately. The macros referred to by the passed in template must be present in the context so that their contents can be referenced. The outputEncoding determines the encoding of the returned string, which will contain the expanded macro.