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
2ed2cfa3
Commit
2ed2cfa3
authored
Sep 14, 1998
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
untabified
parent
d19d04a3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
171 additions
and
171 deletions
+171
-171
lib/python/DocumentTemplate/DTtestExpr.py
lib/python/DocumentTemplate/DTtestExpr.py
+15
-15
lib/python/DocumentTemplate/gparse.py
lib/python/DocumentTemplate/gparse.py
+81
-81
lib/python/DocumentTemplate/pDocumentTemplate.py
lib/python/DocumentTemplate/pDocumentTemplate.py
+75
-75
No files found.
lib/python/DocumentTemplate/DTtestExpr.py
View file @
2ed2cfa3
...
...
@@ -54,8 +54,8 @@
__doc__
=
'''short description
$Id: DTtestExpr.py,v 1.
3 1998/09/14 20:48:42
jim Exp $'''
__version__
=
'$Revision: 1.
3
$'
[
11
:
-
2
]
$Id: DTtestExpr.py,v 1.
4 1998/09/14 22:19:56
jim Exp $'''
__version__
=
'$Revision: 1.
4
$'
[
11
:
-
2
]
from
DocumentTemplate
import
*
import
sys
...
...
@@ -72,21 +72,21 @@ def test3():
def
test4
():
h
=
HTML
(
"""
<!--#if expr="level==1"-->
level was 1
<!--#elif expr="level==2"-->
level was 2
<!--#elif expr="level==3"-->
level was 3
<!--#else-->
level was something else
<!--#endif-->
"""
)
"""
<!--#if expr="level==1"-->
level was 1
<!--#elif expr="level==2"-->
level was 2
<!--#elif expr="level==3"-->
level was 3
<!--#else-->
level was something else
<!--#endif-->
"""
)
for
i
in
range
(
4
):
print
'-'
*
77
print
i
,
h
(
level
=
i
)
print
'-'
*
77
print
i
,
h
(
level
=
i
)
print
'-'
*
77
...
...
lib/python/DocumentTemplate/gparse.py
View file @
2ed2cfa3
...
...
@@ -51,7 +51,7 @@
# (540) 371-6909
#
##############################################################################
"$Id: gparse.py,v 1.
6 1998/09/14 21:26:44
jim Exp $"
"$Id: gparse.py,v 1.
7 1998/09/14 22:19:56
jim Exp $"
import
sys
,
parser
,
symbol
,
token
from
symbol
import
test
,
suite
,
argument
,
arith_expr
,
shift_expr
...
...
@@ -69,59 +69,59 @@ ParseError='Expression Parse Error'
def
munge
(
ast
):
if
ISTERMINAL
(
ast
[
0
]):
return
else
:
if
ast
[
0
]
==
term
and
len
(
ast
)
>
2
:
keep_going
=
1
while
keep_going
:
keep_going
=
0
start
=
2
for
i
in
range
(
start
,
len
(
ast
)
-
1
):
if
ast
[
i
][
0
]
==
STAR
:
ast
[
i
-
1
:
i
+
2
]
=
[
multi_munge
(
ast
[
i
-
1
:
i
+
2
])]
keep_going
=
1
break
for
a
in
ast
[
1
:]:
munge
(
a
)
if
ast
[
0
]
==
term
and
len
(
ast
)
>
2
:
keep_going
=
1
while
keep_going
:
keep_going
=
0
start
=
2
for
i
in
range
(
start
,
len
(
ast
)
-
1
):
if
ast
[
i
][
0
]
==
STAR
:
ast
[
i
-
1
:
i
+
2
]
=
[
multi_munge
(
ast
[
i
-
1
:
i
+
2
])]
keep_going
=
1
break
for
a
in
ast
[
1
:]:
munge
(
a
)
elif
ast
[
0
]
==
power
:
keep_going
=
1
while
keep_going
:
keep_going
=
0
start
=
2
for
i
in
range
(
start
,
len
(
ast
)):
a
=
ast
[
i
]
if
a
[
0
]
==
trailer
:
if
a
[
1
][
0
]
==
DOT
:
ast
[:
i
+
1
]
=
dot_munge
(
ast
,
i
)
keep_going
=
1
start
=
3
break
if
a
[
1
][
0
]
==
LSQB
:
if
(
a
[
2
][
0
]
!=
subscriptlist
or
a
[
2
][
1
][
0
]
!=
subscript
):
raise
ParseError
,
(
'Unexpected form after left square brace'
)
elif
ast
[
0
]
==
power
:
keep_going
=
1
while
keep_going
:
keep_going
=
0
start
=
2
for
i
in
range
(
start
,
len
(
ast
)):
a
=
ast
[
i
]
if
a
[
0
]
==
trailer
:
if
a
[
1
][
0
]
==
DOT
:
ast
[:
i
+
1
]
=
dot_munge
(
ast
,
i
)
keep_going
=
1
start
=
3
break
if
a
[
1
][
0
]
==
LSQB
:
if
(
a
[
2
][
0
]
!=
subscriptlist
or
a
[
2
][
1
][
0
]
!=
subscript
):
raise
ParseError
,
(
'Unexpected form after left square brace'
)
slist
=
a
[
2
]
if
len
(
slist
)
==
2
:
# One subscript, check for range and ...
sub
=
slist
[
1
]
if
sub
[
1
][
0
]
==
DOT
:
raise
ParseError
,
(
'ellipses are not supported'
)
l
=
len
(
sub
)
if
l
<
3
and
sub
[
1
][
0
]
!=
COLON
:
ast
[:
i
+
1
]
=
item_munge
(
ast
,
i
)
elif
l
<
5
:
ast
[:
i
+
1
]
=
slice_munge
(
ast
,
i
)
else
:
raise
ParseError
,
'Invalid slice'
else
:
ast
[:
i
+
1
]
=
item_munge
(
ast
,
i
)
keep_going
=
1
start
=
3
break
slist
=
a
[
2
]
if
len
(
slist
)
==
2
:
# One subscript, check for range and ...
sub
=
slist
[
1
]
if
sub
[
1
][
0
]
==
DOT
:
raise
ParseError
,
(
'ellipses are not supported'
)
l
=
len
(
sub
)
if
l
<
3
and
sub
[
1
][
0
]
!=
COLON
:
ast
[:
i
+
1
]
=
item_munge
(
ast
,
i
)
elif
l
<
5
:
ast
[:
i
+
1
]
=
slice_munge
(
ast
,
i
)
else
:
raise
ParseError
,
'Invalid slice'
else
:
ast
[:
i
+
1
]
=
item_munge
(
ast
,
i
)
keep_going
=
1
start
=
3
break
for
a
in
ast
[
1
:]:
munge
(
a
)
else
:
for
a
in
ast
[
1
:]:
munge
(
a
)
for
a
in
ast
[
1
:]:
munge
(
a
)
else
:
for
a
in
ast
[
1
:]:
munge
(
a
)
return
ast
def
slice_munge
(
ast
,
i
):
...
...
@@ -147,25 +147,25 @@ def slice_munge(ast, i):
sub
=
ast
[
i
][
2
][
1
]
l
=
len
(
sub
)
if
sub
[
1
][
0
]
==
COLON
:
if
l
==
3
:
append
([
COMMA
,
','
])
a
=
(
argument
,
(
test
,
(
and_test
,
(
not_test
,
(
comparison
,
(
expr
,
(
xor_expr
,
(
and_expr
,
(
shift_expr
,
(
arith_expr
,
if
l
==
3
:
append
([
COMMA
,
','
])
a
=
(
argument
,
(
test
,
(
and_test
,
(
not_test
,
(
comparison
,
(
expr
,
(
xor_expr
,
(
and_expr
,
(
shift_expr
,
(
arith_expr
,
(
term
,
(
factor
,
(
power
,
(
atom
,
(
NUMBER
,
'0'
)))))))))))))))
append
(
a
)
append
([
COMMA
,
','
])
append
(
a
)
append
([
COMMA
,
','
])
append
([
argument
,
sub
[
2
]])
else
:
append
([
COMMA
,
','
])
append
([
argument
,
sub
[
1
]])
if
l
==
4
:
append
([
COMMA
,
','
])
append
([
argument
,
sub
[
3
]])
append
([
COMMA
,
','
])
append
([
argument
,
sub
[
1
]])
if
l
==
4
:
append
([
COMMA
,
','
])
append
([
argument
,
sub
[
3
]])
return
[
power
,
[
atom
,
[
NAME
,
'__guarded_getslice__'
]],
[
trailer
,
[
LPAR
,
'('
],
args
,
[
RPAR
,
')'
],
]
]
[
trailer
,
[
LPAR
,
'('
],
args
,
[
RPAR
,
')'
],
]
]
def
item_munge
(
ast
,
i
):
# Munge an item access into a function call
...
...
@@ -188,15 +188,15 @@ def item_munge(ast, i):
append
([
COMMA
,
','
])
for
sub
in
ast
[
i
][
2
][
1
:]:
if
sub
[
0
]
==
COMMA
:
append
(
sub
)
else
:
if
len
(
sub
)
!=
2
:
raise
ParseError
,
'Invalid slice in subscript'
append
([
argument
,
sub
[
1
]])
if
sub
[
0
]
==
COMMA
:
append
(
sub
)
else
:
if
len
(
sub
)
!=
2
:
raise
ParseError
,
'Invalid slice in subscript'
append
([
argument
,
sub
[
1
]])
return
[
power
,
[
atom
,
[
NAME
,
'__guarded_getitem__'
]],
[
trailer
,
[
LPAR
,
'('
],
args
,
[
RPAR
,
')'
],
]
]
[
trailer
,
[
LPAR
,
'('
],
args
,
[
RPAR
,
')'
],
]
]
def
dot_munge
(
ast
,
i
):
# Munge an attribute access into a function call
...
...
@@ -225,8 +225,8 @@ def dot_munge(ast, i):
append
(
a
)
return
[
power
,
[
atom
,
[
NAME
,
'__guarded_getattr__'
]],
[
trailer
,
[
LPAR
,
'('
],
args
,
[
RPAR
,
')'
]],
]
[
trailer
,
[
LPAR
,
'('
],
args
,
[
RPAR
,
')'
]],
]
def
multi_munge
(
ast
):
# Munge a multiplication into a function call: __guarded_mul__
...
...
@@ -241,17 +241,17 @@ def multi_munge(ast):
append
([
COMMA
,
','
])
for
a
in
ast
:
if
a
[
0
]
==
STAR
:
args
.
append
([
COMMA
,
','
])
else
:
a
=
(
argument
,
(
test
,
(
and_test
,
(
not_test
,
(
comparison
,
if
a
[
0
]
==
STAR
:
args
.
append
([
COMMA
,
','
])
else
:
a
=
(
argument
,
(
test
,
(
and_test
,
(
not_test
,
(
comparison
,
(
expr
,
(
xor_expr
,
(
and_expr
,
(
shift_expr
,
(
arith_expr
,
(
term
,
a
)))))))))))
append
(
a
)
append
(
a
)
return
[
factor
,
[
power
,
[
atom
,
[
NAME
,
'__guarded_mul__'
]],
[
trailer
,
[
LPAR
,
'('
],
args
,
[
RPAR
,
')'
],
]]]
[
atom
,
[
NAME
,
'__guarded_mul__'
]],
[
trailer
,
[
LPAR
,
'('
],
args
,
[
RPAR
,
')'
],
]]]
def
compile
(
src
,
file_name
,
ctype
):
if
ctype
==
'eval'
:
ast
=
parser
.
expr
(
src
)
...
...
lib/python/DocumentTemplate/pDocumentTemplate.py
View file @
2ed2cfa3
...
...
@@ -54,8 +54,8 @@
__doc__
=
'''Python implementations of document template some features
$Id: pDocumentTemplate.py,v 1.1
7 1998/09/14 20:48:44
jim Exp $'''
__version__
=
'$Revision: 1.1
7
$'
[
11
:
-
2
]
$Id: pDocumentTemplate.py,v 1.1
8 1998/09/14 22:19:57
jim Exp $'''
__version__
=
'$Revision: 1.1
8
$'
[
11
:
-
2
]
import
string
,
sys
,
types
from
string
import
join
...
...
@@ -64,7 +64,7 @@ StringType=type('')
TupleType
=
type
(())
isFunctionType
=
{}
for
name
in
[
'BuiltinFunctionType'
,
'BuiltinMethodType'
,
'ClassType'
,
'FunctionType'
,
'LambdaType'
,
'MethodType'
]:
'FunctionType'
,
'LambdaType'
,
'MethodType'
]:
try
:
isFunctionType
[
getattr
(
types
,
name
)]
=
1
except
:
pass
...
...
@@ -81,40 +81,40 @@ class InstanceDict:
validate
=
None
def
__init__
(
self
,
o
,
namespace
,
validate
=
None
):
self
.
self
=
o
self
.
cache
=
{}
self
.
namespace
=
namespace
if
validate
is
None
:
self
.
validate
=
namespace
.
validate
else
:
self
.
validate
=
validate
self
.
self
=
o
self
.
cache
=
{}
self
.
namespace
=
namespace
if
validate
is
None
:
self
.
validate
=
namespace
.
validate
else
:
self
.
validate
=
validate
def
has_key
(
self
,
key
):
return
hasattr
(
self
.
self
,
key
)
return
hasattr
(
self
.
self
,
key
)
def
keys
(
self
):
return
self
.
self
.
__dict__
.
keys
()
return
self
.
self
.
__dict__
.
keys
()
def
__repr__
(
self
):
return
'InstanceDict(%s)'
%
str
(
self
.
self
)
def
__getitem__
(
self
,
key
):
cache
=
self
.
cache
if
cache
.
has_key
(
key
):
return
cache
[
key
]
inst
=
self
.
self
cache
=
self
.
cache
if
cache
.
has_key
(
key
):
return
cache
[
key
]
inst
=
self
.
self
if
key
[:
1
]
==
'_'
:
if
key
!=
'__str__'
:
raise
KeyError
,
key
# Don't divuldge private data
r
=
str
(
inst
)
else
:
try
:
r
=
getattr
(
inst
,
key
)
except
AttributeError
:
raise
KeyError
,
key
if
key
[:
1
]
==
'_'
:
if
key
!=
'__str__'
:
raise
KeyError
,
key
# Don't divuldge private data
r
=
str
(
inst
)
else
:
try
:
r
=
getattr
(
inst
,
key
)
except
AttributeError
:
raise
KeyError
,
key
v
=
self
.
validate
if
v
is
not
None
:
v
(
inst
,
inst
,
key
,
r
,
self
.
namespace
)
v
=
self
.
validate
if
v
is
not
None
:
v
(
inst
,
inst
,
key
,
r
,
self
.
namespace
)
self
.
cache
[
key
]
=
r
return
r
self
.
cache
[
key
]
=
r
return
r
class
MultiMapping
:
...
...
@@ -144,11 +144,11 @@ class TemplateDict:
def
_push
(
self
,
d
):
return
self
.
dicts
.
push
(
d
)
def
__init__
(
self
):
m
=
self
.
dicts
=
MultiMapping
()
self
.
_pop
=
m
.
pop
self
.
_push
=
m
.
push
try
:
self
.
keys
=
m
.
keys
except
:
pass
m
=
self
.
dicts
=
MultiMapping
()
self
.
_pop
=
m
.
pop
self
.
_push
=
m
.
push
try
:
self
.
keys
=
m
.
keys
except
:
pass
def
__getitem__
(
self
,
key
,
call
=
1
,
simple
=
{
...
...
@@ -157,12 +157,12 @@ class TemplateDict:
}.
has_key
):
v
=
self
.
dicts
[
key
]
if
call
and
not
simple
(
type
(
v
)):
if
call
and
not
simple
(
type
(
v
)):
if
hasattr
(
v
,
'isDocTemp'
)
and
v
.
isDocTemp
:
v
=
v
(
None
,
self
)
else
:
try
:
v
=
v
()
except
(
AttributeError
,
TypeError
):
pass
except
(
AttributeError
,
TypeError
):
pass
return
v
def
has_key
(
self
,
key
):
...
...
@@ -178,50 +178,50 @@ def render_blocks(blocks, md):
rendered
=
[]
append
=
rendered
.
append
for
section
in
blocks
:
if
type
(
section
)
is
TupleType
:
l
=
len
(
section
)
if
l
==
1
:
# Simple var
section
=
section
[
0
]
if
type
(
section
)
is
StringType
:
section
=
md
[
section
]
else
:
section
=
section
(
md
)
section
=
str
(
section
)
else
:
# if
cache
=
{}
md
.
_push
(
cache
)
try
:
i
=
0
m
=
l
-
1
while
i
<
m
:
cond
=
section
[
i
]
if
type
(
cond
)
is
StringType
:
n
=
cond
try
:
cond
=
md
[
cond
]
cache
[
n
]
=
cond
except
KeyError
,
v
:
if
type
(
section
)
is
TupleType
:
l
=
len
(
section
)
if
l
==
1
:
# Simple var
section
=
section
[
0
]
if
type
(
section
)
is
StringType
:
section
=
md
[
section
]
else
:
section
=
section
(
md
)
section
=
str
(
section
)
else
:
# if
cache
=
{}
md
.
_push
(
cache
)
try
:
i
=
0
m
=
l
-
1
while
i
<
m
:
cond
=
section
[
i
]
if
type
(
cond
)
is
StringType
:
n
=
cond
try
:
cond
=
md
[
cond
]
cache
[
n
]
=
cond
except
KeyError
,
v
:
v
=
str
(
v
)
if
n
!=
v
:
raise
KeyError
,
v
,
sys
.
exc_traceback
cond
=
None
else
:
cond
=
cond
(
md
)
if
cond
:
section
=
section
[
i
+
1
]
if
section
:
section
=
render_blocks
(
section
,
md
)
else
:
section
=
''
m
=
0
break
i
=
i
+
2
if
m
:
if
i
==
m
:
section
=
render_blocks
(
section
[
i
],
md
)
else
:
section
=
''
finally
:
md
.
_pop
()
elif
type
(
section
)
is
not
StringType
:
section
=
section
(
md
)
if
section
:
rendered
.
append
(
section
)
if
n
!=
v
:
raise
KeyError
,
v
,
sys
.
exc_traceback
cond
=
None
else
:
cond
=
cond
(
md
)
if
cond
:
section
=
section
[
i
+
1
]
if
section
:
section
=
render_blocks
(
section
,
md
)
else
:
section
=
''
m
=
0
break
i
=
i
+
2
if
m
:
if
i
==
m
:
section
=
render_blocks
(
section
[
i
],
md
)
else
:
section
=
''
finally
:
md
.
_pop
()
elif
type
(
section
)
is
not
StringType
:
section
=
section
(
md
)
if
section
:
rendered
.
append
(
section
)
l
=
len
(
rendered
)
if
l
==
0
:
return
''
...
...
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