Merged in thorade/mako-2/thorade/unicoderst-edited-online-with-bitbucket--1420641728556 (pull request #15)
unicode.rst edited online with Bitbucket,
diff --git a/doc/build/defs.rst b/doc/build/defs.rst
index 31798d4..3c06840 100644
--- a/doc/build/defs.rst
+++ b/doc/build/defs.rst
@@ -139,8 +139,8 @@
</%def>
""")
- print template.get_def("hi").render(name="ed")
- print template.get_def("bye").render(name="ed")
+ print(template.get_def("hi").render(name="ed"))
+ print(template.get_def("bye").render(name="ed"))
Defs within Defs
----------------
diff --git a/doc/build/usage.rst b/doc/build/usage.rst
index d6e5338..ceb8d41 100644
--- a/doc/build/usage.rst
+++ b/doc/build/usage.rst
@@ -20,7 +20,7 @@
from mako.template import Template
mytemplate = Template("hello world!")
- print mytemplate.render()
+ print(mytemplate.render())
Above, the text argument to :class:`.Template` is **compiled** into a
Python module representation. This module contains a function
@@ -41,7 +41,7 @@
from mako.template import Template
mytemplate = Template("hello, ${name}!")
- print mytemplate.render(name="jack")
+ print(mytemplate.render(name="jack"))
The :meth:`~.Template.render` method calls upon Mako to create a
:class:`.Context` object, which stores all the variable names accessible
@@ -59,7 +59,7 @@
buf = StringIO()
ctx = Context(buf, name="jack")
mytemplate.render_context(ctx)
- print buf.getvalue()
+ print(buf.getvalue())
Using File-Based Templates
==========================
@@ -72,7 +72,7 @@
from mako.template import Template
mytemplate = Template(filename='/docs/mytmpl.txt')
- print mytemplate.render()
+ print(mytemplate.render())
For improved performance, a :class:`.Template` which is loaded from a
file can also cache the source code to its generated module on
@@ -85,7 +85,7 @@
from mako.template import Template
mytemplate = Template(filename='/docs/mytmpl.txt', module_directory='/tmp/mako_modules')
- print mytemplate.render()
+ print(mytemplate.render())
When the above code is rendered, a file
``/tmp/mako_modules/docs/mytmpl.txt.py`` is created containing the
@@ -138,7 +138,7 @@
def serve_template(templatename, **kwargs):
mytemplate = mylookup.get_template(templatename)
- print mytemplate.render(**kwargs)
+ print(mytemplate.render(**kwargs))
In the example above, we create a :class:`.TemplateLookup` which will
look for templates in the ``/docs`` directory, and will store
@@ -206,7 +206,7 @@
mylookup = TemplateLookup(directories=['/docs'], output_encoding='utf-8', encoding_errors='replace')
mytemplate = mylookup.get_template("foo.txt")
- print mytemplate.render()
+ print(mytemplate.render())
When using Python 3, the :meth:`~.Template.render` method will return a ``bytes``
object, **if** ``output_encoding`` is set. Otherwise it returns a
@@ -218,14 +218,14 @@
.. sourcecode:: python
- print mytemplate.render_unicode()
+ print(mytemplate.render_unicode())
The above method disregards the output encoding keyword
argument; you can encode yourself by saying:
.. sourcecode:: python
- print mytemplate.render_unicode().encode('utf-8', 'replace')
+ print(mytemplate.render_unicode().encode('utf-8', 'replace'))
Note that Mako's ability to return data in any encoding and/or
``unicode`` implies that the underlying output stream of the
@@ -264,9 +264,9 @@
try:
template = lookup.get_template(uri)
- print template.render()
+ print(template.render())
except:
- print exceptions.text_error_template().render()
+ print(exceptions.text_error_template().render())
Or for the HTML render function:
@@ -276,9 +276,9 @@
try:
template = lookup.get_template(uri)
- print template.render()
+ print(template.render())
except:
- print exceptions.html_error_template().render()
+ print(exceptions.html_error_template().render())
The :func:`.html_error_template` template accepts two options:
specifying ``full=False`` causes only a section of an HTML
@@ -289,7 +289,7 @@
.. sourcecode:: python
- print exceptions.html_error_template().render(full=False)
+ print(exceptions.html_error_template().render(full=False))
The HTML render function is also available built-in to
:class:`.Template` using the ``format_exceptions`` flag. In this case, any
@@ -300,7 +300,7 @@
.. sourcecode:: python
template = Template(filename="/foo/bar", format_exceptions=True)
- print template.render()
+ print(template.render())
Note that the compile stage of the above template occurs when
you construct the :class:`.Template` itself, and no output stream is
@@ -324,13 +324,13 @@
try:
template = lookup.get_template(uri)
- print template.render()
+ print(template.render())
except:
traceback = RichTraceback()
for (filename, lineno, function, line) in traceback.traceback:
- print "File %s, line %s, in %s" % (filename, lineno, function)
- print line, "\n"
- print "%s: %s" % (str(traceback.error.__class__.__name__), traceback.error)
+ print("File %s, line %s, in %s" % (filename, lineno, function))
+ print(line, "\n")
+ print("%s: %s" % (str(traceback.error.__class__.__name__), traceback.error))
Common Framework Integrations
=============================