Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fuchsia.googlesource.com-third_party-mako
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fuchsia-mirror
fuchsia.googlesource.com-third_party-mako
Commits
d1e8233c
Commit
d1e8233c
authored
12 years ago
by
Mike Bayer
Browse files
Options
Downloads
Patches
Plain Diff
- UNDEFINED is a reserved word too, fix docs, add tests
parent
951d1508
No related branches found
Branches containing commit
Tags
rel_0_7_0
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CHANGES
+1
-1
1 addition, 1 deletion
CHANGES
doc/build/runtime.rst
+8
-5
8 additions, 5 deletions
doc/build/runtime.rst
mako/codegen.py
+1
-1
1 addition, 1 deletion
mako/codegen.py
test/test_template.py
+32
-1
32 additions, 1 deletion
test/test_template.py
with
42 additions
and
8 deletions
CHANGES
+
1
−
1
View file @
d1e8233c
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
names, that is names which are never pulled
names, that is names which are never pulled
from the context and cannot be passed to
from the context and cannot be passed to
the template.render() method. Current names
the template.render() method. Current names
are "context", "loop".
are "context", "loop"
, "UNDEFINED"
.
- [feature] The html_error_template() will now
- [feature] The html_error_template() will now
apply Pygments highlighting to the source
apply Pygments highlighting to the source
...
...
This diff is collapsed.
Click to expand it.
doc/build/runtime.rst
+
8
−
5
View file @
d1e8233c
...
@@ -52,6 +52,8 @@ buffer stack. For this reason, just stick with
...
@@ -52,6 +52,8 @@ buffer stack. For this reason, just stick with
``context.write()`` and content will always go to the topmost
``context.write()`` and content will always go to the topmost
buffer.
buffer.
.. _context_vars:
Context Variables
Context Variables
------------------
------------------
...
@@ -363,10 +365,10 @@ All the built-in names
...
@@ -363,10 +365,10 @@ All the built-in names
A one-stop shop for all the names Mako defines. Most of these
A one-stop shop for all the names Mako defines. Most of these
names are instances of :class:`.Namespace`, which are described
names are instances of :class:`.Namespace`, which are described
in the next section, :ref:`namespaces_toplevel`. Also, most of
in the next section, :ref:`namespaces_toplevel`. Also, most of
these names other than
:class:`.C
ontext`
and
``UNDEFINED`` are
these names other than
``c
ontext`
`,
``UNDEFINED``
, and ``loop``
are
also present *within* the :class:`.Context` itself. The
re are only
also present *within* the :class:`.Context` itself. The
names
two names,
``context``
and
``loop``
, that are themselves not defin
ed
``context``
,
``loop``
and ``UNDEFINED`` themselves can't be pass
ed
in
the context and can't be
replac
ed - see the section :ref:`reserved_names`.
to
the context and can't be
substitut
ed
- see the section :ref:`reserved_names`.
* ``context`` - this is the :class:`.Context` object, introduced
* ``context`` - this is the :class:`.Context` object, introduced
at :ref:`context`.
at :ref:`context`.
...
@@ -409,12 +411,13 @@ in the context and can't be replaced - see the section :ref:`reserved_names`.
...
@@ -409,12 +411,13 @@ in the context and can't be replaced - see the section :ref:`reserved_names`.
Reserved names
Reserved names
--------------
--------------
Mako has
two word
s that are considered to be "reserved" and can't be used
Mako has
a few name
s that are considered to be "reserved" and can't be used
as variable names. As of 0.7, Mako raises an error if these words are found
as variable names. As of 0.7, Mako raises an error if these words are found
passed to the template as context arguments, whereas in previous versions they'd be silently
passed to the template as context arguments, whereas in previous versions they'd be silently
ignored or lead to other error messages.
ignored or lead to other error messages.
* ``context`` - see :ref:`context`
* ``context`` - see :ref:`context`
* ``UNDEFINED`` - see :ref:`context_vars`
* ``loop`` - see :ref:`loop_context`. Note this can be disabled for legacy templates
* ``loop`` - see :ref:`loop_context`. Note this can be disabled for legacy templates
via the ``enable_loop=False`` argument; see :ref:`migrating_loop`.
via the ``enable_loop=False`` argument; see :ref:`migrating_loop`.
...
...
This diff is collapsed.
Click to expand it.
mako/codegen.py
+
1
−
1
View file @
d1e8233c
...
@@ -17,7 +17,7 @@ MAGIC_NUMBER = 8
...
@@ -17,7 +17,7 @@ MAGIC_NUMBER = 8
# names which are hardwired into the
# names which are hardwired into the
# template and are not accessed via the
# template and are not accessed via the
# context itself
# context itself
RESERVED_NAMES
=
set
([
'
context
'
,
'
loop
'
])
RESERVED_NAMES
=
set
([
'
context
'
,
'
loop
'
,
'
UNDEFINED
'
])
def
compile
(
node
,
def
compile
(
node
,
uri
,
uri
,
...
...
This diff is collapsed.
Click to expand it.
test/test_template.py
+
32
−
1
View file @
d1e8233c
...
@@ -747,7 +747,38 @@ class UndefinedVarsTest(TemplateTest):
...
@@ -747,7 +747,38 @@ class UndefinedVarsTest(TemplateTest):
result_lines
(
t
.
render
(
t
=
"
T
"
)),
result_lines
(
t
.
render
(
t
=
"
T
"
)),
[
'
t is: T
'
,
'
a,b,c
'
]
[
'
t is: T
'
,
'
a,b,c
'
]
)
)
class
ReservedNameTest
(
TemplateTest
):
def
test_names_on_context
(
self
):
for
name
in
(
'
context
'
,
'
loop
'
,
'
UNDEFINED
'
):
assert_raises_message
(
exceptions
.
NameConflictError
,
r
"
Reserved words passed to render\(\): %s
"
%
name
,
Template
(
"
x
"
).
render
,
**
{
name
:
'
foo
'
}
)
def
test_names_in_template
(
self
):
for
name
in
(
'
context
'
,
'
loop
'
,
'
UNDEFINED
'
):
assert_raises_message
(
exceptions
.
NameConflictError
,
r
"
Reserved words declared in template: %s
"
%
name
,
Template
,
"
<%% %s = 5 %%>
"
%
name
)
def
test_exclude_loop_context
(
self
):
self
.
_do_memory_test
(
"
loop is ${loop}
"
,
"
loop is 5
"
,
template_args
=
dict
(
loop
=
5
),
enable_loop
=
False
)
def
test_exclude_loop_template
(
self
):
self
.
_do_memory_test
(
"
<% loop = 12 %>loop is ${loop}
"
,
"
loop is 12
"
,
enable_loop
=
False
)
class
ControlTest
(
TemplateTest
):
class
ControlTest
(
TemplateTest
):
def
test_control
(
self
):
def
test_control
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment