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
b812d0a9
Commit
b812d0a9
authored
16 years ago
by
Philip Jenvey
Browse files
Options
Downloads
Patches
Plain Diff
merge trunk@400:branches/jython@400 to trunk
adds support for Jython 2.5
parent
24376b0f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGES
+2
-0
2 additions, 0 deletions
CHANGES
lib/mako/_ast_util.py
+39
-10
39 additions, 10 deletions
lib/mako/_ast_util.py
lib/mako/pyparser.py
+10
-6
10 additions, 6 deletions
lib/mako/pyparser.py
with
51 additions
and
16 deletions
CHANGES
+
2
−
0
View file @
b812d0a9
0.2.3
0.2.3
- added support for Jython 2.5.
- cache module now uses Beaker's clsmap to get at
- cache module now uses Beaker's clsmap to get at
container classes, so cache types such as
container classes, so cache types such as
"ext:google", "ext:sqla", etc. are available.
"ext:google", "ext:sqla", etc. are available.
...
...
This diff is collapsed.
Click to expand it.
lib/mako/_ast_util.py
+
39
−
10
View file @
b812d0a9
...
@@ -25,8 +25,37 @@
...
@@ -25,8 +25,37 @@
:copyright: Copyright 2008 by Armin Ronacher.
:copyright: Copyright 2008 by Armin Ronacher.
:license: Python License.
:license: Python License.
"""
"""
import
sys
from
_ast
import
*
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
(
"
org.python.antlr.ast.expr_contextType
"
,
"
org.python.antlr.ast.boolopType
"
,
"
org.python.antlr.ast.unaryopType
"
,
"
org.python.antlr.ast.cmpopType
"
,
"
org.python.antlr.ast.operatorType
"
):
result
=
str
(
t
)
else
:
result
=
result
.
split
(
"
.
"
)[
-
1
]
if
result
.
endswith
(
"
Type
"
):
result
=
result
[:
-
4
]
if
result
==
"
Unicode
"
:
# XXX: likely unecessary now
result
=
"
Str
"
return
result
else
:
ast_list
=
list
get_symbol_key
=
type
get_class_name
=
lambda
node
:
node
.
__class__
.
__name__
BOOLOP_SYMBOLS
=
{
BOOLOP_SYMBOLS
=
{
And
:
'
and
'
,
And
:
'
and
'
,
...
@@ -109,7 +138,7 @@ def dump(node):
...
@@ -109,7 +138,7 @@ def dump(node):
return
'
%s(%s)
'
%
(
node
.
__class__
.
__name__
,
return
'
%s(%s)
'
%
(
node
.
__class__
.
__name__
,
'
,
'
.
join
(
'
%s=%s
'
%
(
a
,
_format
(
b
))
'
,
'
.
join
(
'
%s=%s
'
%
(
a
,
_format
(
b
))
for
a
,
b
in
iter_fields
(
node
)))
for
a
,
b
in
iter_fields
(
node
)))
elif
isinstance
(
node
,
list
):
elif
isinstance
(
node
,
ast_
list
):
return
'
[%s]
'
%
'
,
'
.
join
(
_format
(
x
)
for
x
in
node
)
return
'
[%s]
'
%
'
,
'
.
join
(
_format
(
x
)
for
x
in
node
)
return
repr
(
node
)
return
repr
(
node
)
if
not
isinstance
(
node
,
AST
):
if
not
isinstance
(
node
,
AST
):
...
@@ -190,7 +219,7 @@ def iter_child_nodes(node):
...
@@ -190,7 +219,7 @@ def iter_child_nodes(node):
for
name
,
field
in
iter_fields
(
node
):
for
name
,
field
in
iter_fields
(
node
):
if
isinstance
(
field
,
AST
):
if
isinstance
(
field
,
AST
):
yield
field
yield
field
elif
isinstance
(
field
,
list
):
elif
isinstance
(
field
,
ast_
list
):
for
item
in
field
:
for
item
in
field
:
if
isinstance
(
item
,
AST
):
if
isinstance
(
item
,
AST
):
yield
item
yield
item
...
@@ -262,7 +291,7 @@ class NodeVisitor(object):
...
@@ -262,7 +291,7 @@ class NodeVisitor(object):
exists for this node. In that case the generic visit function is
exists for this node. In that case the generic visit function is
used instead.
used instead.
"""
"""
method
=
'
visit_
'
+
node
.
_
_class_
_
.
__name__
method
=
'
visit_
'
+
get
_class_
name
(
node
)
return
getattr
(
self
,
method
,
None
)
return
getattr
(
self
,
method
,
None
)
def
visit
(
self
,
node
):
def
visit
(
self
,
node
):
...
@@ -275,7 +304,7 @@ class NodeVisitor(object):
...
@@ -275,7 +304,7 @@ class NodeVisitor(object):
def
generic_visit
(
self
,
node
):
def
generic_visit
(
self
,
node
):
"""
Called if no explicit visitor function exists for a node.
"""
"""
Called if no explicit visitor function exists for a node.
"""
for
field
,
value
in
iter_fields
(
node
):
for
field
,
value
in
iter_fields
(
node
):
if
isinstance
(
value
,
list
):
if
isinstance
(
value
,
ast_
list
):
for
item
in
value
:
for
item
in
value
:
if
isinstance
(
item
,
AST
):
if
isinstance
(
item
,
AST
):
self
.
visit
(
item
)
self
.
visit
(
item
)
...
@@ -321,7 +350,7 @@ class NodeTransformer(NodeVisitor):
...
@@ -321,7 +350,7 @@ class NodeTransformer(NodeVisitor):
def
generic_visit
(
self
,
node
):
def
generic_visit
(
self
,
node
):
for
field
,
old_value
in
iter_fields
(
node
):
for
field
,
old_value
in
iter_fields
(
node
):
old_value
=
getattr
(
node
,
field
,
None
)
old_value
=
getattr
(
node
,
field
,
None
)
if
isinstance
(
old_value
,
list
):
if
isinstance
(
old_value
,
ast_
list
):
new_values
=
[]
new_values
=
[]
for
value
in
old_value
:
for
value
in
old_value
:
if
isinstance
(
value
,
AST
):
if
isinstance
(
value
,
AST
):
...
@@ -422,7 +451,7 @@ class SourceGenerator(NodeVisitor):
...
@@ -422,7 +451,7 @@ class SourceGenerator(NodeVisitor):
def
visit_AugAssign
(
self
,
node
):
def
visit_AugAssign
(
self
,
node
):
self
.
newline
()
self
.
newline
()
self
.
visit
(
node
.
target
)
self
.
visit
(
node
.
target
)
self
.
write
(
BINOP_SYMBOLS
[
type
(
node
.
op
)]
+
'
=
'
)
self
.
write
(
BINOP_SYMBOLS
[
get_symbol_key
(
node
.
op
)]
+
'
=
'
)
self
.
visit
(
node
.
value
)
self
.
visit
(
node
.
value
)
def
visit_ImportFrom
(
self
,
node
):
def
visit_ImportFrom
(
self
,
node
):
...
@@ -698,7 +727,7 @@ class SourceGenerator(NodeVisitor):
...
@@ -698,7 +727,7 @@ class SourceGenerator(NodeVisitor):
def
visit_BinOp
(
self
,
node
):
def
visit_BinOp
(
self
,
node
):
self
.
write
(
'
(
'
)
self
.
write
(
'
(
'
)
self
.
visit
(
node
.
left
)
self
.
visit
(
node
.
left
)
self
.
write
(
'
%s
'
%
BINOP_SYMBOLS
[
type
(
node
.
op
)])
self
.
write
(
'
%s
'
%
BINOP_SYMBOLS
[
get_symbol_key
(
node
.
op
)])
self
.
visit
(
node
.
right
)
self
.
visit
(
node
.
right
)
self
.
write
(
'
)
'
)
self
.
write
(
'
)
'
)
...
@@ -706,7 +735,7 @@ class SourceGenerator(NodeVisitor):
...
@@ -706,7 +735,7 @@ class SourceGenerator(NodeVisitor):
self
.
write
(
'
(
'
)
self
.
write
(
'
(
'
)
for
idx
,
value
in
enumerate
(
node
.
values
):
for
idx
,
value
in
enumerate
(
node
.
values
):
if
idx
:
if
idx
:
self
.
write
(
'
%s
'
%
BOOLOP_SYMBOLS
[
type
(
node
.
op
)])
self
.
write
(
'
%s
'
%
BOOLOP_SYMBOLS
[
get_symbol_key
(
node
.
op
)])
self
.
visit
(
value
)
self
.
visit
(
value
)
self
.
write
(
'
)
'
)
self
.
write
(
'
)
'
)
...
@@ -714,13 +743,13 @@ class SourceGenerator(NodeVisitor):
...
@@ -714,13 +743,13 @@ class SourceGenerator(NodeVisitor):
self
.
write
(
'
(
'
)
self
.
write
(
'
(
'
)
self
.
visit
(
node
.
left
)
self
.
visit
(
node
.
left
)
for
op
,
right
in
zip
(
node
.
ops
,
node
.
comparators
):
for
op
,
right
in
zip
(
node
.
ops
,
node
.
comparators
):
self
.
write
(
'
%s
'
%
CMPOP_SYMBOLS
[
type
(
op
)])
self
.
write
(
'
%s
'
%
CMPOP_SYMBOLS
[
get_symbol_key
(
op
)])
self
.
visit
(
right
)
self
.
visit
(
right
)
self
.
write
(
'
)
'
)
self
.
write
(
'
)
'
)
def
visit_UnaryOp
(
self
,
node
):
def
visit_UnaryOp
(
self
,
node
):
self
.
write
(
'
(
'
)
self
.
write
(
'
(
'
)
op
=
UNARYOP_SYMBOLS
[
type
(
node
.
op
)]
op
=
UNARYOP_SYMBOLS
[
get_symbol_key
(
node
.
op
)]
self
.
write
(
op
)
self
.
write
(
op
)
if
op
==
'
not
'
:
if
op
==
'
not
'
:
self
.
write
(
'
'
)
self
.
write
(
'
'
)
...
...
This diff is collapsed.
Click to expand it.
lib/mako/pyparser.py
+
10
−
6
View file @
b812d0a9
...
@@ -17,13 +17,14 @@ from mako import exceptions, util
...
@@ -17,13 +17,14 @@ from mako import exceptions, util
# words that cannot be assigned to (notably smaller than the total keys in __builtins__)
# words that cannot be assigned to (notably smaller than the total keys in __builtins__)
reserved
=
util
.
Set
([
'
True
'
,
'
False
'
,
'
None
'
])
reserved
=
util
.
Set
([
'
True
'
,
'
False
'
,
'
None
'
])
new_ast
=
sys
.
version_info
>
(
2
,
5
)
jython
=
sys
.
platform
.
startswith
(
'
java
'
)
if
new_ast
:
try
:
import
_ast
import
_ast
util
.
restore__ast
(
_ast
)
util
.
restore__ast
(
_ast
)
import
_ast_util
import
_ast_util
else
:
except
ImportError
:
_ast
=
None
from
compiler
import
parse
as
compiler_parse
from
compiler
import
parse
as
compiler_parse
from
compiler
import
visitor
from
compiler
import
visitor
...
@@ -31,7 +32,7 @@ else:
...
@@ -31,7 +32,7 @@ else:
def
parse
(
code
,
mode
=
'
exec
'
,
**
exception_kwargs
):
def
parse
(
code
,
mode
=
'
exec
'
,
**
exception_kwargs
):
"""
Parse an expression into AST
"""
"""
Parse an expression into AST
"""
try
:
try
:
if
new
_ast
:
if
_ast
:
return
_ast_util
.
parse
(
code
,
'
<unknown>
'
,
mode
)
return
_ast_util
.
parse
(
code
,
'
<unknown>
'
,
mode
)
else
:
else
:
return
compiler_parse
(
code
,
mode
)
return
compiler_parse
(
code
,
mode
)
...
@@ -39,7 +40,7 @@ def parse(code, mode='exec', **exception_kwargs):
...
@@ -39,7 +40,7 @@ def parse(code, mode='exec', **exception_kwargs):
raise
exceptions
.
SyntaxException
(
"
(%s) %s (%s)
"
%
(
e
.
__class__
.
__name__
,
str
(
e
),
repr
(
code
[
0
:
50
])),
**
exception_kwargs
)
raise
exceptions
.
SyntaxException
(
"
(%s) %s (%s)
"
%
(
e
.
__class__
.
__name__
,
str
(
e
),
repr
(
code
[
0
:
50
])),
**
exception_kwargs
)
if
new
_ast
:
if
_ast
:
class
FindIdentifiers
(
_ast_util
.
NodeVisitor
):
class
FindIdentifiers
(
_ast_util
.
NodeVisitor
):
def
__init__
(
self
,
listener
,
**
exception_kwargs
):
def
__init__
(
self
,
listener
,
**
exception_kwargs
):
self
.
in_function
=
False
self
.
in_function
=
False
...
@@ -90,7 +91,10 @@ if new_ast:
...
@@ -90,7 +91,10 @@ if new_ast:
for
statement
in
node
.
orelse
:
for
statement
in
node
.
orelse
:
self
.
visit
(
statement
)
self
.
visit
(
statement
)
def
visit_Name
(
self
,
node
):
def
visit_Name
(
self
,
node
):
if
isinstance
(
node
.
ctx
,
_ast
.
Store
):
if
jython
:
if
node
.
ctx
==
_ast
.
Store
:
self
.
_add_declared
(
node
.
id
)
elif
isinstance
(
node
.
ctx
,
_ast
.
Store
):
self
.
_add_declared
(
node
.
id
)
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
:
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
)
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