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
1c7f13a4
Commit
1c7f13a4
authored
16 years ago
by
Philip Jenvey
Browse files
Options
Downloads
Patches
Plain Diff
fixed compat. with the upcoming Jython 2.5b1 by removing all the Jython
workarounds; its AST matches CPython's pretty closely
parent
4a55ec98
No related branches found
Branches containing commit
Tags
rel_0_1_7
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGES
+3
-0
3 additions, 0 deletions
CHANGES
lib/mako/_ast_util.py
+10
-40
10 additions, 40 deletions
lib/mako/_ast_util.py
lib/mako/pyparser.py
+1
-7
1 addition, 7 deletions
lib/mako/pyparser.py
with
14 additions
and
47 deletions
CHANGES
+
3
−
0
View file @
1c7f13a4
0.2.4
- Fixed compatibility with Jython 2.5b1.
0.2.3
- the <%namespacename:defname> syntax described at
http://techspot.zzzeek.org/?p=28 has now
...
...
This diff is collapsed.
Click to expand it.
lib/mako/_ast_util.py
+
10
−
40
View file @
1c7f13a4
...
...
@@ -25,36 +25,8 @@
:copyright: Copyright 2008 by Armin Ronacher.
:license: Python License.
"""
import
sys
from
_ast
import
*
if
sys
.
platform
.
startswith
(
'
java
'
):
import
array
ast_list
=
array
.
ArrayType
get_symbol_key
=
lambda
op
:
op
def
get_class_name
(
t
):
result
=
t
.
__class__
.
__name__
if
result
in
(
"
expr_contextType
"
,
"
boolopType
"
,
"
unaryopType
"
,
"
cmpopType
"
,
"
operatorType
"
):
result
=
str
(
t
)
if
result
==
"
AugLoad
"
:
result
=
"
Load
"
elif
result
==
"
AugStore
"
:
result
=
"
Store
"
elif
result
.
endswith
(
"
Type
"
):
result
=
result
[:
-
4
]
return
result
else
:
ast_list
=
list
get_symbol_key
=
type
get_class_name
=
lambda
node
:
node
.
__class__
.
__name__
BOOLOP_SYMBOLS
=
{
And
:
'
and
'
,
...
...
@@ -137,7 +109,7 @@ def dump(node):
return
'
%s(%s)
'
%
(
node
.
__class__
.
__name__
,
'
,
'
.
join
(
'
%s=%s
'
%
(
a
,
_format
(
b
))
for
a
,
b
in
iter_fields
(
node
)))
elif
isinstance
(
node
,
ast_
list
):
elif
isinstance
(
node
,
list
):
return
'
[%s]
'
%
'
,
'
.
join
(
_format
(
x
)
for
x
in
node
)
return
repr
(
node
)
if
not
isinstance
(
node
,
AST
):
...
...
@@ -199,8 +171,6 @@ def increment_lineno(node, n=1):
def
iter_fields
(
node
):
"""
Iterate over all fields of a node, only yielding existing fields.
"""
if
not
hasattr
(
node
,
'
_fields
'
)
or
not
node
.
_fields
:
return
for
field
in
node
.
_fields
:
try
:
yield
field
,
getattr
(
node
,
field
)
...
...
@@ -218,7 +188,7 @@ def iter_child_nodes(node):
for
name
,
field
in
iter_fields
(
node
):
if
isinstance
(
field
,
AST
):
yield
field
elif
isinstance
(
field
,
ast_
list
):
elif
isinstance
(
field
,
list
):
for
item
in
field
:
if
isinstance
(
item
,
AST
):
yield
item
...
...
@@ -290,7 +260,7 @@ class NodeVisitor(object):
exists for this node. In that case the generic visit function is
used instead.
"""
method
=
'
visit_
'
+
get
_class_
name
(
node
)
method
=
'
visit_
'
+
node
.
_
_class_
_
.
__name__
return
getattr
(
self
,
method
,
None
)
def
visit
(
self
,
node
):
...
...
@@ -303,7 +273,7 @@ class NodeVisitor(object):
def
generic_visit
(
self
,
node
):
"""
Called if no explicit visitor function exists for a node.
"""
for
field
,
value
in
iter_fields
(
node
):
if
isinstance
(
value
,
ast_
list
):
if
isinstance
(
value
,
list
):
for
item
in
value
:
if
isinstance
(
item
,
AST
):
self
.
visit
(
item
)
...
...
@@ -349,7 +319,7 @@ class NodeTransformer(NodeVisitor):
def
generic_visit
(
self
,
node
):
for
field
,
old_value
in
iter_fields
(
node
):
old_value
=
getattr
(
node
,
field
,
None
)
if
isinstance
(
old_value
,
ast_
list
):
if
isinstance
(
old_value
,
list
):
new_values
=
[]
for
value
in
old_value
:
if
isinstance
(
value
,
AST
):
...
...
@@ -450,7 +420,7 @@ class SourceGenerator(NodeVisitor):
def
visit_AugAssign
(
self
,
node
):
self
.
newline
()
self
.
visit
(
node
.
target
)
self
.
write
(
BINOP_SYMBOLS
[
get_symbol_key
(
node
.
op
)]
+
'
=
'
)
self
.
write
(
BINOP_SYMBOLS
[
type
(
node
.
op
)]
+
'
=
'
)
self
.
visit
(
node
.
value
)
def
visit_ImportFrom
(
self
,
node
):
...
...
@@ -726,7 +696,7 @@ class SourceGenerator(NodeVisitor):
def
visit_BinOp
(
self
,
node
):
self
.
write
(
'
(
'
)
self
.
visit
(
node
.
left
)
self
.
write
(
'
%s
'
%
BINOP_SYMBOLS
[
get_symbol_key
(
node
.
op
)])
self
.
write
(
'
%s
'
%
BINOP_SYMBOLS
[
type
(
node
.
op
)])
self
.
visit
(
node
.
right
)
self
.
write
(
'
)
'
)
...
...
@@ -734,7 +704,7 @@ class SourceGenerator(NodeVisitor):
self
.
write
(
'
(
'
)
for
idx
,
value
in
enumerate
(
node
.
values
):
if
idx
:
self
.
write
(
'
%s
'
%
BOOLOP_SYMBOLS
[
get_symbol_key
(
node
.
op
)])
self
.
write
(
'
%s
'
%
BOOLOP_SYMBOLS
[
type
(
node
.
op
)])
self
.
visit
(
value
)
self
.
write
(
'
)
'
)
...
...
@@ -742,13 +712,13 @@ class SourceGenerator(NodeVisitor):
self
.
write
(
'
(
'
)
self
.
visit
(
node
.
left
)
for
op
,
right
in
zip
(
node
.
ops
,
node
.
comparators
):
self
.
write
(
'
%s
'
%
CMPOP_SYMBOLS
[
get_symbol_key
(
op
)])
self
.
write
(
'
%s
'
%
CMPOP_SYMBOLS
[
type
(
op
)])
self
.
visit
(
right
)
self
.
write
(
'
)
'
)
def
visit_UnaryOp
(
self
,
node
):
self
.
write
(
'
(
'
)
op
=
UNARYOP_SYMBOLS
[
get_symbol_key
(
node
.
op
)]
op
=
UNARYOP_SYMBOLS
[
type
(
node
.
op
)]
self
.
write
(
op
)
if
op
==
'
not
'
:
self
.
write
(
'
'
)
...
...
This diff is collapsed.
Click to expand it.
lib/mako/pyparser.py
+
1
−
7
View file @
1c7f13a4
...
...
@@ -10,15 +10,12 @@ Parsing to AST is done via _ast on Python > 2.5, otherwise the compiler
module is used.
"""
import
sys
from
StringIO
import
StringIO
from
mako
import
exceptions
,
util
# words that cannot be assigned to (notably smaller than the total keys in __builtins__)
reserved
=
util
.
Set
([
'
True
'
,
'
False
'
,
'
None
'
])
jython
=
sys
.
platform
.
startswith
(
'
java
'
)
try
:
import
_ast
util
.
restore__ast
(
_ast
)
...
...
@@ -91,10 +88,7 @@ if _ast:
for
statement
in
node
.
orelse
:
self
.
visit
(
statement
)
def
visit_Name
(
self
,
node
):
if
jython
:
if
node
.
ctx
==
_ast
.
Store
:
self
.
_add_declared
(
node
.
id
)
elif
isinstance
(
node
.
ctx
,
_ast
.
Store
):
if
isinstance
(
node
.
ctx
,
_ast
.
Store
):
self
.
_add_declared
(
node
.
id
)
if
node
.
id
not
in
reserved
and
node
.
id
not
in
self
.
listener
.
declared_identifiers
and
node
.
id
not
in
self
.
local_ident_stack
:
self
.
listener
.
undeclared_identifiers
.
add
(
node
.
id
)
...
...
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