<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>[code_template] </title> <meta content="text/html;charset=ISO-8859-1" name="Content-Type"/> <link href="../style.css" media="screen" rel="stylesheet" type="text/css"/></head> <body> <div><a href="http://codespeak.net"><img alt="py lib" height="114" id="pyimg" src="http://codespeak.net/img/pylib.png" width="154"/></a></div> <div id="metaspace"> <div class="project_title">[code_template] </div> <div id="menubar"><a class="menu" href="../index.html">index</a> <a class="menu" href="../../../apigen/api/index.html">api</a> <a class="menu" href="../../../apigen/source/index.html">source</a> <a class="menu" href="../contact.html">contact</a> <a class="menu" href="../download.html">download</a></div></div> <div id="contentspace"> <div id="docinfoline"> <div style="float: right; font-style: italic;"> </div></div> <div class="document" id="py-code-template-lightweight-and-flexible-code-template-system"> <h1 class="title">py.code_template: Lightweight and flexible code template system</h1> <div class="contents topic" id="contents"> <p class="topic-title first">Contents</p> <ul class="auto-toc simple"> <li><a class="reference internal" href="#motivation" id="id1">1 Motivation</a></li> <li><a class="reference internal" href="#imaginary-world-examples" id="id2">2 Imaginary-world examples</a><ul class="auto-toc"> <li><a class="reference internal" href="#translator-c-genc-py" id="id3">2.1 translator/c/genc.py</a></li> <li><a class="reference internal" href="#translator-c-genc-py-gen-makefile" id="id4">2.2 translator/c/genc.py gen_makefile</a></li> <li><a class="reference internal" href="#translator-llvm-module-excsupport-py" id="id5">2.3 translator/llvm/module/excsupport.py</a></li> </ul> </li> <li><a class="reference internal" href="#template-syntax" id="id6">3 Template syntax</a><ul class="auto-toc"> <li><a class="reference internal" href="#design-decision" id="id7">3.1 Design decision</a></li> <li><a class="reference internal" href="#elements" id="id8">3.2 Elements</a><ul class="auto-toc"> <li><a class="reference internal" href="#keyword-element" id="id9">3.2.1 Keyword element</a></li> <li><a class="reference internal" href="#keyword" id="id10">3.2.2 Keyword</a></li> <li><a class="reference internal" href="#left-brace" id="id11">3.2.3 Left brace</a></li> <li><a class="reference internal" href="#normal-text" id="id12">3.2.4 Normal Text</a></li> <li><a class="reference internal" href="#comment" id="id13">3.2.5 Comment</a></li> <li><a class="reference internal" href="#substituted-expression" id="id14">3.2.6 Substituted expression</a></li> <li><a class="reference internal" href="#conditional-text" id="id15">3.2.7 Conditional text</a></li> <li><a class="reference internal" href="#repeated-text" id="id16">3.2.8 Repeated text</a></li> </ul> </li> <li><a class="reference internal" href="#whitespace-removal-or-modification" id="id17">3.3 Whitespace removal or modification</a><ul class="auto-toc"> <li><a class="reference internal" href="#line-separators" id="id18">3.3.1 Line separators</a></li> <li><a class="reference internal" href="#beginning-or-end-of-string" id="id19">3.3.2 Beginning or end of string</a></li> <li><a class="reference internal" href="#a-comment-or-single-keyword-element-on-a-line" id="id20">3.3.3 A comment or single keyword element on a line</a></li> </ul> </li> </ul> </li> <li><a class="reference internal" href="#template-usage" id="id21">4 Template usage</a></li> <li><a class="reference internal" href="#template-instantiation-and-methods" id="id22">5 Template instantiation and methods</a><ul class="auto-toc"> <li><a class="reference internal" href="#template-open" id="id23">5.1 template.open</a></li> <li><a class="reference internal" href="#template-close" id="id24">5.2 template.close</a></li> <li><a class="reference internal" href="#template-write" id="id25">5.3 template.write</a></li> <li><a class="reference internal" href="#template-read" id="id26">5.4 template.read</a></li> <li><a class="reference internal" href="#template-output" id="id27">5.5 template.output</a></li> </ul> </li> <li><a class="reference internal" href="#caching-and-thread-safety" id="id28">6 Caching and thread safety</a></li> </ul> </div> <div class="section" id="motivation"> <h1><a class="toc-backref" href="#id1">1 Motivation</a></h1> <p>There are as many python templating systems as there are web frameworks (a lot). This is partly because it is so darned easy to write a templating system in Python. What are the distinguishing characteristics of the py.code_template templating system?</p> <blockquote> <ul> <li><p class="first">Optimized for generating code (Python, C, bash scripts, etc.), not XML or HTML</p> </li> <li><p class="first">Designed for use by Python programmers, not by web artists</p> <blockquote> <ul> <li><p class="first">Aesthetic sensibilities are different</p> </li> <li><p class="first">The templates should be an organic part of a module -- just more code</p> </li> <li><p class="first">Templates do not need to be incredibly full-featured, because programmers are perfectly capable of escaping to Python for advanced features.</p> <blockquote> <ul class="simple"> <li>No requirement to support inheritance</li> <li>No requirement to support exec</li> </ul> </blockquote> </li> </ul> </blockquote> </li> <li><p class="first">Designed so that templates can be coded in the most natural way for the task at hand</p> <blockquote> <ul class="simple"> <li>Generation of code and scripts often does not follow MVC paradigm!</li> <li>Small template fragments are typically coded <em>inside</em> Python modules</li> <li>Sometimes it is natural to put strings inside code; sometimes it is natural to put code inside strings. Both should be supported as reasonably and naturally as possible.</li> </ul> </blockquote> </li> </ul> </blockquote> </div> <div class="section" id="imaginary-world-examples"> <h1><a class="toc-backref" href="#id2">2 Imaginary-world examples</a></h1> <p>These would be real-world examples, but, not only is this module not yet implemented, as of now, PyPy is not incredibly useful to the average programmer...</p> <div class="section" id="translator-c-genc-py"> <h2><a class="toc-backref" href="#id3">2.1 translator/c/genc.py</a></h2> <p>The original function:</p> <pre class="literal-block"> def gen_readable_parts_of_main_c_file(f, database, preimplementationlines=[]): # # All declarations # structdeflist = database.getstructdeflist() print >> f print >> f, '/***********************************************************/' print >> f, '/*** Structure definitions ***/' print >> f for node in structdeflist: print >> f, 'struct %s;' % node.name print >> f for node in structdeflist: for line in node.definition(): print >> f, line print >> f print >> f, '/***********************************************************/' print >> f, '/*** Forward declarations ***/' print >> f for node in database.globalcontainers(): for line in node.forward_declaration(): print >> f, line # # Implementation of functions and global structures and arrays # print >> f print >> f, '/***********************************************************/' print >> f, '/*** Implementations ***/' print >> f for line in preimplementationlines: print >> f, line print >> f, '#include "src/g_include.h"' print >> f blank = True for node in database.globalcontainers(): if blank: print >> f blank = False for line in node.implementation(): print >> f, line blank = True </pre> <p>This could be refactored heavily. An initial starting point would look something like this, although later, the template instance could be passed in and reused directly, rather than passing the file handle around:</p> <pre class="literal-block"> def gen_readable_parts_of_main_c_file(f, database, preimplementationlines=[]): def container_implementation(): # Helper function designed to introduce blank lines # between container implementations blank = True for node in database.globalcontainers(): if blank: yield '' blank = False for line in node.implementation(): yield line blank = True t = code_template.Template() # # All declarations # structdeflist = database.getstructdeflist() t.write(dedent=8, text=''' /***********************************************************/ /*** Structure definitions ***/ {for node in structdeflist} struct {node.name}; {endfor} {for node in structdeflist} {for line in node.definition} {line} {endfor} {endfor} /***********************************************************/ /*** Forward declarations ***/ {for node in database.globalcontainers()} {for line in node.forward_declaration()} {line} {endfor} {endfor} {** ** Implementation of functions and global structures and arrays **} /***********************************************************/ /*** Implementations ***/ {for line in preimplementationlines} {line} {endfor} #include "src/g_include.h" {for line in container_implementation()} {line} {endfor} """) t.output(f) </pre> </div> <div class="section" id="translator-c-genc-py-gen-makefile"> <h2><a class="toc-backref" href="#id4">2.2 translator/c/genc.py gen_makefile</a></h2> <p>The original code:</p> <pre class="literal-block"> MAKEFILE = ''' CC = gcc $(TARGET): $(OBJECTS) \t$(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(LIBDIRS) $(LIBS) %.o: %.c \t$(CC) $(CFLAGS) -o $@ -c $< $(INCLUDEDIRS) clean: \trm -f $(OBJECTS) ''' def gen_makefile(self, targetdir): def write_list(lst, prefix): for i, fn in enumerate(lst): print >> f, prefix, fn, if i < len(lst)-1: print >> f, '\\' else: print >> f prefix = ' ' * len(prefix) compiler = self.getccompiler(extra_includes=['.']) cfiles = [] ofiles = [] for fn in compiler.cfilenames: fn = py.path.local(fn).basename assert fn.endswith('.c') cfiles.append(fn) ofiles.append(fn[:-2] + '.o') f = targetdir.join('Makefile').open('w') print >> f, '# automatically generated Makefile' print >> f print >> f, 'TARGET =', py.path.local(compiler.outputfilename).basename print >> f write_list(cfiles, 'SOURCES =') print >> f write_list(ofiles, 'OBJECTS =') print >> f args = ['-l'+libname for libname in compiler.libraries] print >> f, 'LIBS =', ' '.join(args) args = ['-L'+path for path in compiler.library_dirs] print >> f, 'LIBDIRS =', ' '.join(args) args = ['-I'+path for path in compiler.include_dirs] write_list(args, 'INCLUDEDIRS =') print >> f print >> f, 'CFLAGS =', ' '.join(compiler.compile_extra) print >> f, 'LDFLAGS =', ' '.join(compiler.link_extra) print >> f, MAKEFILE.strip() f.close() </pre> <p>Could look something like this:</p> <pre class="literal-block"> MAKEFILE = ''' # automatically generated Makefile TARGET = {py.path.local(compiler.outputfilename).basename} {for line in write_list(cfiles, 'SOURCES =')} {line} {endfor} {for line in write_list(ofiles, 'OBJECTS =')} {line} {endfor} LIBS ={for libname in compiler.libraries} -l{libname}{endfor} LIBDIRS ={for path in compiler.library_dirs} -L{path}{endfor} INCLUDEDIRS ={for path in compiler.include_dirs} -I{path}{endfor} CFLAGS ={for extra in compiler.compile_extra} {extra}{endfor} LDFLAGS ={for extra in compiler.link_extra} {extra}{endfor} CC = gcc $(TARGET): $(OBJECTS) \t$(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(LIBDIRS) $(LIBS) %.o: %.c \t$(CC) $(CFLAGS) -o $@ -c $< $(INCLUDEDIRS) clean: \trm -f $(OBJECTS) ''' def gen_makefile(self, targetdir): def write_list(lst, prefix): for i, fn in enumerate(lst): yield '%s %s %s' % (prefix, fn, i < len(list)-1 and '\\' or '') prefix = ' ' * len(prefix) compiler = self.getccompiler(extra_includes=['.']) cfiles = [] ofiles = [] for fn in compiler.cfilenames: fn = py.path.local(fn).basename assert fn.endswith('.c') cfiles.append(fn) ofiles.append(fn[:-2] + '.o') code_template.Template(MAKEFILE).output(targetdir.join('Makefile')) </pre> </div> <div class="section" id="translator-llvm-module-excsupport-py"> <h2><a class="toc-backref" href="#id5">2.3 translator/llvm/module/excsupport.py</a></h2> <p>The original string:</p> <pre class="literal-block"> invokeunwind_code = ''' ccc %(returntype)s%%__entrypoint__%(entrypointname)s { %%result = invoke %(cconv)s %(returntype)s%%%(entrypointname)s to label %%no_exception except label %%exception no_exception: store %%RPYTHON_EXCEPTION_VTABLE* null, %%RPYTHON_EXCEPTION_VTABLE** %%last_exception_type ret %(returntype)s %%result exception: ret %(noresult)s } ccc int %%__entrypoint__raised_LLVMException() { %%tmp = load %%RPYTHON_EXCEPTION_VTABLE** %%last_exception_type %%result = cast %%RPYTHON_EXCEPTION_VTABLE* %%tmp to int ret int %%result } internal fastcc void %%unwind() { unwind } ''' </pre> <p>Could look something like this if it was used in conjunction with a template:</p> <pre class="literal-block"> invokeunwind_code = ''' ccc {returntype}%__entrypoint__{entrypointname} { %result = invoke {cconv} {returntype}%{entrypointname} to label %no_exception except label %exception no_exception: store %RPYTHON_EXCEPTION_VTABLE* null, %RPYTHON_EXCEPTION_VTABLE** %last_exception_type ret {returntype} %result exception: ret {noresult} } ccc int %__entrypoint__raised_LLVMException() { %tmp = load %RPYTHON_EXCEPTION_VTABLE** %last_exception_type %result = cast %RPYTHON_EXCEPTION_VTABLE* %tmp to int ret int %result } internal fastcc void %unwind() { unwind } ''' </pre> </div> </div> <div class="section" id="template-syntax"> <h1><a class="toc-backref" href="#id6">3 Template syntax</a></h1> <div class="section" id="design-decision"> <h2><a class="toc-backref" href="#id7">3.1 Design decision</a></h2> <p>As all programmers must know by now, all the special symbols on the keyboard are quite heavily overloaded. Often, template systems work around this fact by having special notation like <cite><*</cite> ... <cite>*></cite> or {% ... %}. Some template systems even have multiple special notations -- one for comments, one for statements, one for expressions, etc.</p> <p>I find these hard to type and ugly. Other markups are either too lightweight, or use characters which occur so frequently in the target languages that it becomes hard to distinguish marked-up content from content which should be rendered as-is.</p> <p>The compromise taken by <em>code_template</em> is to use braces (<strong>{}</strong>) for markup.</p> <p>This immediately raises the question: what about when the marked-up language is C or C++? The answer is that if the leading brace is immediately followed by whitespace, it is normal text; if not it is the start of markup.</p> <p>To support normal text which has a leading brace immediately followed by an identifier, if the first whitespace character after the brace is a space character (e.g. not a newline or tab), it will be removed from the output.</p> <p>Examples:</p> <pre class="literal-block"> { This is normal text and the space between { and This will be removed} {'this must be a valid Python expression' + ' because it is treated as markup'} { This is normal text, but nothing is altered (the newline is kept intact) } {{1:'Any valid Python expression is allowed as markup'}[1].ljust(30)} </pre> </div> <div class="section" id="elements"> <span id="code-element"></span><h2><a class="toc-backref" href="#id8">3.2 Elements</a></h2> <p>Templates consist of normal text and code elements. (Comments are considered to be code elements.)</p> <p>All code elements start with a <a class="reference internal" href="#left-brace">left brace</a> which is not followed by whitespace.</p> <div class="section" id="keyword-element"> <h3><a class="toc-backref" href="#id9">3.2.1 Keyword element</a></h3> <p>A keyword element is a <a class="reference internal" href="#code-element">code element</a> which starts with a <a class="reference internal" href="#keyword">keyword</a>.</p> <p>For example, <em>{if foo}</em> is a keyword element, but <em>{foo}</em> is a <a class="reference internal" href="#substituted-expression">substituted expression</a>.</p> </div> <div class="section" id="keyword"> <h3><a class="toc-backref" href="#id10">3.2.2 Keyword</a></h3> <p>A keyword is a word used in <a class="reference internal" href="#conditional-text">conditional text</a> or in <a class="reference internal" href="#repeated-text">repeated text</a>, e.g. one of <em>if</em>, <em>elif</em>, <em>else</em>, <em>endif</em>, <em>for</em>, or <em>endfor</em>.</p> <p>Keywords are designed to match their Python equivalents. However, since templates cannot use spacing to indicate expression nesting, the additional keywords <em>endif</em> and <em>endfor</em> are required.</p> </div> <div class="section" id="left-brace"> <h3><a class="toc-backref" href="#id11">3.2.3 Left brace</a></h3> <p>All elements other than normal text start with a left brace -- the symbol '{', sometimes known as a 'curly bracket'. A left brace is itself considered to be normal text if it is followed by whitespace. If the whitespace starts with a space character, that space character will be stripped from the output. If the whitespace starts with a tab or linefeed character, the whitespace will be left in the output.</p> </div> <div class="section" id="normal-text"> <h3><a class="toc-backref" href="#id12">3.2.4 Normal Text</a></h3> <p>Normal text remains unsubstituted. Transition from text to the other elements is effected by use of a <a class="reference internal" href="#left-brace">left brace</a> which is not followed by whitespace.</p> </div> <div class="section" id="comment"> <h3><a class="toc-backref" href="#id13">3.2.5 Comment</a></h3> <p>A comment starts with a left brace followed by an asterisk ('{<cite>*</cite>'), and ends with an asterisk followed by a right brace ('<cite>*</cite>}'):</p> <pre class="literal-block"> This is a template -- this text will be copied to the output. {* This is a comment and this text will not be copied to the output *} {* Comments can span lines, but cannot be nested *} </pre> </div> <div class="section" id="substituted-expression"> <h3><a class="toc-backref" href="#id14">3.2.6 Substituted expression</a></h3> <p>Any python expression may be used:</p> <pre class="literal-block"> Dear {record.name}, we are sorry to inform you that you did not win {record.contest}. </pre> <p>The expression must be surrounded by braces, and there must not be any whitespace between the leftmost brace and the start of the expression.</p> <p>The expression will automatically be converted to a string with str().</p> </div> <div class="section" id="conditional-text"> <h3><a class="toc-backref" href="#id15">3.2.7 Conditional text</a></h3> <p>The following template has text which is included conditionally:</p> <pre class="literal-block"> This text will always be included in the output {if foo} This text will be included if foo is true {elif bar} This text will be included if foo is not true but bar is true {else} This text will be included if neither foo nor bar is true {endif} </pre> <p>The {elif} and {else} elements are optional.</p> </div> <div class="section" id="repeated-text"> <h3><a class="toc-backref" href="#id16">3.2.8 Repeated text</a></h3> <p>The following template shows how to pull multiple items out of a list:</p> <pre class="literal-block"> {for student, score in sorted(scorelist)} {student.ljust(20)} {score} {endfor} </pre> </div> </div> <div class="section" id="whitespace-removal-or-modification"> <h2><a class="toc-backref" href="#id17">3.3 Whitespace removal or modification</a></h2> <p>In general, whitespace in <a class="reference internal" href="#normal-text">Normal Text</a> is transferred unchanged to the output. There are three exceptions to this rule:</p> <div class="section" id="line-separators"> <h3><a class="toc-backref" href="#id18">3.3.1 Line separators</a></h3> <p>Each newline is converted to the final output using os.linesep.</p> </div> <div class="section" id="beginning-or-end-of-string"> <h3><a class="toc-backref" href="#id19">3.3.2 Beginning or end of string</a></h3> <p>py.code_template is designed to allow easy use of templates inside of python modules. The canonical way to write a template is inside a triple-quoted string, e.g.:</p> <pre class="literal-block"> my_template = ''' This is my template. It can have any text at all in it except another triple-single-quote. ''' </pre> <p>To support this usage, if the first character is a newline, it will be removed, and if the last line consists solely of whitespace with no trailing newline, it will also be removed.</p> </div> <div class="section" id="a-comment-or-single-keyword-element-on-a-line"> <h3><a class="toc-backref" href="#id20">3.3.3 A comment or single keyword element on a line</a></h3> <p>Whenever a <a class="reference internal" href="#keyword-element">keyword element</a> or <a class="reference internal" href="#comment">comment</a> is on a line <em>by itself</em>, that line will not be copied to the output.</p> <dl class="docutils"> <dt>This happens when:</dt> <dd><ul class="first last simple"> <li>There is nothing on the line before the keyword element or comment except whitespace (spaces and/or tabs).</li> <li>There is nothing on the line after the keyword element or comment except a newline.</li> </ul> </dd> </dl> <p>Note that even a multi-line comment or keyword element can have the preceding whitespace and subsequent newline stripped by this rule.</p> <p>The primary purpose of this rule is to allow the Python programmer to use indentation, <strong>even inside a template</strong>:</p> <pre class="literal-block"> This is a template {if mylist} List items: {for item in mylist} - {item} {endfor} {endif} </pre> </div> </div> </div> <div class="section" id="template-usage"> <h1><a class="toc-backref" href="#id21">4 Template usage</a></h1> <p>Templates are used by importing the Template class from py.code_template, constructing a template, and then sending data with the write() method.</p> <p>In general, there are four methods for getting the formatted data back out of the template object:</p> <blockquote> <ul> <li><p class="first">read() reads all the data currently in the object</p> </li> <li><p class="first">output(fobj) outputs the data to a file</p> <blockquote> <p>fobj can either be an open file object, or a string. If it is a string, the file will be opened, written, and closed.</p> </blockquote> </li> <li><p class="first">open(fobj) (or calling the object constructor with a file object)</p> <blockquote> <p>If the open() method is used, or if a file object is passed to the constructor, each write() will automatically flush the data out to the file. If the fobj is a string, it is considered to be <em>owned</em>, otherwise it is considered to be <em>borrowed</em>. <em>Owned</em> file objects are closed when the class is deleted.</p> </blockquote> </li> <li><p class="first">write() can be explicitly called with a file object, in which case it will invoke output() on that object after it generates the data.</p> </li> </ul> </blockquote> </div> <div class="section" id="template-instantiation-and-methods"> <h1><a class="toc-backref" href="#id22">5 Template instantiation and methods</a></h1> <p>template = code_template.Template(outf=None, cache=None)</p> <p>If outf is given, it will be passed to the open() method</p> <p>cache may be given as a mapping. If not given, the template will use the shared default cache. This is not thread safe.</p> <div class="section" id="template-open"> <h2><a class="toc-backref" href="#id23">5.1 template.open</a></h2> <p>template.open(outf, borrowed = None)</p> <p>The open method closes the internal file object if it was already open, and then re-opens it on the given file. It is an error to call open() if there is data in the object left over from previous writes. (Call output() instead.)</p> <p>borrowed defaults to 0 if outf is a string, and 1 if it is a file object.</p> <p>borrowed can also be set explicitly if required.</p> </div> <div class="section" id="template-close"> <h2><a class="toc-backref" href="#id24">5.2 template.close</a></h2> <p>close() disassociates the file from the template, and closes the file if it was not borrowed. close() is automatically called by the destructor.</p> </div> <div class="section" id="template-write"> <h2><a class="toc-backref" href="#id25">5.3 template.write</a></h2> <p>template.write(text='', outf=None, dedent=0, localvars=None, globalvars=None, framelevel=1)</p> <p>The write method has the following parameters:</p> <blockquote> <ul class="simple"> <li>text is the template itself</li> <li>if outf is not None, the output method will be invoked on the object after the current template is processed. If no outf is given, data will be accumulated internal to the instance until a write() with outf is processed, or read() or output() is called, whichever comes first, if there is no file object. If there is a file object, data will be flushed to the file after every write.</li> <li>dedent, if given is applied to each line in the template, to "de-indent"</li> <li>localvars and globalvars default to the dictionaries of the caller. A copy of localvars is made so that the __TrueSpace__ identifier can be added.</li> <li>cache may be given as a mapping. If not given, the template will use the shared default cache. This is not thread safe.</li> <li>framelevel is used to determine which stackframe to access for globals and locals if localvars and/or globalvars are not specified. The default is to use the caller's frame.</li> </ul> </blockquote> <p>The write method supports the print >> file protocol by deleting the softspace attribute on every invocation. This allows code like:</p> <pre class="literal-block"> t = code_template.Template() print >> t, "Hello, world" </pre> </div> <div class="section" id="template-read"> <h2><a class="toc-backref" href="#id26">5.4 template.read</a></h2> <p>This method reads and flushes all accumulated data in the object. Note that if a file has been associated with the object, there will never be any data to read.</p> </div> <div class="section" id="template-output"> <h2><a class="toc-backref" href="#id27">5.5 template.output</a></h2> <p>This method takes one parameter, outf. template.output() first invokes template.read() to read and flush all accumulated data, and then outputs the data to the file specified by outf.</p> <p>If outf has a write() method, that will be invoked with the data. If outf has no write() method, it will be treated as a filename, and that file will be replaced.</p> </div> </div> <div class="section" id="caching-and-thread-safety"> <h1><a class="toc-backref" href="#id28">6 Caching and thread safety</a></h1> <p>The compiled version of every template is cached internal to the code_template module (unless a separate cache object is specified).</p> <p>This allows efficient template reuse, but is not currently thread-safe. Alternatively, each invocation of a template object can specify a cache object. This is thread-safe, but not very efficient. A shared model could be implemented later.</p> </div> </div> </div></body></html>