Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
ff4f12be
Commit
ff4f12be
authored
Sep 14, 1998
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split off testing code.
Got rid of 'from spam import *' imports.
parent
0516a55f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
101 deletions
+8
-101
lib/python/DocumentTemplate/gparse.py
lib/python/DocumentTemplate/gparse.py
+8
-101
No files found.
lib/python/DocumentTemplate/gparse.py
View file @
ff4f12be
...
@@ -51,25 +51,18 @@
...
@@ -51,25 +51,18 @@
# (540) 371-6909
# (540) 371-6909
#
#
##############################################################################
##############################################################################
"$Id: gparse.py,v 1.
5 1998/09/14 20:48
:44 jim Exp $"
"$Id: gparse.py,v 1.
6 1998/09/14 21:26
:44 jim Exp $"
import
sys
,
parser
,
symbol
,
token
import
sys
,
parser
,
symbol
,
token
from
symbol
import
*
from
token
import
*
from
parser
import
sequence2ast
,
compileast
,
ast2list
def
pretty
(
s
):
from
symbol
import
test
,
suite
,
argument
,
arith_expr
,
shift_expr
l
=
ast2list
(
parser
.
expr
(
s
))
from
symbol
import
subscriptlist
,
subscript
,
comparison
,
trailer
,
xor_expr
print
l
from
symbol
import
term
,
not_test
,
factor
,
atom
,
expr
,
arglist
pret
(
l
)
from
symbol
import
power
,
and_test
,
and_expr
def
astl
(
s
):
return
parser
.
ast2list
(
parser
.
expr
(
s
))
from
token
import
STAR
,
NAME
,
RPAR
,
LPAR
,
NUMBER
,
DOT
,
STRING
,
COMMA
from
token
import
ISTERMINAL
,
LSQB
,
COLON
def
pret
(
ast
,
level
=
0
):
from
parser
import
sequence2ast
,
compileast
,
ast2list
if
ISTERMINAL
(
ast
[
0
]):
print
' '
*
level
,
ast
[
1
]
else
:
print
' '
*
level
,
sym_name
[
ast
[
0
]],
'(%s)'
%
ast
[
0
]
for
a
in
ast
[
1
:]:
pret
(
a
,
level
+
1
)
ParseError
=
'Expression Parse Error'
ParseError
=
'Expression Parse Error'
...
@@ -259,15 +252,6 @@ def multi_munge(ast):
...
@@ -259,15 +252,6 @@ def multi_munge(ast):
[
atom
,
[
NAME
,
'__guarded_mul__'
]],
[
atom
,
[
NAME
,
'__guarded_mul__'
]],
[
trailer
,
[
LPAR
,
'('
],
args
,
[
RPAR
,
')'
],
[
trailer
,
[
LPAR
,
'('
],
args
,
[
RPAR
,
')'
],
]]]
]]]
def
tpretty
():
print
60
*
'='
for
arg
in
sys
.
argv
[
1
:]:
print
print
arg
pretty
(
arg
)
print
60
*
'='
def
compile
(
src
,
file_name
,
ctype
):
def
compile
(
src
,
file_name
,
ctype
):
if
ctype
==
'eval'
:
ast
=
parser
.
expr
(
src
)
if
ctype
==
'eval'
:
ast
=
parser
.
expr
(
src
)
...
@@ -277,80 +261,3 @@ def compile(src, file_name, ctype):
...
@@ -277,80 +261,3 @@ def compile(src, file_name, ctype):
ast
=
sequence2ast
(
l
)
ast
=
sequence2ast
(
l
)
return
parser
.
compileast
(
ast
,
file_name
)
return
parser
.
compileast
(
ast
,
file_name
)
def
check
(
expr1
=
None
,
expr2
=
None
):
ok
=
1
expr1
=
expr1
or
sys
.
argv
[
1
]
expr2
=
expr2
or
sys
.
argv
[
2
]
l1
=
munge
(
astl
(
expr1
))
l2
=
astl
(
expr2
)
try
:
c1
=
compileast
(
sequence2ast
(
l1
))
except
:
traceback
.
print_exc
c1
=
None
c2
=
compileast
(
sequence2ast
(
l2
))
if
c1
!=
c2
:
ok
=
0
print
'test failed'
,
expr1
,
expr2
print
print
l1
print
print
l2
print
ast
=
parser
.
sequence2ast
(
l1
)
c
=
parser
.
compileast
(
ast
)
pretty
(
expr1
)
pret
(
l1
)
pret
(
l2
)
return
ok
def
spam
():
# Regression test
import
traceback
ok
=
1
for
expr1
,
expr2
in
(
(
"a*b"
,
"__guarded_mul__(_vars, a, b)"
),
(
"a*b*c"
,
"__guarded_mul__(_vars, __guarded_mul__(_vars, a, b), c)"
),
(
"a.b"
,
"__guarded_getattr__(_vars, a, 'b')"
),
(
"a[b]"
,
"__guarded_getitem__(_vars, a, b)"
),
(
"a[b,c]"
,
"__guarded_getitem__(_vars, a, b, c)"
),
(
"a[b:c]"
,
"__guarded_getslice__(_vars, a, b, c)"
),
(
"a[:c]"
,
"__guarded_getslice__(_vars, a, 0, c)"
),
(
"a[b:]"
,
"__guarded_getslice__(_vars, a, b)"
),
(
"a[:]"
,
"__guarded_getslice__(_vars, a)"
),
(
"_vars['sequence-index'] % 2"
,
"__guarded_getitem__(_vars, _vars, 'sequence-index') % 2"
),
):
l1
=
munge
(
astl
(
expr1
))
l2
=
astl
(
expr2
)
try
:
c1
=
compileast
(
sequence2ast
(
l1
))
except
:
traceback
.
print_exc
c1
=
None
c2
=
compileast
(
sequence2ast
(
l2
))
if
c1
!=
c2
:
ok
=
0
print
'test failed'
,
expr1
,
expr2
print
print
l1
print
print
l2
print
ast
=
parser
.
sequence2ast
(
l1
)
c
=
parser
.
compileast
(
ast
)
if
ok
:
print
'all tests succeeded'
if
__name__
==
'__main__'
:
try
:
c
=
sys
.
argv
[
1
]
del
sys
.
argv
[
1
]
globals
()[
c
]()
except
:
spam
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment