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