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
6544d2da
Commit
6544d2da
authored
Sep 22, 1997
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added expr
parent
cb833537
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
90 additions
and
41 deletions
+90
-41
lib/python/DocumentTemplate/DT_If.py
lib/python/DocumentTemplate/DT_If.py
+24
-12
lib/python/DocumentTemplate/DT_In.py
lib/python/DocumentTemplate/DT_In.py
+14
-7
lib/python/DocumentTemplate/DT_Util.py
lib/python/DocumentTemplate/DT_Util.py
+27
-8
lib/python/DocumentTemplate/DT_Var.py
lib/python/DocumentTemplate/DT_Var.py
+24
-13
lib/python/DocumentTemplate/Setup
lib/python/DocumentTemplate/Setup
+1
-1
No files found.
lib/python/DocumentTemplate/DT_If.py
View file @
6544d2da
...
...
@@ -110,8 +110,8 @@ __doc__='''Conditional insertion
# (540) 371-6909
#
############################################################################
__rcs_id__
=
'$Id: DT_If.py,v 1.
2 1997/09/08 15:35:40
jim Exp $'
__version__
=
'$Revision: 1.
2
$'
[
11
:
-
2
]
__rcs_id__
=
'$Id: DT_If.py,v 1.
3 1997/09/22 14:42:49
jim Exp $'
__version__
=
'$Revision: 1.
3
$'
[
11
:
-
2
]
from
DT_Util
import
*
...
...
@@ -119,19 +119,22 @@ class If:
blockContinuations
=
'else'
,
'elif'
name
=
'if'
elses
=
None
expr
=
''
def
__init__
(
self
,
blocks
):
tname
,
args
,
section
=
blocks
[
0
]
args
=
parse_params
(
args
,
name
=
''
)
name
=
name_param
(
args
)
self
.
__name__
=
name
self
.
sections
=
[(
name
,
section
)]
args
=
parse_params
(
args
,
name
=
''
,
expr
=
''
)
name
,
expr
=
name_param
(
args
,
'if'
,
1
)
self
.
__name__
=
name
self
.
sections
=
[(
name
,
expr
,
section
)]
if
blocks
[
-
1
][
0
]
==
'else'
:
tname
,
args
,
section
=
blocks
[
-
1
]
blocks
=
blocks
[:
-
1
]
args
=
parse_params
(
args
,
name
=
''
)
if
args
:
ename
=
name_param
(
args
)
ename
,
expr
=
name_param
(
args
,
'else'
,
1
)
if
ename
!=
name
:
raise
ParseError
,
'name in else does not match if'
self
.
elses
=
section
...
...
@@ -139,16 +142,22 @@ class If:
for
tname
,
args
,
section
in
blocks
[
1
:]:
if
tname
==
'else'
:
raise
ParseError
,
'more than one else tag for a single if tag'
name
=
name_param
(
args
)
self
.
sections
.
append
((
name
,
section
))
args
=
parse_params
(
args
,
name
=
''
,
expr
=
''
)
name
,
expr
=
name_param
(
args
,
'elif'
,
1
)
self
.
sections
.
append
((
name
,
expr
,
section
))
def
render
(
self
,
md
):
for
name
,
section
in
self
.
sections
:
try
:
v
=
md
[
name
]
except
:
v
=
None
for
name
,
expr
,
section
in
self
.
sections
:
if
expr
is
None
:
try
:
v
=
md
[
name
]
except
:
v
=
None
else
:
v
=
expr
.
eval
(
md
)
if
v
:
return
section
(
None
,
md
)
if
self
.
elses
:
return
self
.
elses
(
None
,
md
)
return
''
__call__
=
render
...
...
@@ -175,6 +184,9 @@ class Else:
##########################################################################
#
# $Log: DT_If.py,v $
# Revision 1.3 1997/09/22 14:42:49 jim
# added expr
#
# Revision 1.2 1997/09/08 15:35:40 jim
# Fixed bug that caused else blocks to render if blocks.
#
...
...
lib/python/DocumentTemplate/DT_In.py
View file @
6544d2da
...
...
@@ -212,7 +212,7 @@
of the module 'Missing', if present.
'''
__rcs_id__
=
'$Id: DT_In.py,v 1.
2 1997/09/02 19:04:24
jim Exp $'
__rcs_id__
=
'$Id: DT_In.py,v 1.
3 1997/09/22 14:42:50
jim Exp $'
############################################################################
# Copyright
...
...
@@ -266,7 +266,7 @@ __rcs_id__='$Id: DT_In.py,v 1.2 1997/09/02 19:04:24 jim Exp $'
# (540) 371-6909
#
############################################################################
__version__
=
'$Revision: 1.
2
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.
3
$'
[
11
:
-
2
]
from
DT_Util
import
*
...
...
@@ -274,15 +274,16 @@ class In:
blockContinuations
=
(
'else'
,)
name
=
'in'
elses
=
None
expr
=
None
def
__init__
(
self
,
blocks
):
tname
,
args
,
section
=
blocks
[
0
]
args
=
parse_params
(
args
,
name
=
''
,
start
=
'1'
,
end
=
'-1'
,
size
=
'10'
,
orphan
=
'3'
,
overlap
=
'1'
,
mapping
=
1
,
previous
=
1
,
next
=
1
)
previous
=
1
,
next
=
1
,
expr
=
''
)
self
.
args
=
args
name
=
name_param
(
args
)
self
.
__name__
=
name
name
,
expr
=
name_param
(
args
,
'in'
,
1
)
self
.
__name__
,
expr
=
name
,
expr
self
.
section
=
section
if
len
(
blocks
)
>
1
:
if
len
(
blocks
)
!=
2
:
raise
ParseError
,
'too many else blocks'
...
...
@@ -296,8 +297,11 @@ class In:
def
render
(
self
,
md
):
try
:
sequence
=
md
[
self
.
__name__
]
or
None
except
:
sequence
=
None
expr
=
self
.
expr
if
expr
is
None
:
try
:
sequence
=
md
[
self
.
__name__
]
or
None
except
:
sequence
=
None
else
:
sequence
=
expr
.
eval
(
md
)
if
not
sequence
:
if
self
.
elses
:
return
self
.
elses
(
None
,
md
)
...
...
@@ -714,6 +718,9 @@ class sequence_variables:
############################################################################
# $Log: DT_In.py,v $
# Revision 1.3 1997/09/22 14:42:50 jim
# added expr
#
# Revision 1.2 1997/09/02 19:04:24 jim
# Got rid of ^Ms
#
...
...
lib/python/DocumentTemplate/DT_Util.py
View file @
6544d2da
'''$Id: DT_Util.py,v 1.
2 1997/09/02 20:35:09
jim Exp $'''
'''$Id: DT_Util.py,v 1.
3 1997/09/22 14:42:50
jim Exp $'''
############################################################################
# Copyright
...
...
@@ -52,13 +52,14 @@
# (540) 371-6909
#
############################################################################
__version__
=
'$Revision: 1.
2
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.
3
$'
[
11
:
-
2
]
import
sys
,
regex
,
string
,
types
,
math
,
os
from
string
import
rfind
,
strip
,
joinfields
,
atoi
,
lower
,
upper
,
capitalize
from
types
import
*
from
regsub
import
gsub
,
sub
,
split
from
__builtin__
import
*
import
VSEval
ParseError
=
'Document Template Parse Error'
...
...
@@ -78,13 +79,28 @@ class func_code:
self
.
co_varnames
=
varnames
self
.
co_argcount
=
len
(
varnames
)
def
name_param
(
params
):
if
params
.
has_key
(
''
):
if
params
.
has_key
(
'name'
):
raise
ParseError
,
'Name given twice'
def
_tm
(
m
,
tag
):
return
m
+
tag
and
(
' in %s'
%
tag
)
def
name_param
(
params
,
tag
=
''
,
expr
=
0
):
used
=
params
.
has_key
if
used
(
''
):
if
used
(
'name'
):
raise
ParseError
,
_tm
(
'Two names were given'
,
tag
)
if
expr
:
if
used
(
'expr'
):
raise
ParseError
,
_tm
(
'name and expr given'
,
tag
)
return
params
[
''
],
None
return
params
[
''
]
elif
params
.
has_key
(
'name'
):
return
params
[
'name'
]
elif
used
(
'name'
):
if
expr
:
if
used
(
'expr'
):
raise
ParseError
,
_tm
(
'name and expr given'
,
tag
)
return
params
[
'name'
],
None
return
params
[
'name'
]
elif
expr
and
used
(
'expr'
):
name
=
params
[
'expr'
]
expr
=
VSEval
.
Eval
(
name
,
__mul__
=
VSEval
.
careful_mul
,
__getattr__
=
None
)
return
name
,
expr
raise
ParseError
,
'No name given'
def
parse_params
(
text
,
...
...
@@ -157,6 +173,9 @@ except: from pDocumentTemplate import InstanceDict, TemplateDict, render_blocks
############################################################################
# $Log: DT_Util.py,v $
# Revision 1.3 1997/09/22 14:42:50 jim
# added expr
#
# Revision 1.2 1997/09/02 20:35:09 jim
# Various fixes to parsing code.
#
...
...
lib/python/DocumentTemplate/DT_Var.py
View file @
6544d2da
...
...
@@ -83,7 +83,7 @@ __doc__='''Variable insertion parameters
The parameter 'spacify' may be provided to cause underscores in
the inserted value to be converted to spaces.
'''
__rcs_id__
=
'$Id: DT_Var.py,v 1.
1 1997/08/27 18:55:44
jim Exp $'
__rcs_id__
=
'$Id: DT_Var.py,v 1.
2 1997/09/22 14:42:51
jim Exp $'
############################################################################
# Copyright
...
...
@@ -137,33 +137,33 @@ __rcs_id__='$Id: DT_Var.py,v 1.1 1997/08/27 18:55:44 jim Exp $'
# (540) 371-6909
#
############################################################################
__version__
=
'$Revision: 1.
1
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.
2
$'
[
11
:
-
2
]
from
DT_Util
import
*
class
Var
:
name
=
'var'
expr
=
None
def
__init__
(
self
,
args
,
fmt
=
''
):
args
=
parse_params
(
args
,
name
=
''
,
lower
=
1
,
upper
=
1
,
args
=
parse_params
(
args
,
name
=
''
,
lower
=
1
,
upper
=
1
,
expr
=
''
,
capitalize
=
1
,
spacify
=
1
,
null
=
''
,
fmt
=
's'
)
self
.
args
=
args
used
=
args
.
has_key
if
args
.
has_key
(
'name'
):
name
=
args
if
args
.
has_key
(
''
):
raise
ParseError
,
'Two named given in var'
elif
args
.
has_key
(
''
):
name
=
args
[
''
]
else
:
raise
ParseError
,
'No name given in var'
name
,
expr
=
name_param
(
args
,
'var'
,
1
)
self
.
__name__
=
name
self
.
__name__
,
self
.
expr
=
name
,
expr
self
.
fmt
=
fmt
def
render
(
self
,
md
):
name
=
self
.
__name__
val
=
md
[
name
]
val
=
self
.
expr
if
val
is
None
:
val
=
md
[
name
]
else
:
val
=
val
.
eval
(
md
)
__traceback_info__
=
name
,
val
# handle special formats defined using fmt= first
...
...
@@ -243,6 +243,12 @@ def dollars_and_cents_with_commas(v):
except
:
v
=
''
return
commatify
(
v
)
def
len_format
(
v
):
return
str
(
len
(
v
))
def
len_comma
(
v
):
return
commatify
(
str
(
len
(
v
)))
special_formats
=
{
'html-quote'
:
html_quote
,
'url-quote'
:
url_quote
,
...
...
@@ -251,10 +257,15 @@ special_formats={
'dollars-and-cents'
:
dollars_and_cents
,
'dollars-with-commas'
:
whole_dollars_with_commas
,
'dollars-and-cents-with-commas'
:
dollars_and_cents_with_commas
,
'collection-length'
:
len_format
,
'collection-length-with-commas'
:
len_comma
,
}
############################################################################
# $Log: DT_Var.py,v $
# Revision 1.2 1997/09/22 14:42:51 jim
# added expr
#
# Revision 1.1 1997/08/27 18:55:44 jim
# initial
#
...
...
lib/python/DocumentTemplate/Setup
View file @
6544d2da
*shared*
cDocumentTemplate cDocumentTemplate.c -I
..
/ExtensionClass
cDocumentTemplate cDocumentTemplate.c -I
/projects/_
/ExtensionClass
# install DT_Dict.py
# install DT_Doc.py
...
...
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