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
717d8a82
Commit
717d8a82
authored
14 years ago
by
Mike Bayer
Browse files
Options
Downloads
Patches
Plain Diff
step 1, three separate classes, new magic number
parent
a3b2aba0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mako/codegen.py
+30
-9
30 additions, 9 deletions
mako/codegen.py
mako/runtime.py
+50
-25
50 additions, 25 deletions
mako/runtime.py
with
80 additions
and
34 deletions
mako/codegen.py
+
30
−
9
View file @
717d8a82
...
...
@@ -11,7 +11,7 @@ import re
from
mako.pygen
import
PythonPrinter
from
mako
import
util
,
ast
,
parsetree
,
filters
MAGIC_NUMBER
=
5
MAGIC_NUMBER
=
6
def
compile
(
node
,
uri
,
...
...
@@ -319,14 +319,35 @@ class _GenerateRenderMethod(object):
callable_name
=
"
make_namespace()
"
else
:
callable_name
=
"
None
"
self
.
printer
.
writeline
(
"
ns = runtime.Namespace(%r, context._clean_inheritance_tokens(),
"
"
templateuri=%s, callables=%s, calling_uri=_template_uri, module=%s)
"
%
(
node
.
name
,
node
.
parsed_attributes
.
get
(
'
file
'
,
'
None
'
),
callable_name
,
node
.
parsed_attributes
.
get
(
'
module
'
,
'
None
'
))
if
'
file
'
in
node
.
parsed_attributes
:
self
.
printer
.
writeline
(
"
ns = runtime.TemplateNamespace(%r, context._clean_inheritance_tokens(),
"
"
templateuri=%s, callables=%s, calling_uri=_template_uri)
"
%
(
node
.
name
,
node
.
parsed_attributes
.
get
(
'
file
'
,
'
None
'
),
callable_name
,
)
)
elif
'
module
'
in
node
.
parsed_attributes
:
self
.
printer
.
writeline
(
"
ns = runtime.ModuleNamespace(%r, context._clean_inheritance_tokens(),
"
"
callables=%s, calling_uri=_template_uri, module=%s)
"
%
(
node
.
name
,
callable_name
,
node
.
parsed_attributes
.
get
(
'
module
'
,
'
None
'
)
)
)
else
:
self
.
printer
.
writeline
(
"
ns = runtime.Namespace(%r, context._clean_inheritance_tokens(),
"
"
callables=%s, calling_uri=_template_uri)
"
%
(
node
.
name
,
callable_name
,
)
)
if
eval
(
node
.
attributes
.
get
(
'
inheritable
'
,
"
False
"
)):
self
.
printer
.
writeline
(
"
context[
'
self
'
].%s = ns
"
%
(
node
.
name
))
...
...
This diff is collapsed.
Click to expand it.
mako/runtime.py
+
50
−
25
View file @
717d8a82
...
...
@@ -210,35 +210,19 @@ class Namespace(object):
"""
def
__init__
(
self
,
name
,
context
,
module
=
None
,
template
=
None
,
templateuri
=
None
,
def
__init__
(
self
,
name
,
context
,
callables
=
None
,
inherits
=
None
,
populate_self
=
True
,
calling_uri
=
None
):
self
.
name
=
name
if
module
is
not
None
:
mod
=
__import__
(
module
)
for
token
in
module
.
split
(
'
.
'
)[
1
:]:
mod
=
getattr
(
mod
,
token
)
self
.
_module
=
mod
else
:
self
.
_module
=
None
if
templateuri
is
not
None
:
self
.
template
=
_lookup_template
(
context
,
templateuri
,
calling_uri
)
self
.
_templateuri
=
self
.
template
.
module
.
_template_uri
else
:
self
.
template
=
template
if
self
.
template
is
not
None
:
self
.
_templateuri
=
self
.
template
.
module
.
_template_uri
self
.
context
=
context
self
.
inherits
=
inherits
if
callables
is
not
None
:
self
.
callables
=
dict
([(
c
.
func_name
,
c
)
for
c
in
callables
])
else
:
self
.
callables
=
None
if
populate_self
and
self
.
template
is
not
None
:
lclcallable
,
lclcontext
=
\
_populate_self_namespace
(
context
,
self
.
template
,
self_ns
=
self
)
callables
=
None
_module
=
None
template
=
None
"""
The :class:`.Template` object referenced by this
:class:`.Namespace`, if any.
...
...
@@ -333,7 +317,7 @@ class Namespace(object):
if
self
.
context
.
namespaces
.
has_key
(
key
):
return
self
.
context
.
namespaces
[
key
]
else
:
ns
=
Namespace
(
uri
,
self
.
context
.
_copy
(),
ns
=
Template
Namespace
(
uri
,
self
.
context
.
_copy
(),
templateuri
=
uri
,
calling_uri
=
self
.
_templateuri
)
self
.
context
.
namespaces
[
key
]
=
ns
...
...
@@ -433,6 +417,47 @@ class Namespace(object):
"
Namespace
'
%s
'
has no member
'
%s
'"
%
(
self
.
name
,
key
))
class
TemplateNamespace
(
Namespace
):
def
__init__
(
self
,
name
,
context
,
template
=
None
,
templateuri
=
None
,
callables
=
None
,
inherits
=
None
,
populate_self
=
True
,
calling_uri
=
None
):
self
.
name
=
name
self
.
context
=
context
self
.
inherits
=
inherits
if
callables
is
not
None
:
self
.
callables
=
dict
([(
c
.
func_name
,
c
)
for
c
in
callables
])
if
templateuri
is
not
None
:
self
.
template
=
_lookup_template
(
context
,
templateuri
,
calling_uri
)
self
.
_templateuri
=
self
.
template
.
module
.
_template_uri
elif
template
is
not
None
:
self
.
template
=
template
self
.
_templateuri
=
template
.
module
.
_template_uri
else
:
raise
TypeError
(
"'
template
'
argument is required.
"
)
if
populate_self
:
lclcallable
,
lclcontext
=
\
_populate_self_namespace
(
context
,
self
.
template
,
self_ns
=
self
)
class
ModuleNamespace
(
Namespace
):
def
__init__
(
self
,
name
,
context
,
module
,
callables
=
None
,
inherits
=
None
,
populate_self
=
True
,
calling_uri
=
None
):
self
.
name
=
name
self
.
context
=
context
self
.
inherits
=
inherits
if
callables
is
not
None
:
self
.
callables
=
dict
([(
c
.
func_name
,
c
)
for
c
in
callables
])
mod
=
__import__
(
module
)
for
token
in
module
.
split
(
'
.
'
)[
1
:]:
mod
=
getattr
(
mod
,
token
)
self
.
_module
=
mod
def
supports_caller
(
func
):
"""
Apply a caller_stack compatibility decorator to a plain
Python function.
...
...
@@ -514,7 +539,7 @@ def _inherit_from(context, uri, calling_uri):
while
ih
.
inherits
is
not
None
:
ih
=
ih
.
inherits
lclcontext
=
context
.
locals_
({
'
next
'
:
ih
})
ih
.
inherits
=
Namespace
(
"
self:%s
"
%
template
.
uri
,
ih
.
inherits
=
Template
Namespace
(
"
self:%s
"
%
template
.
uri
,
lclcontext
,
template
=
template
,
populate_self
=
False
)
...
...
@@ -544,7 +569,7 @@ def _lookup_template(context, uri, relativeto):
def
_populate_self_namespace
(
context
,
template
,
self_ns
=
None
):
if
self_ns
is
None
:
self_ns
=
Namespace
(
'
self:%s
'
%
template
.
uri
,
self_ns
=
Template
Namespace
(
'
self:%s
'
%
template
.
uri
,
context
,
template
=
template
,
populate_self
=
False
)
context
.
_data
[
'
self
'
]
=
context
.
_data
[
'
local
'
]
=
self_ns
...
...
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