|
@@ -30,7 +30,7 @@
|
|
|
|
|
|
|
|
<h1>Mako Documentation</h1>
|
|
<h1>Mako Documentation</h1>
|
|
|
|
|
|
|
|
-<div class="versionheader">Version: 0.3.3 Last Updated: 05/31/10 16:21:29</div>
|
|
|
|
|
|
|
+<div class="versionheader">Version: 0.3.4 Last Updated: 06/22/10 17:39:23</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -689,7 +689,7 @@
|
|
|
|
|
|
|
|
<div class="code">
|
|
<div class="code">
|
|
|
<div class="highlight"><pre><span class="n">mylookup</span> <span class="o">=</span> <span class="n">TemplateLookup</span><span class="p">(</span><span class="n">directories</span><span class="o">=</span><span class="p">[</span><span class="s">'/docs'</span><span class="p">],</span>
|
|
<div class="highlight"><pre><span class="n">mylookup</span> <span class="o">=</span> <span class="n">TemplateLookup</span><span class="p">(</span><span class="n">directories</span><span class="o">=</span><span class="p">[</span><span class="s">'/docs'</span><span class="p">],</span>
|
|
|
- <span class="n">module_directory</span><span class="o">=</span><span class="s">'/tmp/mako_modules'</span><span class="p">,</span> <span class="n">collection_size</span><span class="o">=</span><span class="mf">500</span><span class="p">)</span>
|
|
|
|
|
|
|
+ <span class="n">module_directory</span><span class="o">=</span><span class="s">'/tmp/mako_modules'</span><span class="p">,</span> <span class="n">collection_size</span><span class="o">=</span><span class="mi">500</span><span class="p">)</span>
|
|
|
</pre></div>
|
|
</pre></div>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
@@ -1152,7 +1152,7 @@ msgstr ""
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="code">
|
|
<div class="code">
|
|
|
- <div class="highlight"><pre>pythagorean theorem: <span class="cp">${</span><span class="nb">pow</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="mf">2</span><span class="p">)</span> <span class="o">+</span> <span class="nb">pow</span><span class="p">(</span><span class="n">y</span><span class="p">,</span><span class="mf">2</span><span class="p">)</span><span class="cp">}</span>
|
|
|
|
|
|
|
+ <div class="highlight"><pre>pythagorean theorem: <span class="cp">${</span><span class="nb">pow</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="nb">pow</span><span class="p">(</span><span class="n">y</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span><span class="cp">}</span>
|
|
|
</pre></div>
|
|
</pre></div>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
@@ -1215,7 +1215,7 @@ msgstr ""
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="code">
|
|
<div class="code">
|
|
|
- <div class="highlight"><pre><span class="cp">%</span> <span class="k">if</span> <span class="n">x</span><span class="o">==</span><span class="mf">5</span><span class="p">:</span>
|
|
|
|
|
|
|
+ <div class="highlight"><pre><span class="cp">%</span> <span class="k">if</span> <span class="n">x</span><span class="o">==</span><span class="mi">5</span><span class="p">:</span>
|
|
|
this is some output
|
|
this is some output
|
|
|
<span class="cp">%</span><span class="k"> endif</span>
|
|
<span class="cp">%</span><span class="k"> endif</span>
|
|
|
</pre></div>
|
|
</pre></div>
|
|
@@ -1229,9 +1229,9 @@ msgstr ""
|
|
|
|
|
|
|
|
<div class="code">
|
|
<div class="code">
|
|
|
<div class="highlight"><pre><span class="cp">%</span> <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="p">[</span><span class="s">'one'</span><span class="p">,</span> <span class="s">'two'</span><span class="p">,</span> <span class="s">'three'</span><span class="p">,</span> <span class="s">'four'</span><span class="p">,</span> <span class="s">'five'</span><span class="p">]:</span>
|
|
<div class="highlight"><pre><span class="cp">%</span> <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="p">[</span><span class="s">'one'</span><span class="p">,</span> <span class="s">'two'</span><span class="p">,</span> <span class="s">'three'</span><span class="p">,</span> <span class="s">'four'</span><span class="p">,</span> <span class="s">'five'</span><span class="p">]:</span>
|
|
|
- <span class="cp">%</span> <span class="k">if</span> <span class="n">a</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span> <span class="o">==</span> <span class="s">'t'</span><span class="p">:</span>
|
|
|
|
|
|
|
+ <span class="cp">%</span> <span class="k">if</span> <span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s">'t'</span><span class="p">:</span>
|
|
|
its two or three
|
|
its two or three
|
|
|
- <span class="cp">%</span> <span class="k">elif</span> <span class="n">a</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span> <span class="o">==</span> <span class="s">'f'</span><span class="p">:</span>
|
|
|
|
|
|
|
+ <span class="cp">%</span> <span class="k">elif</span> <span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s">'f'</span><span class="p">:</span>
|
|
|
four/five
|
|
four/five
|
|
|
<span class="cp">%</span> <span class="k">else</span><span class="p">:</span>
|
|
<span class="cp">%</span> <span class="k">else</span><span class="p">:</span>
|
|
|
one
|
|
one
|
|
@@ -1366,7 +1366,7 @@ another line.
|
|
|
<div class="highlight"><pre>this is a template
|
|
<div class="highlight"><pre>this is a template
|
|
|
<span class="cp"><%</span>
|
|
<span class="cp"><%</span>
|
|
|
<span class="n">x</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">get_resource</span><span class="p">(</span><span class="s">'foo'</span><span class="p">)</span>
|
|
<span class="n">x</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">get_resource</span><span class="p">(</span><span class="s">'foo'</span><span class="p">)</span>
|
|
|
- <span class="n">y</span> <span class="o">=</span> <span class="p">[</span><span class="n">z</span><span class="o">.</span><span class="n">element</span> <span class="k">for</span> <span class="n">z</span> <span class="ow">in</span> <span class="n">x</span> <span class="k">if</span> <span class="n">x</span><span class="o">.</span><span class="n">frobnizzle</span><span class="o">==</span><span class="mf">5</span><span class="p">]</span>
|
|
|
|
|
|
|
+ <span class="n">y</span> <span class="o">=</span> <span class="p">[</span><span class="n">z</span><span class="o">.</span><span class="n">element</span> <span class="k">for</span> <span class="n">z</span> <span class="ow">in</span> <span class="n">x</span> <span class="k">if</span> <span class="n">x</span><span class="o">.</span><span class="n">frobnizzle</span><span class="o">==</span><span class="mi">5</span><span class="p">]</span>
|
|
|
<span class="cp">%></span>
|
|
<span class="cp">%></span>
|
|
|
<span class="cp">%</span> <span class="k">for</span> <span class="n">elem</span> <span class="ow">in</span> <span class="n">y</span><span class="p">:</span>
|
|
<span class="cp">%</span> <span class="k">for</span> <span class="n">elem</span> <span class="ow">in</span> <span class="n">y</span><span class="p">:</span>
|
|
|
element: <span class="cp">${</span><span class="n">elem</span><span class="cp">}</span>
|
|
element: <span class="cp">${</span><span class="n">elem</span><span class="cp">}</span>
|
|
@@ -1569,7 +1569,7 @@ another line.
|
|
|
this is myfunc, x is <span class="cp">${</span><span class="n">x</span><span class="cp">}</span>
|
|
this is myfunc, x is <span class="cp">${</span><span class="n">x</span><span class="cp">}</span>
|
|
|
<span class="cp"></%</span><span class="nb">def</span><span class="cp">></span>
|
|
<span class="cp"></%</span><span class="nb">def</span><span class="cp">></span>
|
|
|
|
|
|
|
|
-<span class="cp">${</span><span class="n">myfunc</span><span class="p">(</span><span class="mf">7</span><span class="p">)</span><span class="cp">}</span>
|
|
|
|
|
|
|
+<span class="cp">${</span><span class="n">myfunc</span><span class="p">(</span><span class="mi">7</span><span class="p">)</span><span class="cp">}</span>
|
|
|
</pre></div>
|
|
</pre></div>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
@@ -1958,7 +1958,7 @@ another line.
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="code">
|
|
<div class="code">
|
|
|
- <div class="highlight"><pre><span class="cp">${</span><span class="n">mystuff</span><span class="o">.</span><span class="n">somedef</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="mf">5</span><span class="p">,</span><span class="n">y</span><span class="o">=</span><span class="mf">7</span><span class="p">)</span><span class="cp">}</span>
|
|
|
|
|
|
|
+ <div class="highlight"><pre><span class="cp">${</span><span class="n">mystuff</span><span class="o">.</span><span class="n">somedef</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span><span class="n">y</span><span class="o">=</span><span class="mi">7</span><span class="p">)</span><span class="cp">}</span>
|
|
|
</pre></div>
|
|
</pre></div>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
@@ -2060,11 +2060,11 @@ another line.
|
|
|
|
|
|
|
|
<div class="code">
|
|
<div class="code">
|
|
|
<div class="highlight"><pre><span class="cp"><%</span>
|
|
<div class="highlight"><pre><span class="cp"><%</span>
|
|
|
- <span class="n">x</span> <span class="o">=</span> <span class="mf">12</span>
|
|
|
|
|
|
|
+ <span class="n">x</span> <span class="o">=</span> <span class="mi">12</span>
|
|
|
<span class="cp">%></span>
|
|
<span class="cp">%></span>
|
|
|
<span class="cp"><%</span><span class="nb">def</span> <span class="na">name=</span><span class="s">"outer()"</span><span class="cp">></span>
|
|
<span class="cp"><%</span><span class="nb">def</span> <span class="na">name=</span><span class="s">"outer()"</span><span class="cp">></span>
|
|
|
<span class="cp"><%</span>
|
|
<span class="cp"><%</span>
|
|
|
- <span class="n">y</span> <span class="o">=</span> <span class="mf">15</span>
|
|
|
|
|
|
|
+ <span class="n">y</span> <span class="o">=</span> <span class="mi">15</span>
|
|
|
<span class="cp">%></span>
|
|
<span class="cp">%></span>
|
|
|
<span class="cp"><%</span><span class="nb">def</span> <span class="na">name=</span><span class="s">"inner()"</span><span class="cp">></span>
|
|
<span class="cp"><%</span><span class="nb">def</span> <span class="na">name=</span><span class="s">"inner()"</span><span class="cp">></span>
|
|
|
inner, x is <span class="cp">${</span><span class="n">x</span><span class="cp">}</span>, y is <span class="cp">${</span><span class="n">y</span><span class="cp">}</span>
|
|
inner, x is <span class="cp">${</span><span class="n">x</span><span class="cp">}</span>, y is <span class="cp">${</span><span class="n">y</span><span class="cp">}</span>
|
|
@@ -2083,13 +2083,13 @@ another line.
|
|
|
|
|
|
|
|
<div class="code">
|
|
<div class="code">
|
|
|
<div class="highlight"><pre><span class="cp"><%</span>
|
|
<div class="highlight"><pre><span class="cp"><%</span>
|
|
|
- <span class="n">x</span> <span class="o">=</span> <span class="mf">10</span>
|
|
|
|
|
|
|
+ <span class="n">x</span> <span class="o">=</span> <span class="mi">10</span>
|
|
|
<span class="cp">%></span>
|
|
<span class="cp">%></span>
|
|
|
<span class="cp"><%</span><span class="nb">def</span> <span class="na">name=</span><span class="s">"somedef()"</span><span class="cp">></span>
|
|
<span class="cp"><%</span><span class="nb">def</span> <span class="na">name=</span><span class="s">"somedef()"</span><span class="cp">></span>
|
|
|
<span class="cp">## error !</span>
|
|
<span class="cp">## error !</span>
|
|
|
somedef, x is <span class="cp">${</span><span class="n">x</span><span class="cp">}</span>
|
|
somedef, x is <span class="cp">${</span><span class="n">x</span><span class="cp">}</span>
|
|
|
<span class="cp"><%</span>
|
|
<span class="cp"><%</span>
|
|
|
- <span class="n">x</span> <span class="o">=</span> <span class="mf">27</span>
|
|
|
|
|
|
|
+ <span class="n">x</span> <span class="o">=</span> <span class="mi">27</span>
|
|
|
<span class="cp">%></span>
|
|
<span class="cp">%></span>
|
|
|
<span class="cp"></%</span><span class="nb">def</span><span class="cp">></span>
|
|
<span class="cp"></%</span><span class="nb">def</span><span class="cp">></span>
|
|
|
</pre></div>
|
|
</pre></div>
|
|
@@ -2117,7 +2117,7 @@ another line.
|
|
|
|
|
|
|
|
<p>A flip-side to def within def is a def call with content. This is where you call a def, and at the same time declare a block of content (or multiple blocks) that can be used by the def being called. The main point of such a call is to create custom, nestable tags, just like any other template language's custom-tag creation system - where the external tag controls the execution of the nested tags and can communicate state to them. Only with Mako, you don't have to use any external Python modules, you can define arbitrarily nestable tags right in your templates.
|
|
<p>A flip-side to def within def is a def call with content. This is where you call a def, and at the same time declare a block of content (or multiple blocks) that can be used by the def being called. The main point of such a call is to create custom, nestable tags, just like any other template language's custom-tag creation system - where the external tag controls the execution of the nested tags and can communicate state to them. Only with Mako, you don't have to use any external Python modules, you can define arbitrarily nestable tags right in your templates.
|
|
|
</p>
|
|
</p>
|
|
|
-<p>To achieve this, the target def is invoked using the form <code><%namepacename:defname></code> instead of the normal <code>${}</code> syntax. This syntax, introduced in Mako 0.2.3, is functionally equivalent another tag known as <code>call</code>, which takes the form <code><%call expr='namespacename.defname(args)'></code>. While <code>%call</code> is available in all versions of Mako, the newer style is probably more familiar looking. The <code>namespace</code> portion of the call is the name of the <strong>namespace</strong> in which the def is defined - in the most simple cases, this can be <code>local</code> or <code>self</code> to reference the current template's namespace (the difference between <code>local</code> and <code>self</code> is one of inheritance - see <a href="#namespaces_builtin">Built-in Namespaces</a> for details).
|
|
|
|
|
|
|
+<p>To achieve this, the target def is invoked using the form <code><%namepacename:defname></code> instead of the normal <code>${}</code> syntax. This syntax, introduced in Mako 0.2.3, is functionally equivalent another tag known as <code>call</code>, which takes the form <code><%call expr='namespacename.defname(args)'></code>. While <code>%call</code> is available in all versions of Mako, the newer style is probably more familiar looking. The <code>namespace</code> portion of the call is the name of the <strong>namespace</strong> in which the def is defined - in the most simple cases, this can be <code>local</code> or <code>self</code> to reference the current template's namespace (the difference between <code>local</code> and <code>self</code> is one of inheritance - see <a href="#namespaces_builtin">Built-in Namespaces</a> for details).
|
|
|
</p>
|
|
</p>
|
|
|
<p>When the target def is invoked, a variable <code>caller</code> is placed in its context which contains another namespace containing the body and other defs defined by the caller. The body itself is referenced by the method <code>body()</code>. Below, we build a <code>%def</code> that operates upon <code>caller.body()</code> to invoke the body of the custom tag:
|
|
<p>When the target def is invoked, a variable <code>caller</code> is placed in its context which contains another namespace containing the body and other defs defined by the caller. The body itself is referenced by the method <code>body()</code>. Below, we build a <code>%def</code> that operates upon <code>caller.body()</code> to invoke the body of the custom tag:
|
|
|
</p>
|
|
</p>
|
|
@@ -2575,7 +2575,7 @@ Body data: <span class="cp">${</span><span class="n">col</span><span class="cp">
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="code">
|
|
<div class="code">
|
|
|
- <div class="highlight"><pre><span class="cp">${</span><span class="n">next</span><span class="o">.</span><span class="n">body</span><span class="p">(</span><span class="o">**</span><span class="n">context</span><span class="o">.</span><span class="n">kwargs</span><span class="p">)</span><span class="cp">}</span>
|
|
|
|
|
|
|
+ <div class="highlight"><pre><span class="cp">${</span><span class="nb">next</span><span class="o">.</span><span class="n">body</span><span class="p">(</span><span class="o">**</span><span class="n">context</span><span class="o">.</span><span class="n">kwargs</span><span class="p">)</span><span class="cp">}</span>
|
|
|
</pre></div>
|
|
</pre></div>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
@@ -2730,7 +2730,7 @@ Body data: <span class="cp">${</span><span class="n">col</span><span class="cp">
|
|
|
<span class="cp"><%</span><span class="nb">namespace</span> <span class="na">name=</span><span class="s">"comp"</span> <span class="na">file=</span><span class="s">"components.html"</span><span class="cp">/></span>
|
|
<span class="cp"><%</span><span class="nb">namespace</span> <span class="na">name=</span><span class="s">"comp"</span> <span class="na">file=</span><span class="s">"components.html"</span><span class="cp">/></span>
|
|
|
|
|
|
|
|
Heres comp1: <span class="cp">${</span><span class="n">comp</span><span class="o">.</span><span class="n">comp1</span><span class="p">()</span><span class="cp">}</span>
|
|
Heres comp1: <span class="cp">${</span><span class="n">comp</span><span class="o">.</span><span class="n">comp1</span><span class="p">()</span><span class="cp">}</span>
|
|
|
-Heres comp2: <span class="cp">${</span><span class="n">comp</span><span class="o">.</span><span class="n">comp2</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="mf">5</span><span class="p">)</span><span class="cp">}</span>
|
|
|
|
|
|
|
+Heres comp2: <span class="cp">${</span><span class="n">comp</span><span class="o">.</span><span class="n">comp2</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span><span class="cp">}</span>
|
|
|
</pre></div>
|
|
</pre></div>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
@@ -2746,7 +2746,7 @@ Heres comp2: <span class="cp">${</span><span class="n">comp</span><span class="
|
|
|
<div class="highlight"><pre><span class="cp"><%</span><span class="nb">namespace</span> <span class="na">file=</span><span class="s">"components.html"</span> <span class="na">import=</span><span class="s">"comp1, comp2"</span><span class="cp">/></span>
|
|
<div class="highlight"><pre><span class="cp"><%</span><span class="nb">namespace</span> <span class="na">file=</span><span class="s">"components.html"</span> <span class="na">import=</span><span class="s">"comp1, comp2"</span><span class="cp">/></span>
|
|
|
|
|
|
|
|
Heres comp1: <span class="cp">${</span><span class="n">comp1</span><span class="p">()</span><span class="cp">}</span>
|
|
Heres comp1: <span class="cp">${</span><span class="n">comp1</span><span class="p">()</span><span class="cp">}</span>
|
|
|
-Heres comp2: <span class="cp">${</span><span class="n">comp2</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="mf">5</span><span class="p">)</span><span class="cp">}</span>
|
|
|
|
|
|
|
+Heres comp2: <span class="cp">${</span><span class="n">comp2</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span><span class="cp">}</span>
|
|
|
</pre></div>
|
|
</pre></div>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
@@ -2760,7 +2760,7 @@ Heres comp2: <span class="cp">${</span><span class="n">comp2</span><span class=
|
|
|
<div class="highlight"><pre><span class="cp"><%</span><span class="nb">namespace</span> <span class="na">file=</span><span class="s">"components.html"</span> <span class="na">import=</span><span class="s">"*"</span><span class="cp">/></span>
|
|
<div class="highlight"><pre><span class="cp"><%</span><span class="nb">namespace</span> <span class="na">file=</span><span class="s">"components.html"</span> <span class="na">import=</span><span class="s">"*"</span><span class="cp">/></span>
|
|
|
|
|
|
|
|
Heres comp1: <span class="cp">${</span><span class="n">comp1</span><span class="p">()</span><span class="cp">}</span>
|
|
Heres comp1: <span class="cp">${</span><span class="n">comp1</span><span class="p">()</span><span class="cp">}</span>
|
|
|
-Heres comp2: <span class="cp">${</span><span class="n">comp2</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="mf">5</span><span class="p">)</span><span class="cp">}</span>
|
|
|
|
|
|
|
+Heres comp2: <span class="cp">${</span><span class="n">comp2</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span><span class="cp">}</span>
|
|
|
</pre></div>
|
|
</pre></div>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
@@ -2890,7 +2890,7 @@ Heres comp2: <span class="cp">${</span><span class="n">comp2</span><span class=
|
|
|
</pre></div>
|
|
</pre></div>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
|
-<p>Note that the <code>context</code> argument is not needed in the call; the <code>namespace</code> tag creates a locally-scoped callable which takes care of it. The <code>return ''</code> is so that the def does not dump a <code>None</code> into the output stream - the return value of any def is rendered after the def completes, in addition to whatever was passed to <code>context.write()</code> within its body.
|
|
|
|
|
|
|
+<p>Note that the <code>context</code> argument is not needed in the call; the <code>namespace</code> tag creates a locally-scoped callable which takes care of it. The <code>return ''</code> is so that the def does not dump a <code>None</code> into the output stream - the return value of any def is rendered after the def completes, in addition to whatever was passed to <code>context.write()</code> within its body.
|
|
|
</p>
|
|
</p>
|
|
|
<p>If your def is to be called in an "embedded content" context, that is as described in <a href="#defs_defswithcontent">Calling a def with embedded content and/or other defs</a>, you should use the <code>@supports_caller</code> decorator, which will ensure that Mako will ensure the correct "caller" variable is available when your def is called, supporting embedded content:
|
|
<p>If your def is to be called in an "embedded content" context, that is as described in <a href="#defs_defswithcontent">Calling a def with embedded content and/or other defs</a>, you should use the <code>@supports_caller</code> decorator, which will ensure that Mako will ensure the correct "caller" variable is available when your def is called, supporting embedded content:
|
|
|
</p>
|
|
</p>
|
|
@@ -3001,7 +3001,7 @@ Heres comp2: <span class="cp">${</span><span class="n">comp2</span><span class=
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="code">
|
|
<div class="code">
|
|
|
- <div class="highlight"><pre><span class="cp">${</span><span class="bp">self</span><span class="o">.</span><span class="n">body</span><span class="p">(</span><span class="mf">5</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="mf">10</span><span class="p">,</span> <span class="n">someval</span><span class="o">=</span><span class="mf">15</span><span class="p">,</span> <span class="n">delta</span><span class="o">=</span><span class="mf">7</span><span class="p">)</span><span class="cp">}</span>
|
|
|
|
|
|
|
+ <div class="highlight"><pre><span class="cp">${</span><span class="bp">self</span><span class="o">.</span><span class="n">body</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">someval</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span> <span class="n">delta</span><span class="o">=</span><span class="mi">7</span><span class="p">)</span><span class="cp">}</span>
|
|
|
</pre></div>
|
|
</pre></div>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
@@ -3012,7 +3012,7 @@ Heres comp2: <span class="cp">${</span><span class="n">comp2</span><span class=
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="code">
|
|
<div class="code">
|
|
|
- <div class="highlight"><pre><span class="cp">${</span><span class="n">next</span><span class="o">.</span><span class="n">body</span><span class="p">(</span><span class="o">**</span><span class="n">context</span><span class="o">.</span><span class="n">kwargs</span><span class="p">)</span><span class="cp">}</span>
|
|
|
|
|
|
|
+ <div class="highlight"><pre><span class="cp">${</span><span class="nb">next</span><span class="o">.</span><span class="n">body</span><span class="p">(</span><span class="o">**</span><span class="n">context</span><span class="o">.</span><span class="n">kwargs</span><span class="p">)</span><span class="cp">}</span>
|
|
|
</pre></div>
|
|
</pre></div>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
@@ -3146,7 +3146,7 @@ Heres comp2: <span class="cp">${</span><span class="n">comp2</span><span class=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-<p>The <code><%namespace></code> tag includes an optional attribute <code>inheritable="True"</code>, which will cause the namespace to be attached to the <code>self</code> namespace. Since <code>self</code> is globally available throughout an inheritance chain (described in the next section), all the templates in an inheritance chain can get at the namespace imported in a super-template via <code>self</code>.
|
|
|
|
|
|
|
+<p>The <code><%namespace></code> tag includes an optional attribute <code>inheritable="True"</code>, which will cause the namespace to be attached to the <code>self</code> namespace. Since <code>self</code> is globally available throughout an inheritance chain (described in the next section), all the templates in an inheritance chain can get at the namespace imported in a super-template via <code>self</code>.
|
|
|
</p>
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
@@ -3156,7 +3156,7 @@ Heres comp2: <span class="cp">${</span><span class="n">comp2</span><span class=
|
|
|
<div class="highlight"><pre><span class="cp">## base.html</span>
|
|
<div class="highlight"><pre><span class="cp">## base.html</span>
|
|
|
<span class="cp"><%</span><span class="nb">namespace</span> <span class="na">name=</span><span class="s">"foo"</span> <span class="na">file=</span><span class="s">"foo.html"</span> <span class="na">inheritable=</span><span class="s">"True"</span><span class="cp">/></span>
|
|
<span class="cp"><%</span><span class="nb">namespace</span> <span class="na">name=</span><span class="s">"foo"</span> <span class="na">file=</span><span class="s">"foo.html"</span> <span class="na">inheritable=</span><span class="s">"True"</span><span class="cp">/></span>
|
|
|
|
|
|
|
|
-<span class="cp">${</span><span class="n">next</span><span class="o">.</span><span class="n">body</span><span class="p">()</span><span class="cp">}</span>
|
|
|
|
|
|
|
+<span class="cp">${</span><span class="nb">next</span><span class="o">.</span><span class="n">body</span><span class="p">()</span><span class="cp">}</span>
|
|
|
|
|
|
|
|
<span class="cp">## somefile.html</span>
|
|
<span class="cp">## somefile.html</span>
|
|
|
<span class="cp"><%</span><span class="nb">inherit</span> <span class="na">file=</span><span class="s">"base.html"</span><span class="cp">/></span>
|
|
<span class="cp"><%</span><span class="nb">inherit</span> <span class="na">file=</span><span class="s">"base.html"</span><span class="cp">/></span>
|
|
@@ -3167,7 +3167,7 @@ Heres comp2: <span class="cp">${</span><span class="n">comp2</span><span class=
|
|
|
</div>
|
|
</div>
|
|
|
<p>This allows a super-template to load a whole bunch of namespaces that its inheriting templates can get to, without them having to explicitly load those namespaces themselves.
|
|
<p>This allows a super-template to load a whole bunch of namespaces that its inheriting templates can get to, without them having to explicitly load those namespaces themselves.
|
|
|
</p>
|
|
</p>
|
|
|
-<p>The <code>import="*"</code> part of the <code><%namespace></code> tag doesn't yet interact with the <code>inheritable</code> flag, so currently you have to use the explicit namespace name off of <code>self</code>, followed by the desired function name. But more on this in a future release.
|
|
|
|
|
|
|
+<p>The <code>import="*"</code> part of the <code><%namespace></code> tag doesn't yet interact with the <code>inheritable</code> flag, so currently you have to use the explicit namespace name off of <code>self</code>, followed by the desired function name. But more on this in a future release.
|
|
|
</p>
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
@@ -3355,7 +3355,7 @@ this is the body content.
|
|
|
<span class="cp">${</span><span class="bp">self</span><span class="o">.</span><span class="n">header</span><span class="p">()</span><span class="cp">}</span>
|
|
<span class="cp">${</span><span class="bp">self</span><span class="o">.</span><span class="n">header</span><span class="p">()</span><span class="cp">}</span>
|
|
|
<span class="nt"></div></span>
|
|
<span class="nt"></div></span>
|
|
|
|
|
|
|
|
- <span class="cp">${</span><span class="n">next</span><span class="o">.</span><span class="n">body</span><span class="p">()</span><span class="cp">}</span>
|
|
|
|
|
|
|
+ <span class="cp">${</span><span class="nb">next</span><span class="o">.</span><span class="n">body</span><span class="p">()</span><span class="cp">}</span>
|
|
|
|
|
|
|
|
<span class="nt"><div</span> <span class="na">class=</span><span class="s">"footer"</span><span class="nt">></span>
|
|
<span class="nt"><div</span> <span class="na">class=</span><span class="s">"footer"</span><span class="nt">></span>
|
|
|
<span class="cp">${</span><span class="bp">self</span><span class="o">.</span><span class="n">footer</span><span class="p">()</span><span class="cp">}</span>
|
|
<span class="cp">${</span><span class="bp">self</span><span class="o">.</span><span class="n">footer</span><span class="p">()</span><span class="cp">}</span>
|
|
@@ -3382,7 +3382,7 @@ this is the body content.
|
|
|
<span class="cp">${</span><span class="bp">self</span><span class="o">.</span><span class="n">toolbar</span><span class="p">()</span><span class="cp">}</span>
|
|
<span class="cp">${</span><span class="bp">self</span><span class="o">.</span><span class="n">toolbar</span><span class="p">()</span><span class="cp">}</span>
|
|
|
<span class="nt"></ul></span>
|
|
<span class="nt"></ul></span>
|
|
|
<span class="nt"><div</span> <span class="na">class=</span><span class="s">"mainlayout"</span><span class="nt">></span>
|
|
<span class="nt"><div</span> <span class="na">class=</span><span class="s">"mainlayout"</span><span class="nt">></span>
|
|
|
- <span class="cp">${</span><span class="n">next</span><span class="o">.</span><span class="n">body</span><span class="p">()</span><span class="cp">}</span>
|
|
|
|
|
|
|
+ <span class="cp">${</span><span class="nb">next</span><span class="o">.</span><span class="n">body</span><span class="p">()</span><span class="cp">}</span>
|
|
|
<span class="nt"></div></span>
|
|
<span class="nt"></div></span>
|
|
|
|
|
|
|
|
<span class="cp"><%</span><span class="nb">def</span> <span class="na">name=</span><span class="s">"toolbar()"</span><span class="cp">></span>
|
|
<span class="cp"><%</span><span class="nb">def</span> <span class="na">name=</span><span class="s">"toolbar()"</span><span class="cp">></span>
|
|
@@ -3662,11 +3662,11 @@ This is the body
|
|
|
</p>
|
|
</p>
|
|
|
<ul>
|
|
<ul>
|
|
|
<li>
|
|
<li>
|
|
|
- <code>u</code> : URL escaping, provided by <code>urllib.quote_plus(string.encode('utf-8'))</code>
|
|
|
|
|
|
|
+ <code>u</code> : URL escaping, provided by <code>urllib.quote_plus(string.encode('utf-8'))</code>
|
|
|
</li>
|
|
</li>
|
|
|
|
|
|
|
|
<li>
|
|
<li>
|
|
|
- <code>h</code> : HTML escaping, provided by <code>cgi.escape(string, True)</code>
|
|
|
|
|
|
|
+ <code>h</code> : HTML escaping, provided by <code>markupsafe.escape(string)</code> (new as of 0.3.4 - prior versions use <code>cgi.escape(string, True)</code>)
|
|
|
</li>
|
|
</li>
|
|
|
|
|
|
|
|
<li>
|
|
<li>
|
|
@@ -3773,7 +3773,7 @@ Escaped text: <span class="cp">${</span><span class="s">"<html>some
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-<p>In addition to the <code>expression_filter</code> argument, the <code>default_filters</code> argument to both <code>Template</code> and <code>TemplateLookup</code> can specify filtering for all expression tags at the programmatic level. This array-based argument, when given its default argument of <code>None</code>, will be internally set to <code>["unicode"]</code> (or <code>["str"]</code> on Python 3), except when <code>disable_unicode=True</code> is set in which case it defaults to <code>["str"]</code>:
|
|
|
|
|
|
|
+<p>In addition to the <code>expression_filter</code> argument, the <code>default_filters</code> argument to both <code>Template</code> and <code>TemplateLookup</code> can specify filtering for all expression tags at the programmatic level. This array-based argument, when given its default argument of <code>None</code>, will be internally set to <code>["unicode"]</code> (or <code>["str"]</code> on Python 3), except when <code>disable_unicode=True</code> is set in which case it defaults to <code>["str"]</code>:
|
|
|
</p>
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
@@ -3943,7 +3943,7 @@ Escaped text: <span class="cp">${</span><span class="s">"<html>some
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-<p>One of Mako's central design goals is speed. To this end, all of the textual content within a template and its various callables is by default piped directly to the single buffer that is stored within the <code>Context</code> object. While this normally is easy to miss, it has certain side effects. The main one is that when you call a def using the normal expression syntax, i.e. <code>${somedef()}</code>, it may appear that the return value of the function is the content it produced, which is then delivered to your template just like any other expression substitution, except that normally, this is not the case; the return value of <code>${somedef()}</code> is simply the empty string <code>''</code>. By the time you receive this empty string, the output of <code>somedef()</code> has been sent to the underlying buffer.
|
|
|
|
|
|
|
+<p>One of Mako's central design goals is speed. To this end, all of the textual content within a template and its various callables is by default piped directly to the single buffer that is stored within the <code>Context</code> object. While this normally is easy to miss, it has certain side effects. The main one is that when you call a def using the normal expression syntax, i.e. <code>${somedef()}</code>, it may appear that the return value of the function is the content it produced, which is then delivered to your template just like any other expression substitution, except that normally, this is not the case; the return value of <code>${somedef()}</code> is simply the empty string <code>''</code>. By the time you receive this empty string, the output of <code>somedef()</code> has been sent to the underlying buffer.
|
|
|
</p>
|
|
</p>
|
|
|
<p>You may not want this effect, if for example you are doing something like this:
|
|
<p>You may not want this effect, if for example you are doing something like this:
|
|
|
</p>
|
|
</p>
|
|
@@ -3956,7 +3956,7 @@ Escaped text: <span class="cp">${</span><span class="s">"<html>some
|
|
|
</pre></div>
|
|
</pre></div>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
|
-<p>If the <code>somedef()</code> function produced the content "<code>somedef's results</code>", the above template would produce this output:
|
|
|
|
|
|
|
+<p>If the <code>somedef()</code> function produced the content "<code>somedef's results</code>", the above template would produce this output:
|
|
|
</p>
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
@@ -4021,7 +4021,7 @@ Escaped text: <span class="cp">${</span><span class="s">"<html>some
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="code">
|
|
<div class="code">
|
|
|
- <div class="highlight"><pre><span class="cp">${</span><span class="n">capture</span><span class="p">(</span><span class="n">somedef</span><span class="p">,</span> <span class="mf">17</span><span class="p">,</span> <span class="s">'hi'</span><span class="p">,</span> <span class="n">use_paging</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span><span class="cp">}</span>
|
|
|
|
|
|
|
+ <div class="highlight"><pre><span class="cp">${</span><span class="n">capture</span><span class="p">(</span><span class="n">somedef</span><span class="p">,</span> <span class="mi">17</span><span class="p">,</span> <span class="s">'hi'</span><span class="p">,</span> <span class="n">use_paging</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span><span class="cp">}</span>
|
|
|
</pre></div>
|
|
</pre></div>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
@@ -4032,7 +4032,7 @@ Escaped text: <span class="cp">${</span><span class="s">"<html>some
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="code">
|
|
<div class="code">
|
|
|
- <div class="highlight"><pre><span class="cp">${</span><span class="n">somedef</span><span class="p">(</span><span class="mf">17</span><span class="p">,</span> <span class="s">'hi'</span><span class="p">,</span> <span class="n">use_paging</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span><span class="cp">}</span>
|
|
|
|
|
|
|
+ <div class="highlight"><pre><span class="cp">${</span><span class="n">somedef</span><span class="p">(</span><span class="mi">17</span><span class="p">,</span> <span class="s">'hi'</span><span class="p">,</span> <span class="n">use_paging</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span><span class="cp">}</span>
|
|
|
</pre></div>
|
|
</pre></div>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
@@ -4081,7 +4081,7 @@ Escaped text: <span class="cp">${</span><span class="s">"<html>some
|
|
|
</pre></div>
|
|
</pre></div>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
|
-<p>The above template will return, with more whitespace than this, <code>"BAR this is foo BAR"</code>. The function is the render callable itself (or possibly a wrapper around it), and by default will write to the context. To capture its output, use the <code>capture</code> callable in the <code>mako.runtime</code> module (available in templates as just <code>runtime</code>):
|
|
|
|
|
|
|
+<p>The above template will return, with more whitespace than this, <code>"BAR this is foo BAR"</code>. The function is the render callable itself (or possibly a wrapper around it), and by default will write to the context. To capture its output, use the <code>capture</code> callable in the <code>mako.runtime</code> module (available in templates as just <code>runtime</code>):
|
|
|
</p>
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
@@ -4103,7 +4103,7 @@ Escaped text: <span class="cp">${</span><span class="s">"<html>some
|
|
|
</pre></div>
|
|
</pre></div>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
|
-<p>The decorator can be used with top-level defs as well as nested defs. Note that when calling a top-level def from the <code>Template</code> api, i.e. <code>template.get_def('somedef').render()</code>, the decorator has to write the output to the <code>context</code>, i.e. as in the first example. The return value gets discarded.
|
|
|
|
|
|
|
+<p>The decorator can be used with top-level defs as well as nested defs. Note that when calling a top-level def from the <code>Template</code> api, i.e. <code>template.get_def('somedef').render()</code>, the decorator has to write the output to the <code>context</code>, i.e. as in the first example. The return value gets discarded.
|
|
|
</p>
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
@@ -4156,11 +4156,11 @@ Escaped text: <span class="cp">${</span><span class="s">"<html>some
|
|
|
|
|
|
|
|
<p>The Python language supports two ways of representing what we know as "strings", i.e. series of characters. In Python 2, the two types are <code>string</code> and <code>unicode</code>, and in Python 3 they are <code>bytes</code> and <code>string</code>. A key aspect of the Python 2 <code>string</code> and Python 3 <code>bytes</code> types are that they contain no information regarding what <strong>encoding</strong> the data is stored in. For this reason they were commonly referred to as <strong>byte strings</strong> on Python 2, and Python 3 makes this name more explicit. The origins of this come from Python's background of being developed before the Unicode standard was even available, back when strings were C-style strings and were just that, a series of bytes. Strings that had only values below 128 just happened to be <strong>ascii</strong> strings and were printable on the console, whereas strings with values above 128 would produce all kinds of graphical characters and bells.
|
|
<p>The Python language supports two ways of representing what we know as "strings", i.e. series of characters. In Python 2, the two types are <code>string</code> and <code>unicode</code>, and in Python 3 they are <code>bytes</code> and <code>string</code>. A key aspect of the Python 2 <code>string</code> and Python 3 <code>bytes</code> types are that they contain no information regarding what <strong>encoding</strong> the data is stored in. For this reason they were commonly referred to as <strong>byte strings</strong> on Python 2, and Python 3 makes this name more explicit. The origins of this come from Python's background of being developed before the Unicode standard was even available, back when strings were C-style strings and were just that, a series of bytes. Strings that had only values below 128 just happened to be <strong>ascii</strong> strings and were printable on the console, whereas strings with values above 128 would produce all kinds of graphical characters and bells.
|
|
|
</p>
|
|
</p>
|
|
|
-<p>Contrast the "bytestring" types with the "unicode/string" type. Objects of this type are created whenever you say something like <code>u"hello world"</code> (or in Python 3, just <code>"hello world"</code>). In this case, Python represents each character in the string internally using multiple bytes per character (something similar to UTF-16). Whats important is that when using the <code>unicode</code>/<code>string</code> type to store strings, Python knows the data's encoding; its in its own internal format. Whereas when using the <code>string</code>/<code>bytes</code> type, it does not.
|
|
|
|
|
|
|
+<p>Contrast the "bytestring" types with the "unicode/string" type. Objects of this type are created whenever you say something like <code>u"hello world"</code> (or in Python 3, just <code>"hello world"</code>). In this case, Python represents each character in the string internally using multiple bytes per character (something similar to UTF-16). Whats important is that when using the <code>unicode</code>/<code>string</code> type to store strings, Python knows the data's encoding; its in its own internal format. Whereas when using the <code>string</code>/<code>bytes</code> type, it does not.
|
|
|
</p>
|
|
</p>
|
|
|
<p>When Python 2 attempts to treat a byte-string as a string, which means its attempting to compare/parse its characters, to coerce it into another encoding, or to decode it to a unicode object, it has to guess what the encoding is. In this case, it will pretty much always guess the encoding as <code>ascii</code>...and if the bytestring contains bytes above value 128, you'll get an error. Python 3 eliminates much of this confusion by just raising an error unconditionally if a bytestring is used in a character-aware context.
|
|
<p>When Python 2 attempts to treat a byte-string as a string, which means its attempting to compare/parse its characters, to coerce it into another encoding, or to decode it to a unicode object, it has to guess what the encoding is. In this case, it will pretty much always guess the encoding as <code>ascii</code>...and if the bytestring contains bytes above value 128, you'll get an error. Python 3 eliminates much of this confusion by just raising an error unconditionally if a bytestring is used in a character-aware context.
|
|
|
</p>
|
|
</p>
|
|
|
-<p>There is one operation that Python <em>can</em> do with a non-ascii bytestring, and its a great source of confusion: it can dump the bytestring straight out to a stream or a file, with nary a care what the encoding is. To Python, this is pretty much like dumping any other kind of binary data (like an image) to a stream somewhere. In Python 2, it is common to see programs that embed all kinds of international characters and encodings into plain byte-strings (i.e. using <code>"hello world"</code> style literals) can fly right through their run, sending reams of strings out to whereever they are going, and the programmer, seeing the same output as was expressed in the input, is now under the illusion that his or her program is Unicode-compliant. In fact, their program has no unicode awareness whatsoever, and similarly has no ability to interact with libraries that <em>are</em> unicode aware. Python 3 makes this much less likely by defaulting to unicode as the storage format for strings.
|
|
|
|
|
|
|
+<p>There is one operation that Python <em>can</em> do with a non-ascii bytestring, and its a great source of confusion: it can dump the bytestring straight out to a stream or a file, with nary a care what the encoding is. To Python, this is pretty much like dumping any other kind of binary data (like an image) to a stream somewhere. In Python 2, it is common to see programs that embed all kinds of international characters and encodings into plain byte-strings (i.e. using <code>"hello world"</code> style literals) can fly right through their run, sending reams of strings out to whereever they are going, and the programmer, seeing the same output as was expressed in the input, is now under the illusion that his or her program is Unicode-compliant. In fact, their program has no unicode awareness whatsoever, and similarly has no ability to interact with libraries that <em>are</em> unicode aware. Python 3 makes this much less likely by defaulting to unicode as the storage format for strings.
|
|
|
</p>
|
|
</p>
|
|
|
<p>The "pass through encoded data" scheme is what template languages like Cheetah and earlier versions of Myghty do by default. Mako as of version 0.2 also supports this mode of operation when using Python 2, using the "disable_unicode=True" flag. However, when using Mako in its default mode of unicode-aware, it requires explicitness when dealing with non-ascii encodings. Additionally, if you ever need to handle unicode strings and other kinds of encoding conversions more intelligently, the usage of raw bytestrings quickly becomes a nightmare, since you are sending the Python interpreter collections of bytes for which it can make no intelligent decisions with regards to encoding. In Python 3 Mako only allows usage of native, unicode strings.
|
|
<p>The "pass through encoded data" scheme is what template languages like Cheetah and earlier versions of Myghty do by default. Mako as of version 0.2 also supports this mode of operation when using Python 2, using the "disable_unicode=True" flag. However, when using Mako in its default mode of unicode-aware, it requires explicitness when dealing with non-ascii encodings. Additionally, if you ever need to handle unicode strings and other kinds of encoding conversions more intelligently, the usage of raw bytestrings quickly becomes a nightmare, since you are sending the Python interpreter collections of bytes for which it can make no intelligent decisions with regards to encoding. In Python 3 Mako only allows usage of native, unicode strings.
|
|
|
</p>
|
|
</p>
|
|
@@ -4393,7 +4393,7 @@ Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petit voi
|
|
|
|
|
|
|
|
<p>Mako does play some games with the style of buffering used internally, to maximize performance. Since the buffer is by far the most heavily used object in a render operation, its important!
|
|
<p>Mako does play some games with the style of buffering used internally, to maximize performance. Since the buffer is by far the most heavily used object in a render operation, its important!
|
|
|
</p>
|
|
</p>
|
|
|
-<p>When calling <code>render()</code> on a template that does not specify any output encoding (i.e. its <code>ascii</code>), Python's <code>cStringIO</code> module, which cannot handle encoding of non-ascii <code>unicode</code> objects (even though it can send raw bytestrings through), is used for buffering. Otherwise, a custom Mako class called <code>FastEncodingBuffer</code> is used, which essentially is a super dumbed-down version of <code>StringIO</code> that gathers all strings into a list and uses <code>u''.join(elements)</code> to produce the final output - its markedly faster than <code>StringIO</code>.
|
|
|
|
|
|
|
+<p>When calling <code>render()</code> on a template that does not specify any output encoding (i.e. its <code>ascii</code>), Python's <code>cStringIO</code> module, which cannot handle encoding of non-ascii <code>unicode</code> objects (even though it can send raw bytestrings through), is used for buffering. Otherwise, a custom Mako class called <code>FastEncodingBuffer</code> is used, which essentially is a super dumbed-down version of <code>StringIO</code> that gathers all strings into a list and uses <code>u''.join(elements)</code> to produce the final output - its markedly faster than <code>StringIO</code>.
|
|
|
</p>
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
@@ -4418,7 +4418,7 @@ Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petit voi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-<p>Some segements of Mako's userbase choose to make no usage of Unicode whatsoever, and instead would prefer the "passthru" approach; all string expressions in their templates return encoded bytestrings, and they would like these strings to pass right through. The only advantage to this approach is that templates need not use <code>u""</code> for literal strings; there's an arguable speed improvement as well since raw bytestrings generally perform slightly faster than unicode objects in Python. For these users, assuming they're sticking with Python 2, they can hit the <code>disable_unicode=True</code> flag as so:
|
|
|
|
|
|
|
+<p>Some segements of Mako's userbase choose to make no usage of Unicode whatsoever, and instead would prefer the "passthru" approach; all string expressions in their templates return encoded bytestrings, and they would like these strings to pass right through. The only advantage to this approach is that templates need not use <code>u""</code> for literal strings; there's an arguable speed improvement as well since raw bytestrings generally perform slightly faster than unicode objects in Python. For these users, assuming they're sticking with Python 2, they can hit the <code>disable_unicode=True</code> flag as so:
|
|
|
</p>
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
@@ -4459,7 +4459,9 @@ Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petit voi
|
|
|
</div>
|
|
</div>
|
|
|
<p>Where above that the string literal used within <code>context.write</code> is a regular bytestring.
|
|
<p>Where above that the string literal used within <code>context.write</code> is a regular bytestring.
|
|
|
</p>
|
|
</p>
|
|
|
-<p>When <code>disable_unicode=True</code> is turned on, the <code>default_filters</code> argument which normally defaults to <code>["unicode"]</code> now defaults to <code>["str"]</code> instead. Setting default_filters to the empty list <code>[]</code> can remove the overhead of the <code>str</code> call. Also, in this mode you <strong>cannot</strong> safely call <code>render_unicode()</code> - you'll get unicode/decode errors.
|
|
|
|
|
|
|
+<p>When <code>disable_unicode=True</code> is turned on, the <code>default_filters</code> argument which normally defaults to <code>["unicode"]</code> now defaults to <code>["str"]</code> instead. Setting default_filters to the empty list <code>[]</code> can remove the overhead of the <code>str</code> call. Also, in this mode you <strong>cannot</strong> safely call <code>render_unicode()</code> - you'll get unicode/decode errors.
|
|
|
|
|
+</p>
|
|
|
|
|
+<p>The <code>h</code> filter (html escape) uses a less performant pure Python escape function in non-unicode mode (note that in versions prior to 0.3.4, it used cgi.escape(), which has been replaced with a function that also escapes single quotes). This because MarkupSafe only supports Python unicode objects for non-ascii strings.
|
|
|
</p>
|
|
</p>
|
|
|
<p><strong>Rules for using disable_unicode=True</strong>
|
|
<p><strong>Rules for using disable_unicode=True</strong>
|
|
|
</p>
|
|
</p>
|
|
@@ -4605,7 +4607,7 @@ template text
|
|
|
<div class="code">
|
|
<div class="code">
|
|
|
<div class="highlight"><pre><span class="cp"><%</span><span class="nb">page</span> <span class="na">cached=</span><span class="s">"True"</span> <span class="na">cache_key=</span><span class="s">"${self.filename}"</span><span class="cp">/></span>
|
|
<div class="highlight"><pre><span class="cp"><%</span><span class="nb">page</span> <span class="na">cached=</span><span class="s">"True"</span> <span class="na">cache_key=</span><span class="s">"${self.filename}"</span><span class="cp">/></span>
|
|
|
|
|
|
|
|
-<span class="cp">${</span><span class="n">next</span><span class="o">.</span><span class="n">body</span><span class="p">()</span><span class="cp">}</span>
|
|
|
|
|
|
|
+<span class="cp">${</span><span class="nb">next</span><span class="o">.</span><span class="n">body</span><span class="p">()</span><span class="cp">}</span>
|
|
|
|
|
|
|
|
<span class="cp">## rest of template</span>
|
|
<span class="cp">## rest of template</span>
|
|
|
</pre></div>
|
|
</pre></div>
|