Edgewall Software

genshi.template.interpolation

String interpolation routines, i.e. the splitting up a given text into some parts that are literal strings, and others that are Python expressions.

interpolate(text, basedir=None, filename=None, lineno=1, offset=0, lookup='lenient')

Parse the given string and extract expressions.

This function is a generator that yields TEXT events for literal strings, and EXPR events for expressions, depending on the results of parsing the string.

>>> for kind, data, pos in interpolate("hey ${foo}bar"):
...     print kind, `data`
TEXT u'hey '
EXPR Expression('foo')
TEXT u'bar'
param text:the text to parse
param basedir:base directory of the file in which the text was found (optional)
param filename:basename of the file in which the text was found (optional)
param lineno:the line number at which the text was found (optional)
param offset:the column number at which the text starts in the source (optional)
param lookup:the variable lookup mechanism; either "lenient" (the default), "strict", or a custom lookup class
return:a list of TEXT and EXPR events
raise TemplateSyntaxError:
 when a syntax error in an expression is encountered

lex(text, textpos, filepath)

(Not documented)


See ApiDocs, Documentation

Last modified 9 years ago Last modified on Dec 10, 2015, 6:15:05 AM