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
cbd3d223
Commit
cbd3d223
authored
Sep 14, 1998
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
untabified
parent
cad7d8e1
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
1603 additions
and
1600 deletions
+1603
-1600
lib/python/DocumentTemplate/DT_HTML.py
lib/python/DocumentTemplate/DT_HTML.py
+131
-131
lib/python/DocumentTemplate/DT_If.py
lib/python/DocumentTemplate/DT_If.py
+41
-42
lib/python/DocumentTemplate/DT_In.py
lib/python/DocumentTemplate/DT_In.py
+293
-294
lib/python/DocumentTemplate/DT_InSV.py
lib/python/DocumentTemplate/DT_InSV.py
+233
-234
lib/python/DocumentTemplate/DT_Raise.py
lib/python/DocumentTemplate/DT_Raise.py
+17
-18
lib/python/DocumentTemplate/DT_String.py
lib/python/DocumentTemplate/DT_String.py
+297
-298
lib/python/DocumentTemplate/DT_UI.py
lib/python/DocumentTemplate/DT_UI.py
+11
-11
lib/python/DocumentTemplate/DT_Util.py
lib/python/DocumentTemplate/DT_Util.py
+87
-87
lib/python/DocumentTemplate/DT_Var.py
lib/python/DocumentTemplate/DT_Var.py
+95
-96
lib/python/DocumentTemplate/DT_With.py
lib/python/DocumentTemplate/DT_With.py
+20
-20
lib/python/DocumentTemplate/DTtest.py
lib/python/DocumentTemplate/DTtest.py
+303
-304
lib/python/DocumentTemplate/DTtest_basicIn.py
lib/python/DocumentTemplate/DTtest_basicIn.py
+1
-1
lib/python/DocumentTemplate/VSEval.py
lib/python/DocumentTemplate/VSEval.py
+58
-58
lib/python/DocumentTemplate/release_notes
lib/python/DocumentTemplate/release_notes
+16
-6
No files found.
lib/python/DocumentTemplate/DT_HTML.py
View file @
cbd3d223
...
...
@@ -54,7 +54,7 @@
"""HTML formated DocumentTemplates
$Id: DT_HTML.py,v 1.1
2 1998/09/14 20:48:39
jim Exp $"""
$Id: DT_HTML.py,v 1.1
3 1998/09/14 22:03:31
jim Exp $"""
from
DT_String
import
String
,
FileMixin
import
DT_String
,
regex
...
...
@@ -64,48 +64,48 @@ from string import strip, find, split, join, rfind
class
dtml_re_class
:
def
search
(
self
,
text
,
start
=
0
,
name_match
=
regex
.
compile
(
'[
\
0
- ]*[a-zA-Z]+[
\
0
- ]*'
).
match
,
end_match
=
regex
.
compile
(
'[
\
0
- ]*
\
(/
\
|end
\
)
'
,
regex.casefold).match,
):
s=find(text,'
<
!
--
#',start)
if
s
<
0
:
return
s
e
=
find
(
text
,
'-->'
,
s
)
if
e
<
0
:
return
e
n
=
s
+
5
l
=
end_match
(
text
,
n
)
if
l
>
0
:
end
=
strip
(
text
[
n
:
n
+
l
])
n
=
n
+
l
else
:
end
=
''
l
=
name_match
(
text
,
n
)
if
l
<
0
:
return
l
a
=
n
+
l
name
=
strip
(
text
[
n
:
a
])
args
=
strip
(
text
[
a
:
e
])
d
=
self
.
__dict__
d
[
0
]
=
text
[
s
:
e
+
3
]
d
[
1
]
=
end
d
[
'end'
]
=
end
d
[
2
]
=
name
d
[
'name'
]
=
name
d
[
3
]
=
args
d
[
'args'
]
=
args
return
s
name_match
=
regex
.
compile
(
'[
\
0
- ]*[a-zA-Z]+[
\
0
- ]*'
).
match
,
end_match
=
regex
.
compile
(
'[
\
0
- ]*
\
(/
\
|end
\
)
'
,
regex.casefold).match,
):
s=find(text,'
<
!
--
#',start)
if
s
<
0
:
return
s
e
=
find
(
text
,
'-->'
,
s
)
if
e
<
0
:
return
e
n
=
s
+
5
l
=
end_match
(
text
,
n
)
if
l
>
0
:
end
=
strip
(
text
[
n
:
n
+
l
])
n
=
n
+
l
else
:
end
=
''
l
=
name_match
(
text
,
n
)
if
l
<
0
:
return
l
a
=
n
+
l
name
=
strip
(
text
[
n
:
a
])
args
=
strip
(
text
[
a
:
e
])
d
=
self
.
__dict__
d
[
0
]
=
text
[
s
:
e
+
3
]
d
[
1
]
=
end
d
[
'end'
]
=
end
d
[
2
]
=
name
d
[
'name'
]
=
name
d
[
3
]
=
args
d
[
'args'
]
=
args
return
s
def
group
(
self
,
*
args
):
g
=
self
.
__dict__
if
len
(
args
)
==
1
:
return
g
[
args
[
0
]]
r
=
[]
for
arg
in
args
:
r
.
append
(
g
[
arg
])
return
tuple
(
r
)
g
=
self
.
__dict__
if
len
(
args
)
==
1
:
return
g
[
args
[
0
]]
r
=
[]
for
arg
in
args
:
r
.
append
(
g
[
arg
])
return
tuple
(
r
)
class
HTML
(
DT_String
.
String
):
"""HTML Document Templates
...
...
@@ -123,83 +123,83 @@ class HTML(DT_String.String):
"""
def
tagre
(
self
):
return
dtml_re_class
()
return
dtml_re_class
()
def
parseTag
(
self
,
tagre
,
command
=
None
,
sargs
=
''
):
"""Parse a tag using an already matched re
"""Parse a tag using an already matched re
Return: tag, args, command, coname
Return: tag, args, command, coname
where: tag is the tag,
where: tag is the tag,
args is the tag
\
'
s argument string,
command is a corresponding command info structure if the
command is a corresponding command info structure if the
tag is a start tag, or None otherwise, and
coname is the name of a continue tag (e.g. else)
or None otherwise
"""
tag
,
end
,
name
,
args
,
=
tagre
.
group
(
0
,
'end'
,
'name'
,
'args'
)
args
=
strip
(
args
)
if
end
:
if
not
command
or
name
!=
command
.
name
:
raise
ParseError
,
(
'unexpected end tag'
,
tag
)
return
tag
,
args
,
None
,
None
if
command
and
name
in
command
.
blockContinuations
:
if
name
==
'else'
and
args
:
# Waaaaaah! Have to special case else because of
# old else start tag usage. Waaaaaaah!
l
=
len
(
args
)
if
not
(
args
==
sargs
or
args
==
sargs
[:
l
]
and
sargs
[
l
:
l
+
1
]
in
'
\
t
\
n
'
):
return
tag
,
args
,
self
.
commands
[
name
],
None
return
tag
,
args
,
None
,
name
try
:
return
tag
,
args
,
self
.
commands
[
name
],
None
except
KeyError
:
raise
ParseError
,
(
'Unexpected tag'
,
tag
)
coname is the name of a continue tag (e.g. else)
or None otherwise
"""
tag
,
end
,
name
,
args
,
=
tagre
.
group
(
0
,
'end'
,
'name'
,
'args'
)
args
=
strip
(
args
)
if
end
:
if
not
command
or
name
!=
command
.
name
:
raise
ParseError
,
(
'unexpected end tag'
,
tag
)
return
tag
,
args
,
None
,
None
if
command
and
name
in
command
.
blockContinuations
:
if
name
==
'else'
and
args
:
# Waaaaaah! Have to special case else because of
# old else start tag usage. Waaaaaaah!
l
=
len
(
args
)
if
not
(
args
==
sargs
or
args
==
sargs
[:
l
]
and
sargs
[
l
:
l
+
1
]
in
'
\
t
\
n
'
):
return
tag
,
args
,
self
.
commands
[
name
],
None
return
tag
,
args
,
None
,
name
try
:
return
tag
,
args
,
self
.
commands
[
name
],
None
except
KeyError
:
raise
ParseError
,
(
'Unexpected tag'
,
tag
)
def
SubTemplate
(
self
,
name
):
return
HTML
(
''
,
__name__
=
name
)
def
varExtra
(
self
,
tagre
):
return
's'
def
manage_edit
(
self
,
data
,
REQUEST
=
None
):
'edit a template'
self
.
munge
(
data
)
if
REQUEST
:
return
self
.
editConfirmation
(
self
,
REQUEST
)
'edit a template'
self
.
munge
(
data
)
if
REQUEST
:
return
self
.
editConfirmation
(
self
,
REQUEST
)
def
quotedHTML
(
self
,
text
=
None
,
character_entities
=
(
((
'&'
),
'&'
),
((
"<"
),
'<'
),
((
">"
),
'>'
),
((
'"'
),
'"'
))):
#"
text
=
None
,
character_entities
=
(
((
'&'
),
'&'
),
((
"<"
),
'<'
),
((
">"
),
'>'
),
((
'"'
),
'"'
))):
#"
if
text
is
None
:
text
=
self
.
read_raw
()
for
re
,
name
in
character_entities
:
for
re
,
name
in
character_entities
:
if
find
(
text
,
re
)
>=
0
:
text
=
join
(
split
(
text
,
re
),
name
)
return
text
return
text
errQuote
=
quotedHTML
def
__str__
(
self
):
return
self
.
quotedHTML
()
return
self
.
quotedHTML
()
def
management_interface
(
self
):
'''Hook to allow public execution of management interface with
everything else private.'''
return
self
'''Hook to allow public execution of management interface with
everything else private.'''
return
self
def
manage_editForm
(
self
,
PARENT_URL
,
REQUEST
):
'''Display doc template editing form'''
#"
return
self
.
_manage_editForm
(
self
,
mapping
=
REQUEST
,
__str__
=
str
(
self
),
PARENT_URL
=
PARENT_URL
)
'''Display doc template editing form'''
#"
return
self
.
_manage_editForm
(
self
,
mapping
=
REQUEST
,
__str__
=
str
(
self
),
PARENT_URL
=
PARENT_URL
)
manage_editDocument
=
manage
=
manage_editForm
...
...
@@ -213,10 +213,10 @@ class HTMLDefault(HTML):
copy_class
=
HTML
def
manage_edit
(
self
,
data
,
PARENTS
,
URL1
,
REQUEST
):
'edit a template'
newHTML
=
self
.
copy_class
(
data
,
self
.
globals
,
self
.
__name__
)
setattr
(
PARENTS
[
1
],
URL1
[
rfind
(
URL1
,
'/'
)
+
1
:],
newHTML
)
return
self
.
editConfirmation
(
self
,
REQUEST
)
'edit a template'
newHTML
=
self
.
copy_class
(
data
,
self
.
globals
,
self
.
__name__
)
setattr
(
PARENTS
[
1
],
URL1
[
rfind
(
URL1
,
'/'
)
+
1
:],
newHTML
)
return
self
.
editConfirmation
(
self
,
REQUEST
)
class
HTMLFile
(
FileMixin
,
HTML
):
...
...
@@ -231,45 +231,45 @@ class HTMLFile(FileMixin, HTML):
"""
def
manage_default
(
self
,
REQUEST
=
None
):
'Revert to factory defaults'
if
self
.
edited_source
:
self
.
edited_source
=
''
self
.
cooked
=
self
.
cook
()
if
REQUEST
:
return
self
.
editConfirmation
(
self
,
REQUEST
)
'Revert to factory defaults'
if
self
.
edited_source
:
self
.
edited_source
=
''
self
.
cooked
=
self
.
cook
()
if
REQUEST
:
return
self
.
editConfirmation
(
self
,
REQUEST
)
def
manage_editForm
(
self
,
PARENT_URL
,
REQUEST
):
'''Display doc template editing form'''
return
self
.
_manage_editForm
(
mapping
=
REQUEST
,
document_template_edit_width
=
self
.
document_template_edit_width
,
document_template_edit_header
=
self
.
document_template_edit_header
,
document_template_form_header
=
self
.
document_template_form_header
,
document_template_edit_footer
=
self
.
document_template_edit_footer
,
PARENT_URL
=
PARENT_URL
,
__str__
=
str
(
self
),
FactoryDefaultString
=
FactoryDefaultString
,
)
'''Display doc template editing form'''
return
self
.
_manage_editForm
(
mapping
=
REQUEST
,
document_template_edit_width
=
self
.
document_template_edit_width
,
document_template_edit_header
=
self
.
document_template_edit_header
,
document_template_form_header
=
self
.
document_template_form_header
,
document_template_edit_footer
=
self
.
document_template_edit_footer
,
PARENT_URL
=
PARENT_URL
,
__str__
=
str
(
self
),
FactoryDefaultString
=
FactoryDefaultString
,
)
manage_editDocument
=
manage
=
manage_editForm
def
manage_edit
(
self
,
data
,
PARENTS
=
[],
URL1
=
''
,
URL2
=
''
,
REQUEST
=
''
,
SUBMIT
=
''
):
'edit a template'
if
SUBMIT
==
FactoryDefaultString
:
return
self
.
manage_default
(
REQUEST
)
PARENTS
=
[],
URL1
=
''
,
URL2
=
''
,
REQUEST
=
''
,
SUBMIT
=
''
):
'edit a template'
if
SUBMIT
==
FactoryDefaultString
:
return
self
.
manage_default
(
REQUEST
)
if
find
(
data
,
'
\
r
'
):
data
=
join
(
split
(
data
,
'
\
r
\
n
'
),
'
\
n
\
r
'
)
data
=
join
(
split
(
data
,
'
\
n
\
r
'
),
'
\
n
'
)
if
self
.
edited_source
:
self
.
edited_source
=
data
self
.
cooked
=
self
.
cook
()
else
:
__traceback_info__
=
self
.
__class__
newHTML
=
self
.
__class__
()
newHTML
.
__setstate__
(
self
.
__getstate__
())
newHTML
.
edited_source
=
data
setattr
(
PARENTS
[
1
],
URL1
[
rfind
(
URL1
,
'/'
)
+
1
:],
newHTML
)
if
REQUEST
:
return
self
.
editConfirmation
(
self
,
REQUEST
)
if
self
.
edited_source
:
self
.
edited_source
=
data
self
.
cooked
=
self
.
cook
()
else
:
__traceback_info__
=
self
.
__class__
newHTML
=
self
.
__class__
()
newHTML
.
__setstate__
(
self
.
__getstate__
())
newHTML
.
edited_source
=
data
setattr
(
PARENTS
[
1
],
URL1
[
rfind
(
URL1
,
'/'
)
+
1
:],
newHTML
)
if
REQUEST
:
return
self
.
editConfirmation
(
self
,
REQUEST
)
lib/python/DocumentTemplate/DT_If.py
View file @
cbd3d223
...
...
@@ -117,8 +117,8 @@ __doc__='''Conditional insertion
variable is not reevaluated.
'''
__rcs_id__
=
'$Id: DT_If.py,v 1.1
3 1998/09/14 20:48:39
jim Exp $'
__version__
=
'$Revision: 1.1
3
$'
[
11
:
-
2
]
__rcs_id__
=
'$Id: DT_If.py,v 1.1
4 1998/09/14 22:03:31
jim Exp $'
__version__
=
'$Revision: 1.1
4
$'
[
11
:
-
2
]
from
DT_Util
import
ParseError
,
parse_params
,
name_param
,
str
...
...
@@ -130,53 +130,52 @@ class If:
def
__init__
(
self
,
blocks
):
tname
,
args
,
section
=
blocks
[
0
]
args
=
parse_params
(
args
,
name
=
''
,
expr
=
''
)
name
,
expr
=
name_param
(
args
,
'if'
,
1
)
self
.
__name__
=
name
if
expr
is
None
:
cond
=
name
else
:
cond
=
expr
.
eval
sections
=
[
cond
,
section
.
blocks
]
if
blocks
[
-
1
][
0
]
==
'else'
:
tname
,
args
,
section
=
blocks
[
-
1
]
del
blocks
[
-
1
]
args
=
parse_params
(
args
,
name
=
''
)
if
args
:
ename
,
expr
=
name_param
(
args
,
'else'
,
1
)
if
ename
!=
name
:
raise
ParseError
,
(
'name in else does not match if'
,
'in'
)
elses
=
section
.
blocks
else
:
elses
=
None
for
tname
,
args
,
section
in
blocks
[
1
:]:
if
tname
==
'else'
:
raise
ParseError
,
(
'more than one else tag for a single if tag'
,
'in'
)
args
=
parse_params
(
args
,
name
=
''
,
expr
=
''
)
name
,
expr
=
name_param
(
args
,
'elif'
,
1
)
if
expr
is
None
:
cond
=
name
else
:
cond
=
expr
.
eval
sections
.
append
(
cond
)
sections
.
append
(
section
.
blocks
)
if
elses
is
not
None
:
sections
.
append
(
elses
)
self
.
simple_form
=
tuple
(
sections
)
tname
,
args
,
section
=
blocks
[
0
]
args
=
parse_params
(
args
,
name
=
''
,
expr
=
''
)
name
,
expr
=
name_param
(
args
,
'if'
,
1
)
self
.
__name__
=
name
if
expr
is
None
:
cond
=
name
else
:
cond
=
expr
.
eval
sections
=
[
cond
,
section
.
blocks
]
if
blocks
[
-
1
][
0
]
==
'else'
:
tname
,
args
,
section
=
blocks
[
-
1
]
del
blocks
[
-
1
]
args
=
parse_params
(
args
,
name
=
''
)
if
args
:
ename
,
expr
=
name_param
(
args
,
'else'
,
1
)
if
ename
!=
name
:
raise
ParseError
,
(
'name in else does not match if'
,
'in'
)
elses
=
section
.
blocks
else
:
elses
=
None
for
tname
,
args
,
section
in
blocks
[
1
:]:
if
tname
==
'else'
:
raise
ParseError
,
(
'more than one else tag for a single if tag'
,
'in'
)
args
=
parse_params
(
args
,
name
=
''
,
expr
=
''
)
name
,
expr
=
name_param
(
args
,
'elif'
,
1
)
if
expr
is
None
:
cond
=
name
else
:
cond
=
expr
.
eval
sections
.
append
(
cond
)
sections
.
append
(
section
.
blocks
)
if
elses
is
not
None
:
sections
.
append
(
elses
)
self
.
simple_form
=
tuple
(
sections
)
class
Unless
:
name
=
'unless'
blockContinuations
=
()
def
__init__
(
self
,
blocks
):
tname
,
args
,
section
=
blocks
[
0
]
args
=
parse_params
(
args
,
name
=
''
,
expr
=
''
)
name
,
expr
=
name_param
(
args
,
'unless'
,
1
)
if
expr
is
None
:
cond
=
name
else
:
cond
=
expr
.
eval
self
.
simple_form
=
(
cond
,
None
,
section
.
blocks
)
tname
,
args
,
section
=
blocks
[
0
]
args
=
parse_params
(
args
,
name
=
''
,
expr
=
''
)
name
,
expr
=
name_param
(
args
,
'unless'
,
1
)
if
expr
is
None
:
cond
=
name
else
:
cond
=
expr
.
eval
self
.
simple_form
=
(
cond
,
None
,
section
.
blocks
)
class
Else
(
Unless
):
# The else tag is included for backward compatibility and is deprecated.
name
=
'else'
lib/python/DocumentTemplate/DT_In.py
View file @
cbd3d223
...
...
@@ -86,8 +86,8 @@
A more complete case is used as follows::
<!--#in sequence sort=age-->
<!--#var sequence-number-->) <!--#var age-->
<!--#/in-->
<!--#var sequence-number-->) <!--#var age-->
<!--#/in-->
Attributes
...
...
@@ -100,15 +100,15 @@
'sequence-item' -- The element.
'sequence-var-nnn' -- The value of a specific named attribute
of the item, where 'nnn' is the name. For example, to get
an items 'title' attribute, use 'sequence-var-title'. This
construct is most useful in an 'if' tag to test whether an
attribute is present, because the attribute lookup will be
extended to the full document template namespace.
'sequence-var-nnn' -- The value of a specific named attribute
of the item, where 'nnn' is the name. For example, to get
an items 'title' attribute, use 'sequence-var-title'. This
construct is most useful in an 'if' tag to test whether an
attribute is present, because the attribute lookup will be
extended to the full document template namespace.
'sequence-key' -- The key associated with the element in an
items list. See below.
'sequence-key' -- The key associated with the element in an
items list. See below.
'sequence-index' -- The index, starting from 0, of the
element within the sequence.
...
...
@@ -190,9 +190,9 @@
attribute removed. This is extremely useful when
building URLs to fetch another batch.
To see how this is used, consider the following example::
To see how this is used, consider the following example::
<!--#in search_results size=20 start=batch_start-->
<!--#in search_results size=20 start=batch_start-->
... display rows
...
...
@@ -204,18 +204,18 @@
</a>
<!--#/if--> <!--#/if-->
<!--#/in-->
<!--#/in-->
If the original URL is: 'foo/bar?x=1&y=2', then the
rendered text (after row data are displated) will be::
If the original URL is: 'foo/bar?x=1&y=2', then the
rendered text (after row data are displated) will be::
<a href="foo/bar?x=1&y=2&batch_start=20">
(Next 20 results)
</a>
If the original URL is: 'foo/bar?batch_start=10&x=1&y=2',
then the rendered text (after row data are displated)
will be::
If the original URL is: 'foo/bar?batch_start=10&x=1&y=2',
then the rendered text (after row data are displated)
will be::
<a href="foo/bar?x=1&y=2&batch_start=30">
(Next 20 results)
...
...
@@ -307,29 +307,29 @@
Currently supported statistic names are:
total -- The total of numeric values.
total -- The total of numeric values.
count -- The total number of non-missing values.
count -- The total number of non-missing values.
min -- The minimum of non-missing values.
min -- The minimum of non-missing values.
max -- The maximum of non-missing values.
max -- The maximum of non-missing values.
median -- The median of non-missing values.
median -- The median of non-missing values.
mean -- The mean of numeric values values.
mean -- The mean of numeric values values.
variance -- The variance of numeric values computed with a
degrees of freedom qeual to the count - 1.
variance -- The variance of numeric values computed with a
degrees of freedom qeual to the count - 1.
variance-n -- The variance of numeric values computed with a
degrees of freedom qeual to the count.
variance-n -- The variance of numeric values computed with a
degrees of freedom qeual to the count.
standard-deviation -- The standard deviation of numeric values
computed with a degrees of freedom qeual to the count - 1.
standard-deviation -- The standard deviation of numeric values
computed with a degrees of freedom qeual to the count - 1.
standard-deviation-n -- The standard deviation of numeric
values computed with a degrees of freedom qeual to the count.
standard-deviation-n -- The standard deviation of numeric
values computed with a degrees of freedom qeual to the count.
Missing values are either 'None' or the attribute 'Value'
of the module 'Missing', if present.
...
...
@@ -342,15 +342,15 @@
- The sequence given to the 'in' tag is of zero length, or
- The 'previous' attribute was used and their are no
previous batches, or
previous batches, or
- The 'next' attribute was used and their are no
next batches, or
next batches, or
'''
#'
__rcs_id__
=
'$Id: DT_In.py,v 1.
29 1998/09/14 20:48:40
jim Exp $'
__version__
=
'$Revision: 1.
29
$'
[
11
:
-
2
]
__rcs_id__
=
'$Id: DT_In.py,v 1.
30 1998/09/14 22:03:32
jim Exp $'
__version__
=
'$Revision: 1.
30
$'
[
11
:
-
2
]
from
DT_Util
import
ParseError
,
parse_params
,
name_param
,
str
from
DT_Util
import
render_blocks
,
InstanceDict
...
...
@@ -364,9 +364,9 @@ class InFactory:
name
=
'in'
def
__call__
(
self
,
blocks
):
i
=
InClass
(
blocks
)
if
i
.
batch
:
return
i
.
renderwb
else
:
return
i
.
renderwob
i
=
InClass
(
blocks
)
if
i
.
batch
:
return
i
.
renderwb
else
:
return
i
.
renderwob
In
=
InFactory
()
...
...
@@ -376,143 +376,143 @@ class InClass:
start_name_re
=
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
,
skip_unauthorized
=
1
,
previous
=
1
,
next
=
1
,
expr
=
''
,
sort
=
''
)
self
.
args
=
args
has_key
=
args
.
has_key
if
has_key
(
'sort'
):
self
.
sort
=
args
[
'sort'
]
if
has_key
(
'mapping'
):
self
.
mapping
=
args
[
'mapping'
]
for
n
in
'start'
,
'size'
,
'end'
:
if
has_key
(
n
):
self
.
batch
=
1
for
n
in
'orphan'
,
'overlap'
,
'previous'
,
'next'
:
if
has_key
(
n
)
and
not
self
.
batch
:
raise
ParseError
,
(
"""
The %s attribute was used but neither of the
<code>start</code>, <code>end</code>, or <code>size</code>
attributes were used.
"""
%
n
,
'in'
)
if
has_key
(
'start'
):
v
=
args
[
'start'
]
if
type
(
v
)
==
type
(
''
):
try
:
atoi
(
v
)
except
:
self
.
start_name_re
=
ts_regex
.
compile
(
'&+'
+
join
(
map
(
lambda
c
:
"[%s]"
%
c
,
v
),
''
)
+
'=[0-9]+&+'
)
name
,
expr
=
name_param
(
args
,
'in'
,
1
)
if
expr
is
not
None
:
expr
=
expr
.
eval
self
.
__name__
,
self
.
expr
=
name
,
expr
self
.
section
=
section
.
blocks
if
len
(
blocks
)
>
1
:
if
len
(
blocks
)
!=
2
:
raise
ParseError
,
(
'too many else blocks'
,
'in'
)
tname
,
args
,
section
=
blocks
[
1
]
args
=
parse_params
(
args
,
name
=
''
)
if
args
:
ename
=
name_param
(
args
)
if
ename
!=
name
:
raise
ParseError
,
(
'name in else does not match in'
,
'in'
)
self
.
elses
=
section
.
blocks
tname
,
args
,
section
=
blocks
[
0
]
args
=
parse_params
(
args
,
name
=
''
,
start
=
'1'
,
end
=
'-1'
,
size
=
'10'
,
orphan
=
'3'
,
overlap
=
'1'
,
mapping
=
1
,
skip_unauthorized
=
1
,
previous
=
1
,
next
=
1
,
expr
=
''
,
sort
=
''
)
self
.
args
=
args
has_key
=
args
.
has_key
if
has_key
(
'sort'
):
self
.
sort
=
args
[
'sort'
]
if
has_key
(
'mapping'
):
self
.
mapping
=
args
[
'mapping'
]
for
n
in
'start'
,
'size'
,
'end'
:
if
has_key
(
n
):
self
.
batch
=
1
for
n
in
'orphan'
,
'overlap'
,
'previous'
,
'next'
:
if
has_key
(
n
)
and
not
self
.
batch
:
raise
ParseError
,
(
"""
The %s attribute was used but neither of the
<code>start</code>, <code>end</code>, or <code>size</code>
attributes were used.
"""
%
n
,
'in'
)
if
has_key
(
'start'
):
v
=
args
[
'start'
]
if
type
(
v
)
==
type
(
''
):
try
:
atoi
(
v
)
except
:
self
.
start_name_re
=
ts_regex
.
compile
(
'&+'
+
join
(
map
(
lambda
c
:
"[%s]"
%
c
,
v
),
''
)
+
'=[0-9]+&+'
)
name
,
expr
=
name_param
(
args
,
'in'
,
1
)
if
expr
is
not
None
:
expr
=
expr
.
eval
self
.
__name__
,
self
.
expr
=
name
,
expr
self
.
section
=
section
.
blocks
if
len
(
blocks
)
>
1
:
if
len
(
blocks
)
!=
2
:
raise
ParseError
,
(
'too many else blocks'
,
'in'
)
tname
,
args
,
section
=
blocks
[
1
]
args
=
parse_params
(
args
,
name
=
''
)
if
args
:
ename
=
name_param
(
args
)
if
ename
!=
name
:
raise
ParseError
,
(
'name in else does not match in'
,
'in'
)
self
.
elses
=
section
.
blocks
def
renderwb
(
self
,
md
):
expr
=
self
.
expr
name
=
self
.
__name__
if
expr
is
None
:
sequence
=
md
[
name
]
cache
=
{
name
:
sequence
}
else
:
sequence
=
expr
(
md
)
cache
=
None
if
not
sequence
:
if
self
.
elses
:
return
render_blocks
(
self
.
elses
,
md
)
return
''
section
=
self
.
section
params
=
self
.
args
mapping
=
self
.
mapping
if
self
.
sort
is
not
None
:
sequence
=
self
.
sort_sequence
(
sequence
)
next
=
previous
=
0
try
:
start
=
int_param
(
params
,
md
,
'start'
,
0
)
except
:
start
=
1
end
=
int_param
(
params
,
md
,
'end'
,
0
)
size
=
int_param
(
params
,
md
,
'size'
,
0
)
overlap
=
int_param
(
params
,
md
,
'overlap'
,
0
)
orphan
=
int_param
(
params
,
md
,
'orphan'
,
'3'
)
start
,
end
,
sz
=
opt
(
start
,
end
,
size
,
orphan
,
sequence
)
if
params
.
has_key
(
'next'
):
next
=
1
if
params
.
has_key
(
'previous'
):
previous
=
1
last
=
end
-
1
first
=
start
-
1
try
:
query_string
=
md
[
'QUERY_STRING'
]
except
:
query_string
=
''
vars
=
sequence_variables
(
sequence
,
'?'
+
query_string
,
self
.
start_name_re
)
kw
=
vars
.
data
kw
[
'mapping'
]
=
mapping
kw
[
'sequence-step-size'
]
=
sz
kw
[
'sequence-step-overlap'
]
=
overlap
kw
[
'sequence-step-start'
]
=
start
kw
[
'sequence-step-end'
]
=
end
kw
[
'sequence-step-start-index'
]
=
start
-
1
kw
[
'sequence-step-end-index'
]
=
end
-
1
kw
[
'sequence-step-orphan'
]
=
orphan
push
=
md
.
_push
pop
=
md
.
_pop
render
=
render_blocks
if
cache
:
push
(
cache
)
push
(
vars
)
try
:
if
previous
:
if
first
>
0
:
pstart
,
pend
,
psize
=
opt
(
None
,
first
+
overlap
,
sz
,
orphan
,
sequence
)
kw
[
'previous-sequence'
]
=
1
kw
[
'previous-sequence-start-index'
]
=
pstart
-
1
kw
[
'previous-sequence-end-index'
]
=
pend
-
1
kw
[
'previous-sequence-size'
]
=
pend
+
1
-
pstart
result
=
render
(
section
,
md
)
elif
self
.
elses
:
result
=
render
(
self
.
elses
,
md
)
else
:
result
=
''
elif
next
:
try
:
# The following line is a sneaky way to test whether
# there are more items, without actually
# computing a length:
sequence
[
end
]
pstart
,
pend
,
psize
=
opt
(
end
+
1
-
overlap
,
None
,
sz
,
orphan
,
sequence
)
kw
[
'next-sequence'
]
=
1
kw
[
'next-sequence-start-index'
]
=
pstart
-
1
kw
[
'next-sequence-end-index'
]
=
pend
-
1
kw
[
'next-sequence-size'
]
=
pend
+
1
-
pstart
result
=
render
(
section
,
md
)
except
:
if
self
.
elses
:
result
=
render
(
self
.
elses
,
md
)
else
:
result
=
''
else
:
expr
=
self
.
expr
name
=
self
.
__name__
if
expr
is
None
:
sequence
=
md
[
name
]
cache
=
{
name
:
sequence
}
else
:
sequence
=
expr
(
md
)
cache
=
None
if
not
sequence
:
if
self
.
elses
:
return
render_blocks
(
self
.
elses
,
md
)
return
''
section
=
self
.
section
params
=
self
.
args
mapping
=
self
.
mapping
if
self
.
sort
is
not
None
:
sequence
=
self
.
sort_sequence
(
sequence
)
next
=
previous
=
0
try
:
start
=
int_param
(
params
,
md
,
'start'
,
0
)
except
:
start
=
1
end
=
int_param
(
params
,
md
,
'end'
,
0
)
size
=
int_param
(
params
,
md
,
'size'
,
0
)
overlap
=
int_param
(
params
,
md
,
'overlap'
,
0
)
orphan
=
int_param
(
params
,
md
,
'orphan'
,
'3'
)
start
,
end
,
sz
=
opt
(
start
,
end
,
size
,
orphan
,
sequence
)
if
params
.
has_key
(
'next'
):
next
=
1
if
params
.
has_key
(
'previous'
):
previous
=
1
last
=
end
-
1
first
=
start
-
1
try
:
query_string
=
md
[
'QUERY_STRING'
]
except
:
query_string
=
''
vars
=
sequence_variables
(
sequence
,
'?'
+
query_string
,
self
.
start_name_re
)
kw
=
vars
.
data
kw
[
'mapping'
]
=
mapping
kw
[
'sequence-step-size'
]
=
sz
kw
[
'sequence-step-overlap'
]
=
overlap
kw
[
'sequence-step-start'
]
=
start
kw
[
'sequence-step-end'
]
=
end
kw
[
'sequence-step-start-index'
]
=
start
-
1
kw
[
'sequence-step-end-index'
]
=
end
-
1
kw
[
'sequence-step-orphan'
]
=
orphan
push
=
md
.
_push
pop
=
md
.
_pop
render
=
render_blocks
if
cache
:
push
(
cache
)
push
(
vars
)
try
:
if
previous
:
if
first
>
0
:
pstart
,
pend
,
psize
=
opt
(
None
,
first
+
overlap
,
sz
,
orphan
,
sequence
)
kw
[
'previous-sequence'
]
=
1
kw
[
'previous-sequence-start-index'
]
=
pstart
-
1
kw
[
'previous-sequence-end-index'
]
=
pend
-
1
kw
[
'previous-sequence-size'
]
=
pend
+
1
-
pstart
result
=
render
(
section
,
md
)
elif
self
.
elses
:
result
=
render
(
self
.
elses
,
md
)
else
:
result
=
''
elif
next
:
try
:
# The following line is a sneaky way to test whether
# there are more items, without actually
# computing a length:
sequence
[
end
]
pstart
,
pend
,
psize
=
opt
(
end
+
1
-
overlap
,
None
,
sz
,
orphan
,
sequence
)
kw
[
'next-sequence'
]
=
1
kw
[
'next-sequence-start-index'
]
=
pstart
-
1
kw
[
'next-sequence-end-index'
]
=
pend
-
1
kw
[
'next-sequence-size'
]
=
pend
+
1
-
pstart
result
=
render
(
section
,
md
)
except
:
if
self
.
elses
:
result
=
render
(
self
.
elses
,
md
)
else
:
result
=
''
else
:
result
=
[]
append
=
result
.
append
validate
=
md
.
validate
validate
=
md
.
validate
for
index
in
range
(
first
,
end
):
if
index
==
first
and
index
>
0
:
pstart
,
pend
,
psize
=
opt
(
None
,
index
+
overlap
,
...
...
@@ -537,154 +537,153 @@ class InClass:
kw
[
'next-sequence-end-index'
]
=
pend
-
1
kw
[
'next-sequence-size'
]
=
pend
+
1
-
pstart
except
:
pass
if
index
==
last
:
kw
[
'sequence-end'
]
=
1
if
index
==
last
:
kw
[
'sequence-end'
]
=
1
client
=
sequence
[
index
]
client
=
sequence
[
index
]
if
validate
is
not
None
:
try
:
vv
=
validate
(
sequence
,
sequence
,
index
,
client
,
md
)
except
:
vv
=
0
if
not
vv
:
if
(
params
.
has_key
(
'skip_unauthorized'
)
and
params
[
'skip_unauthorized'
]):
if
index
==
first
:
kw
[
'sequence-start'
]
=
0
continue
raise
ValidationError
,
index
if
validate
is
not
None
:
try
:
vv
=
validate
(
sequence
,
sequence
,
index
,
client
,
md
)
except
:
vv
=
0
if
not
vv
:
if
(
params
.
has_key
(
'skip_unauthorized'
)
and
params
[
'skip_unauthorized'
]):
if
index
==
first
:
kw
[
'sequence-start'
]
=
0
continue
raise
ValidationError
,
index
kw
[
'sequence-index'
]
=
index
if
type
(
client
)
==
TupleType
and
len
(
client
)
==
2
:
client
=
client
[
1
]
kw
[
'sequence-index'
]
=
index
if
type
(
client
)
==
TupleType
and
len
(
client
)
==
2
:
client
=
client
[
1
]
if
mapping
:
push
(
client
)
else
:
push
(
InstanceDict
(
client
,
md
))
if
mapping
:
push
(
client
)
else
:
push
(
InstanceDict
(
client
,
md
))
try
:
append
(
render
(
section
,
md
))
finally
:
pop
(
1
)
try
:
append
(
render
(
section
,
md
))
finally
:
pop
(
1
)
if
index
==
first
:
kw
[
'sequence-start'
]
=
0
if
index
==
first
:
kw
[
'sequence-start'
]
=
0
result
=
join
(
result
,
''
)
result
=
join
(
result
,
''
)
finally
:
if
cache
:
pop
()
pop
()
finally
:
if
cache
:
pop
()
pop
()
return
result
return
result
def
renderwob
(
self
,
md
):
expr
=
self
.
expr
name
=
self
.
__name__
if
expr
is
None
:
sequence
=
md
[
name
]
cache
=
{
name
:
sequence
}
else
:
sequence
=
expr
(
md
)
cache
=
None
if
not
sequence
:
if
self
.
elses
:
return
render_blocks
(
self
.
elses
,
md
)
return
''
section
=
self
.
section
mapping
=
self
.
mapping
if
self
.
sort
is
not
None
:
sequence
=
self
.
sort_sequence
(
sequence
)
vars
=
sequence_variables
(
sequence
)
kw
=
vars
.
data
kw
[
'mapping'
]
=
mapping
l
=
len
(
sequence
)
last
=
l
-
1
push
=
md
.
_push
pop
=
md
.
_pop
render
=
render_blocks
if
cache
:
push
(
cache
)
push
(
vars
)
try
:
result
=
[]
append
=
result
.
append
validate
=
md
.
validate
for
index
in
range
(
l
):
if
index
==
last
:
kw
[
'sequence-end'
]
=
1
client
=
sequence
[
index
]
if
validate
is
not
None
:
try
:
vv
=
validate
(
sequence
,
sequence
,
index
,
client
,
md
)
except
:
vv
=
0
if
not
vv
:
if
(
self
.
args
.
has_key
(
'skip_unauthorized'
)
and
self
.
args
[
'skip_unauthorized'
]):
if
index
==
1
:
kw
[
'sequence-start'
]
=
0
continue
raise
ValidationError
,
index
kw
[
'sequence-index'
]
=
index
if
type
(
client
)
==
TupleType
and
len
(
client
)
==
2
:
client
=
client
[
1
]
if
mapping
:
push
(
client
)
else
:
push
(
InstanceDict
(
client
,
md
))
try
:
append
(
render
(
section
,
md
))
finally
:
pop
()
if
index
==
0
:
kw
[
'sequence-start'
]
=
0
result
=
join
(
result
,
''
)
finally
:
if
cache
:
pop
()
pop
()
return
result
expr
=
self
.
expr
name
=
self
.
__name__
if
expr
is
None
:
sequence
=
md
[
name
]
cache
=
{
name
:
sequence
}
else
:
sequence
=
expr
(
md
)
cache
=
None
if
not
sequence
:
if
self
.
elses
:
return
render_blocks
(
self
.
elses
,
md
)
return
''
section
=
self
.
section
mapping
=
self
.
mapping
if
self
.
sort
is
not
None
:
sequence
=
self
.
sort_sequence
(
sequence
)
vars
=
sequence_variables
(
sequence
)
kw
=
vars
.
data
kw
[
'mapping'
]
=
mapping
l
=
len
(
sequence
)
last
=
l
-
1
push
=
md
.
_push
pop
=
md
.
_pop
render
=
render_blocks
if
cache
:
push
(
cache
)
push
(
vars
)
try
:
result
=
[]
append
=
result
.
append
validate
=
md
.
validate
for
index
in
range
(
l
):
if
index
==
last
:
kw
[
'sequence-end'
]
=
1
client
=
sequence
[
index
]
if
validate
is
not
None
:
try
:
vv
=
validate
(
sequence
,
sequence
,
index
,
client
,
md
)
except
:
vv
=
0
if
not
vv
:
if
(
self
.
args
.
has_key
(
'skip_unauthorized'
)
and
self
.
args
[
'skip_unauthorized'
]):
if
index
==
1
:
kw
[
'sequence-start'
]
=
0
continue
raise
ValidationError
,
index
kw
[
'sequence-index'
]
=
index
if
type
(
client
)
==
TupleType
and
len
(
client
)
==
2
:
client
=
client
[
1
]
if
mapping
:
push
(
client
)
else
:
push
(
InstanceDict
(
client
,
md
))
try
:
append
(
render
(
section
,
md
))
finally
:
pop
()
if
index
==
0
:
kw
[
'sequence-start'
]
=
0
result
=
join
(
result
,
''
)
finally
:
if
cache
:
pop
()
pop
()
return
result
def
sort_sequence
(
self
,
sequence
):
sort
=
self
.
sort
mapping
=
self
.
mapping
isort
=
not
sort
k
=
None
s
=
[]
for
client
in
sequence
:
if
type
(
client
)
==
TupleType
and
len
(
client
)
==
2
:
if
isort
:
k
=
client
[
0
]
v
=
client
[
1
]
else
:
if
isort
:
k
=
client
v
=
client
sort
=
self
.
sort
mapping
=
self
.
mapping
isort
=
not
sort
k
=
None
s
=
[]
for
client
in
sequence
:
if
type
(
client
)
==
TupleType
and
len
(
client
)
==
2
:
if
isort
:
k
=
client
[
0
]
v
=
client
[
1
]
else
:
if
isort
:
k
=
client
v
=
client
if
sort
:
if
mapping
:
k
=
v
[
sort
]
else
:
k
=
getattr
(
v
,
sort
)
if
not
basic_type
(
k
):
try
:
k
=
k
()
except
:
pass
if
sort
:
if
mapping
:
k
=
v
[
sort
]
else
:
k
=
getattr
(
v
,
sort
)
if
not
basic_type
(
k
):
try
:
k
=
k
()
except
:
pass
s
.
append
((
k
,
client
))
s
.
append
((
k
,
client
))
s
.
sort
()
s
.
sort
()
sequence
=
[]
for
k
,
client
in
s
:
sequence
.
append
(
client
)
sequence
=
[]
for
k
,
client
in
s
:
sequence
.
append
(
client
)
return
sequence
return
sequence
basic_type
=
{
type
(
''
):
1
,
type
(
0
):
1
,
type
(
0.0
):
1
,
type
(()):
1
,
type
([]):
1
}.
has_key
}.
has_key
def
int_param
(
params
,
md
,
name
,
default
=
0
,
st
=
type
(
''
)):
try
:
v
=
params
[
name
]
except
:
v
=
default
if
v
:
try
:
v
=
atoi
(
v
)
except
:
v
=
md
[
v
]
if
type
(
v
)
is
st
:
v
=
atoi
(
v
)
try
:
v
=
atoi
(
v
)
except
:
v
=
md
[
v
]
if
type
(
v
)
is
st
:
v
=
atoi
(
v
)
return
v
lib/python/DocumentTemplate/DT_InSV.py
View file @
cbd3d223
...
...
@@ -54,8 +54,8 @@
__doc__
=
'''Sequence variables support
$Id: DT_InSV.py,v 1.
7 1998/09/14 20:48:40
jim Exp $'''
__version__
=
'$Revision: 1.
7
$'
[
11
:
-
2
]
$Id: DT_InSV.py,v 1.
8 1998/09/14 22:03:32
jim Exp $'''
__version__
=
'$Revision: 1.
8
$'
[
11
:
-
2
]
from
string
import
lower
,
rfind
from
math
import
sqrt
...
...
@@ -69,17 +69,17 @@ except: mv=None
class
sequence_variables
:
def
__init__
(
self
,
items
=
None
,
query_string
=
''
,
start_name_re
=
None
):
self
.
items
=
items
self
.
query_string
=
query_string
self
.
start_name_re
=
start_name_re
self
.
items
=
items
self
.
query_string
=
query_string
self
.
start_name_re
=
start_name_re
self
.
data
=
data
=
{
'previous-sequence'
:
0
,
'next-sequence'
:
0
,
'sequence-start'
:
1
,
'sequence-end'
:
0
,
}
self
.
data
=
data
=
{
'previous-sequence'
:
0
,
'next-sequence'
:
0
,
'sequence-start'
:
1
,
'sequence-end'
:
0
,
}
def
number
(
self
,
index
):
return
index
+
1
...
...
@@ -89,84 +89,84 @@ class sequence_variables:
def
Letter
(
self
,
index
):
return
chr
(
ord
(
'A'
)
+
index
)
def
key
(
self
,
index
):
return
self
.
items
[
index
][
0
]
def
item
(
self
,
index
,
tt
=
type
(())):
i
=
self
.
items
[
index
]
if
type
(
i
)
is
tt
and
len
(
i
)
==
2
:
return
i
[
1
]
return
i
i
=
self
.
items
[
index
]
if
type
(
i
)
is
tt
and
len
(
i
)
==
2
:
return
i
[
1
]
return
i
def
roman
(
self
,
index
):
return
lower
(
self
.
Roman
(
index
))
def
Roman
(
self
,
num
):
# Force number to be an integer value
num
=
int
(
num
)
+
1
# Force number to be an integer value
num
=
int
(
num
)
+
1
# Initialize roman as an empty string
# Initialize roman as an empty string
roman
=
''
while
num
>=
1000
:
num
=
num
-
1000
while
num
>=
1000
:
num
=
num
-
1000
roman
=
'%sM'
%
roman
while
num
>=
500
:
num
=
num
-
500
while
num
>=
500
:
num
=
num
-
500
roman
=
'%sD'
%
roman
while
num
>=
100
:
num
=
num
-
100
roman
=
'%sC'
%
roman
while
num
>=
100
:
num
=
num
-
100
roman
=
'%sC'
%
roman
while
num
>=
50
:
num
=
num
-
50
while
num
>=
50
:
num
=
num
-
50
roman
=
'%sL'
%
roman
while
num
>=
10
:
num
=
num
-
10
roman
=
'%sX'
%
roman
while
num
>=
10
:
num
=
num
-
10
roman
=
'%sX'
%
roman
while
num
>=
5
:
num
=
num
-
5
roman
=
'%sV'
%
roman
while
num
>=
5
:
num
=
num
-
5
roman
=
'%sV'
%
roman
while
num
<
5
and
num
>=
1
:
num
=
num
-
1
roman
=
'%sI'
%
roman
while
num
<
5
and
num
>=
1
:
num
=
num
-
1
roman
=
'%sI'
%
roman
# Replaces special cases in Roman Numerals
roman
=
sub
(
'DCCCC'
,
'CM'
,
roman
)
roman
=
sub
(
'CCCC'
,
'CD'
,
roman
)
roman
=
sub
(
'LXXXX'
,
'XC'
,
roman
)
roman
=
sub
(
'XXXX'
,
'XL'
,
roman
)
roman
=
sub
(
'VIIII'
,
'IX'
,
roman
)
roman
=
sub
(
'IIII'
,
'IV'
,
roman
)
# Replaces special cases in Roman Numerals
roman
=
sub
(
'DCCCC'
,
'CM'
,
roman
)
roman
=
sub
(
'CCCC'
,
'CD'
,
roman
)
roman
=
sub
(
'LXXXX'
,
'XC'
,
roman
)
roman
=
sub
(
'XXXX'
,
'XL'
,
roman
)
roman
=
sub
(
'VIIII'
,
'IX'
,
roman
)
roman
=
sub
(
'IIII'
,
'IV'
,
roman
)
return
roman
return
roman
def
value
(
self
,
index
,
name
):
data
=
self
.
data
item
=
self
.
items
[
index
]
if
type
(
item
)
==
TupleType
and
len
(
item
)
==
2
:
item
=
item
[
1
]
if
data
[
'mapping'
]:
return
item
[
name
]
return
getattr
(
item
,
name
)
data
=
self
.
data
item
=
self
.
items
[
index
]
if
type
(
item
)
==
TupleType
and
len
(
item
)
==
2
:
item
=
item
[
1
]
if
data
[
'mapping'
]:
return
item
[
name
]
return
getattr
(
item
,
name
)
def
first
(
self
,
name
,
key
=
''
):
data
=
self
.
data
if
data
[
'sequence-start'
]:
return
1
index
=
data
[
'sequence-index'
]
return
self
.
value
(
index
,
name
)
!=
self
.
value
(
index
-
1
,
name
)
data
=
self
.
data
if
data
[
'sequence-start'
]:
return
1
index
=
data
[
'sequence-index'
]
return
self
.
value
(
index
,
name
)
!=
self
.
value
(
index
-
1
,
name
)
def
last
(
self
,
name
,
key
=
''
):
data
=
self
.
data
if
data
[
'sequence-end'
]:
return
1
index
=
data
[
'sequence-index'
]
return
self
.
value
(
index
,
name
)
!=
self
.
value
(
index
+
1
,
name
)
data
=
self
.
data
if
data
[
'sequence-end'
]:
return
1
index
=
data
[
'sequence-index'
]
return
self
.
value
(
index
,
name
)
!=
self
.
value
(
index
+
1
,
name
)
def
length
(
self
,
ignored
):
l
=
self
.
data
[
'sequence-length'
]
=
len
(
self
.
items
)
return
l
l
=
self
.
data
[
'sequence-length'
]
=
len
(
self
.
items
)
return
l
def
query
(
self
,
*
ignored
):
if
self
.
start_name_re
is
None
:
raise
KeyError
,
'sequence-query'
if
self
.
start_name_re
is
None
:
raise
KeyError
,
'sequence-query'
query_string
=
self
.
query_string
while
query_string
and
query_string
[:
1
]
in
'?&'
:
query_string
=
query_string
[
1
:]
...
...
@@ -184,180 +184,180 @@ class sequence_variables:
else
:
query_string
=
'?'
self
.
data
[
'sequence-query'
]
=
query_string
return
query_string
statistic_names
=
(
'total'
,
'count'
,
'min'
,
'max'
,
'median'
,
'mean'
,
'variance'
,
'variance-n'
,
'standard-deviation'
,
'standard-deviation-n'
,
)
'total'
,
'count'
,
'min'
,
'max'
,
'median'
,
'mean'
,
'variance'
,
'variance-n'
,
'standard-deviation'
,
'standard-deviation-n'
,
)
def
statistics
(
self
,
name
,
key
):
items
=
self
.
items
data
=
self
.
data
mapping
=
data
[
'mapping'
]
count
=
sum
=
sumsq
=
0
min
=
max
=
None
scount
=
smin
=
smax
=
None
values
=
[]
svalues
=
[]
for
item
in
items
:
try
:
if
mapping
:
item
=
item
[
name
]
else
:
item
=
getattr
(
item
,
name
)
try
:
s
=
item
*
item
sum
=
sum
+
item
sumsq
=
sumsq
+
s
values
.
append
(
item
)
if
min
is
None
:
min
=
max
=
item
else
:
if
item
<
min
:
min
=
item
if
item
>
max
:
max
=
item
except
:
if
item
is
not
None
and
item
is
not
mv
:
if
smin
is
None
:
smin
=
smax
=
item
else
:
if
item
<
smin
:
smin
=
item
if
item
>
smax
:
smax
=
item
svalues
.
append
(
item
)
except
:
pass
# Initialize all stats to empty strings:
for
stat
in
self
.
statistic_names
:
data
[
'%s-%s'
%
(
stat
,
name
)]
=
''
count
=
len
(
values
)
try
:
# Numeric statistics
n
=
float
(
count
)
mean
=
sum
/
n
sumsq
=
sumsq
/
n
-
mean
*
mean
data
[
'mean-%s'
%
name
]
=
mean
data
[
'total-%s'
%
name
]
=
sum
data
[
'variance-n-%s'
%
name
]
=
sumsq
data
[
'standard-deviation-n-%s'
%
name
]
=
sqrt
(
sumsq
)
if
count
>
1
:
sumsq
=
sumsq
*
n
/
(
n
-
1
)
data
[
'variance-%s'
%
name
]
=
sumsq
data
[
'standard-deviation-%s'
%
name
]
=
sqrt
(
sumsq
)
else
:
data
[
'variance-%s'
%
name
]
=
''
data
[
'standard-deviation-%s'
%
name
]
=
''
except
:
if
min
is
None
:
min
,
max
,
values
=
smin
,
smax
,
svalues
else
:
if
smin
<
min
:
min
=
smin
if
smax
>
max
:
max
=
smax
values
=
values
+
svalues
count
=
len
(
values
)
data
[
'count-%s'
%
name
]
=
count
# data['_values']=values
if
min
is
not
None
:
data
[
'min-%s'
%
name
]
=
min
data
[
'max-%s'
%
name
]
=
max
values
.
sort
()
if
count
==
1
:
data
[
'median-%s'
%
name
]
=
min
else
:
n
=
count
+
1
if
n
/
2
*
2
==
n
:
data
[
'median-%s'
%
name
]
=
values
[
n
/
2
-
1
]
else
:
n
=
n
/
2
try
:
data
[
'median-%s'
%
name
]
=
(
values
[
n
]
+
values
[
n
-
1
])
/
2
except
:
try
:
data
[
'median-%s'
%
name
]
=
(
"between %s and %s"
%
(
values
[
n
],
values
[
n
-
1
]))
except
:
pass
return
data
[
key
]
items
=
self
.
items
data
=
self
.
data
mapping
=
data
[
'mapping'
]
count
=
sum
=
sumsq
=
0
min
=
max
=
None
scount
=
smin
=
smax
=
None
values
=
[]
svalues
=
[]
for
item
in
items
:
try
:
if
mapping
:
item
=
item
[
name
]
else
:
item
=
getattr
(
item
,
name
)
try
:
s
=
item
*
item
sum
=
sum
+
item
sumsq
=
sumsq
+
s
values
.
append
(
item
)
if
min
is
None
:
min
=
max
=
item
else
:
if
item
<
min
:
min
=
item
if
item
>
max
:
max
=
item
except
:
if
item
is
not
None
and
item
is
not
mv
:
if
smin
is
None
:
smin
=
smax
=
item
else
:
if
item
<
smin
:
smin
=
item
if
item
>
smax
:
smax
=
item
svalues
.
append
(
item
)
except
:
pass
# Initialize all stats to empty strings:
for
stat
in
self
.
statistic_names
:
data
[
'%s-%s'
%
(
stat
,
name
)]
=
''
count
=
len
(
values
)
try
:
# Numeric statistics
n
=
float
(
count
)
mean
=
sum
/
n
sumsq
=
sumsq
/
n
-
mean
*
mean
data
[
'mean-%s'
%
name
]
=
mean
data
[
'total-%s'
%
name
]
=
sum
data
[
'variance-n-%s'
%
name
]
=
sumsq
data
[
'standard-deviation-n-%s'
%
name
]
=
sqrt
(
sumsq
)
if
count
>
1
:
sumsq
=
sumsq
*
n
/
(
n
-
1
)
data
[
'variance-%s'
%
name
]
=
sumsq
data
[
'standard-deviation-%s'
%
name
]
=
sqrt
(
sumsq
)
else
:
data
[
'variance-%s'
%
name
]
=
''
data
[
'standard-deviation-%s'
%
name
]
=
''
except
:
if
min
is
None
:
min
,
max
,
values
=
smin
,
smax
,
svalues
else
:
if
smin
<
min
:
min
=
smin
if
smax
>
max
:
max
=
smax
values
=
values
+
svalues
count
=
len
(
values
)
data
[
'count-%s'
%
name
]
=
count
# data['_values']=values
if
min
is
not
None
:
data
[
'min-%s'
%
name
]
=
min
data
[
'max-%s'
%
name
]
=
max
values
.
sort
()
if
count
==
1
:
data
[
'median-%s'
%
name
]
=
min
else
:
n
=
count
+
1
if
n
/
2
*
2
==
n
:
data
[
'median-%s'
%
name
]
=
values
[
n
/
2
-
1
]
else
:
n
=
n
/
2
try
:
data
[
'median-%s'
%
name
]
=
(
values
[
n
]
+
values
[
n
-
1
])
/
2
except
:
try
:
data
[
'median-%s'
%
name
]
=
(
"between %s and %s"
%
(
values
[
n
],
values
[
n
-
1
]))
except
:
pass
return
data
[
key
]
def
next_batches
(
self
,
suffix
=
'batches'
,
key
=
''
):
if
suffix
!=
'batches'
:
raise
KeyError
,
key
data
=
self
.
data
sequence
=
self
.
items
try
:
if
not
data
[
'next-sequence'
]:
return
()
sz
=
data
[
'sequence-step-size'
]
start
=
data
[
'sequence-step-start'
]
end
=
data
[
'sequence-step-end'
]
l
=
len
(
sequence
)
orphan
=
data
[
'sequence-step-orphan'
]
overlap
=
data
[
'sequence-step-overlap'
]
except
:
AttributeError
,
'next-batches'
r
=
[]
while
end
<
l
:
start
,
end
,
spam
=
opt
(
end
+
1
-
overlap
,
None
,
sz
,
orphan
,
sequence
)
v
=
sequence_variables
(
self
.
items
,
self
.
query_string
,
self
.
start_name_re
)
d
=
v
.
data
d
[
'batch-start-index'
]
=
start
-
1
d
[
'batch-end-index'
]
=
end
-
1
d
[
'batch-size'
]
=
end
+
1
-
start
d
[
'mapping'
]
=
data
[
'mapping'
]
r
.
append
(
v
)
data
[
'next-batches'
]
=
r
return
r
if
suffix
!=
'batches'
:
raise
KeyError
,
key
data
=
self
.
data
sequence
=
self
.
items
try
:
if
not
data
[
'next-sequence'
]:
return
()
sz
=
data
[
'sequence-step-size'
]
start
=
data
[
'sequence-step-start'
]
end
=
data
[
'sequence-step-end'
]
l
=
len
(
sequence
)
orphan
=
data
[
'sequence-step-orphan'
]
overlap
=
data
[
'sequence-step-overlap'
]
except
:
AttributeError
,
'next-batches'
r
=
[]
while
end
<
l
:
start
,
end
,
spam
=
opt
(
end
+
1
-
overlap
,
None
,
sz
,
orphan
,
sequence
)
v
=
sequence_variables
(
self
.
items
,
self
.
query_string
,
self
.
start_name_re
)
d
=
v
.
data
d
[
'batch-start-index'
]
=
start
-
1
d
[
'batch-end-index'
]
=
end
-
1
d
[
'batch-size'
]
=
end
+
1
-
start
d
[
'mapping'
]
=
data
[
'mapping'
]
r
.
append
(
v
)
data
[
'next-batches'
]
=
r
return
r
def
previous_batches
(
self
,
suffix
=
'batches'
,
key
=
''
):
if
suffix
!=
'batches'
:
raise
KeyError
,
key
data
=
self
.
data
sequence
=
self
.
items
try
:
if
not
data
[
'previous-sequence'
]:
return
()
sz
=
data
[
'sequence-step-size'
]
start
=
data
[
'sequence-step-start'
]
end
=
data
[
'sequence-step-end'
]
l
=
len
(
sequence
)
orphan
=
data
[
'sequence-step-orphan'
]
overlap
=
data
[
'sequence-step-overlap'
]
except
:
AttributeError
,
'previous-batches'
r
=
[]
while
start
>
1
:
start
,
end
,
spam
=
opt
(
None
,
start
-
1
+
overlap
,
sz
,
orphan
,
sequence
)
v
=
sequence_variables
(
self
.
items
,
self
.
query_string
,
self
.
start_name_re
)
d
=
v
.
data
d
[
'batch-start-index'
]
=
start
-
1
d
[
'batch-end-index'
]
=
end
-
1
d
[
'batch-size'
]
=
end
+
1
-
start
d
[
'mapping'
]
=
data
[
'mapping'
]
r
.
append
(
v
)
r
.
reverse
()
data
[
'previous-batches'
]
=
r
return
r
if
suffix
!=
'batches'
:
raise
KeyError
,
key
data
=
self
.
data
sequence
=
self
.
items
try
:
if
not
data
[
'previous-sequence'
]:
return
()
sz
=
data
[
'sequence-step-size'
]
start
=
data
[
'sequence-step-start'
]
end
=
data
[
'sequence-step-end'
]
l
=
len
(
sequence
)
orphan
=
data
[
'sequence-step-orphan'
]
overlap
=
data
[
'sequence-step-overlap'
]
except
:
AttributeError
,
'previous-batches'
r
=
[]
while
start
>
1
:
start
,
end
,
spam
=
opt
(
None
,
start
-
1
+
overlap
,
sz
,
orphan
,
sequence
)
v
=
sequence_variables
(
self
.
items
,
self
.
query_string
,
self
.
start_name_re
)
d
=
v
.
data
d
[
'batch-start-index'
]
=
start
-
1
d
[
'batch-end-index'
]
=
end
-
1
d
[
'batch-size'
]
=
end
+
1
-
start
d
[
'mapping'
]
=
data
[
'mapping'
]
r
.
append
(
v
)
r
.
reverse
()
data
[
'previous-batches'
]
=
r
return
r
special_prefixes
=
{
'first'
:
first
,
'last'
:
last
,
'previous'
:
previous_batches
,
'next'
:
next_batches
,
# These two are for backward compatability with a missfeature:
'sequence-index'
:
lambda
self
,
suffix
,
key
:
self
[
'sequence-'
+
suffix
],
'sequence-index-is'
:
lambda
self
,
suffix
,
key
:
self
[
'sequence-'
+
suffix
],
}
'first'
:
first
,
'last'
:
last
,
'previous'
:
previous_batches
,
'next'
:
next_batches
,
# These two are for backward compatability with a missfeature:
'sequence-index'
:
lambda
self
,
suffix
,
key
:
self
[
'sequence-'
+
suffix
],
'sequence-index-is'
:
lambda
self
,
suffix
,
key
:
self
[
'sequence-'
+
suffix
],
}
for
n
in
statistic_names
:
special_prefixes
[
n
]
=
statistics
def
__getitem__
(
self
,
key
,
special_prefixes
=
special_prefixes
,
special_prefixes
=
special_prefixes
,
special_prefix
=
special_prefixes
.
has_key
):
data
=
self
.
data
if
data
.
has_key
(
key
):
return
data
[
key
]
l
=
rfind
(
key
,
'-'
)
if
l
<
0
:
raise
KeyError
,
key
if
l
<
0
:
raise
KeyError
,
key
suffix
=
key
[
l
+
1
:]
prefix
=
key
[:
l
]
if
hasattr
(
self
,
suffix
):
try
:
v
=
data
[
prefix
+
'-index'
]
except
:
pass
else
:
return
getattr
(
self
,
suffix
)(
v
)
try
:
v
=
data
[
prefix
+
'-index'
]
except
:
pass
else
:
return
getattr
(
self
,
suffix
)(
v
)
if
special_prefix
(
prefix
):
return
special_prefixes
[
prefix
](
self
,
suffix
,
key
)
if
special_prefix
(
prefix
):
return
special_prefixes
[
prefix
](
self
,
suffix
,
key
)
if
prefix
[
-
4
:]
==
'-var'
:
prefix
=
prefix
[:
-
4
]
...
...
@@ -371,33 +371,32 @@ class sequence_variables:
def
opt
(
start
,
end
,
size
,
orphan
,
sequence
):
if
size
<
1
:
if
start
>
0
and
end
>
0
and
end
>=
start
:
size
=
end
+
1
-
start
else
:
size
=
7
if
start
>
0
and
end
>
0
and
end
>=
start
:
size
=
end
+
1
-
start
else
:
size
=
7
if
start
>
0
:
try
:
sequence
[
start
-
1
]
except
:
start
=
len
(
sequence
)
# if start > l: start=l
if
end
>
0
:
if
end
>
start
:
end
=
start
else
:
end
=
start
+
size
-
1
try
:
sequence
[
end
+
orphan
-
1
]
except
:
end
=
len
(
sequence
)
# if l - end < orphan: end=l
try
:
sequence
[
start
-
1
]
except
:
start
=
len
(
sequence
)
# if start > l: start=l
if
end
>
0
:
if
end
>
start
:
end
=
start
else
:
end
=
start
+
size
-
1
try
:
sequence
[
end
+
orphan
-
1
]
except
:
end
=
len
(
sequence
)
# if l - end < orphan: end=l
elif
end
>
0
:
try
:
sequence
[
end
-
1
]
except
:
end
=
len
(
sequence
)
# if end > l: end=l
start
=
end
+
1
-
size
if
start
-
1
<
orphan
:
start
=
1
try
:
sequence
[
end
-
1
]
except
:
end
=
len
(
sequence
)
# if end > l: end=l
start
=
end
+
1
-
size
if
start
-
1
<
orphan
:
start
=
1
else
:
start
=
1
end
=
start
+
size
-
1
try
:
sequence
[
end
+
orphan
-
1
]
except
:
end
=
len
(
sequence
)
# if l - end < orphan: end=l
start
=
1
end
=
start
+
size
-
1
try
:
sequence
[
end
+
orphan
-
1
]
except
:
end
=
len
(
sequence
)
# if l - end < orphan: end=l
return
start
,
end
,
size
lib/python/DocumentTemplate/DT_Raise.py
View file @
cbd3d223
...
...
@@ -65,8 +65,8 @@
<!--#/if-->
'''
__rcs_id__
=
'$Id: DT_Raise.py,v 1.
8 1998/09/14 20:48:40
jim Exp $'
__version__
=
'$Revision: 1.
8
$'
[
11
:
-
2
]
__rcs_id__
=
'$Id: DT_Raise.py,v 1.
9 1998/09/14 22:03:32
jim Exp $'
__version__
=
'$Revision: 1.
9
$'
[
11
:
-
2
]
from
DT_Util
import
parse_params
,
name_param
,
render_blocks
,
str
...
...
@@ -77,25 +77,24 @@ class Raise:
def
__init__
(
self
,
blocks
):
tname
,
args
,
section
=
blocks
[
0
]
self
.
section
=
section
.
blocks
args
=
parse_params
(
args
,
type
=
''
,
expr
=
''
)
self
.
__name__
,
self
.
expr
=
name_param
(
args
,
'raise'
,
1
,
attr
=
'type'
)
tname
,
args
,
section
=
blocks
[
0
]
self
.
section
=
section
.
blocks
args
=
parse_params
(
args
,
type
=
''
,
expr
=
''
)
self
.
__name__
,
self
.
expr
=
name_param
(
args
,
'raise'
,
1
,
attr
=
'type'
)
def
render
(
self
,
md
):
expr
=
self
.
expr
if
expr
is
None
:
t
=
self
.
__name__
if
t
[
-
5
:]
==
'Error'
and
__builtins__
.
has_key
(
t
):
t
=
__builtins__
[
t
]
else
:
try
:
t
=
expr
.
eval
(
md
)
except
:
t
=
'Invalid Error Type Expression'
expr
=
self
.
expr
if
expr
is
None
:
t
=
self
.
__name__
if
t
[
-
5
:]
==
'Error'
and
__builtins__
.
has_key
(
t
):
t
=
__builtins__
[
t
]
else
:
try
:
t
=
expr
.
eval
(
md
)
except
:
t
=
'Invalid Error Type Expression'
try
:
v
=
render_blocks
(
self
.
section
,
md
)
except
:
v
=
'Invalid Error Value'
try
:
v
=
render_blocks
(
self
.
section
,
md
)
except
:
v
=
'Invalid Error Value'
raise
t
,
v
raise
t
,
v
__call__
=
render
lib/python/DocumentTemplate/DT_String.py
View file @
cbd3d223
...
...
@@ -51,7 +51,7 @@
# (540) 371-6909
#
##############################################################################
"$Id: DT_String.py,v 1.1
8 1998/09/14 20:48:41
jim Exp $"
"$Id: DT_String.py,v 1.1
9 1998/09/14 22:03:32
jim Exp $"
from
string
import
split
,
strip
import
regex
,
ts_regex
...
...
@@ -90,34 +90,34 @@ class String:
def
errQuote
(
self
,
s
):
return
s
def
parse_error
(
self
,
mess
,
tag
,
text
,
start
):
raise
ParseError
,
"%s, for tag %s, on line %s of %s<p>"
%
(
mess
,
self
.
errQuote
(
tag
),
len
(
split
(
text
[:
start
],
'
\
n
'
)),
self
.
errQuote
(
self
.
__name__
))
raise
ParseError
,
"%s, for tag %s, on line %s of %s<p>"
%
(
mess
,
self
.
errQuote
(
tag
),
len
(
split
(
text
[:
start
],
'
\
n
'
)),
self
.
errQuote
(
self
.
__name__
))
commands
=
{
'var'
:
Var
,
'call'
:
Call
,
'in'
:
(
'in'
,
'DT_In'
,
'In'
),
'with'
:
(
'with'
,
'DT_With'
,
'With'
),
'if'
:
(
'if'
,
'DT_If'
,
'If'
),
'unless'
:
(
'unless'
,
'DT_If'
,
'Unless'
),
'else'
:
(
'else'
,
'DT_If'
,
'Else'
),
'comment'
:
Comment
,
'raise'
:
(
'raise'
,
'DT_Raise'
,
'Raise'
),
}
'var'
:
Var
,
'call'
:
Call
,
'in'
:
(
'in'
,
'DT_In'
,
'In'
),
'with'
:
(
'with'
,
'DT_With'
,
'With'
),
'if'
:
(
'if'
,
'DT_If'
,
'If'
),
'unless'
:
(
'unless'
,
'DT_If'
,
'Unless'
),
'else'
:
(
'else'
,
'DT_If'
,
'Else'
),
'comment'
:
Comment
,
'raise'
:
(
'raise'
,
'DT_Raise'
,
'Raise'
),
}
def
SubTemplate
(
self
,
name
):
return
String
(
''
,
__name__
=
name
)
def
tagre
(
self
):
return
ts_regex
.
symcomp
(
'%('
# beginning
'
\
(<
n
ame>[a-zA-Z0-9_/.-]+
\
)
'
# tag name
'
\
(
'
'
[
\
0
-
]
+
' # space after tag name
'
\
(
<
args
>
\
([
^
)
"]+
\
(
"
[^"
]
*
"
\
)?
\
)*
\
)
'
# arguments
'
\
)?
'
')
\
(<
f
mt>[0-9]*[.]?[0-9]*[a-z]
\
|[]![]
\
)' # end
, regex.casefold)
return
ts_regex
.
symcomp
(
'%('
# beginning
'
\
(<
n
ame>[a-zA-Z0-9_/.-]+
\
)
'
# tag name
'
\
(
'
'
[
\
0
-
]
+
' # space after tag name
'
\
(
<
args
>
\
([
^
)
"]+
\
(
"
[^"
]
*
"
\
)?
\
)*
\
)
'
# arguments
'
\
)?
'
')
\
(<
f
mt>[0-9]*[.]?[0-9]*[a-z]
\
|[]![]
\
)' # end
, regex.casefold)
def _parseTag(self, tagre, command=None, sargs='', tt=type(())):
tag, args, command, coname = self.parseTag(tagre,command,sargs)
...
...
@@ -133,159 +133,159 @@ class String:
return tag, args, command, coname
def parseTag(self, tagre, command=None, sargs=''):
"""Parse a tag using an already matched re
"""Parse a tag using an already matched re
Return: tag, args, command, coname
Return: tag, args, command, coname
where: tag is the tag,
where: tag is the tag,
args is the tag
\
'
s argument string,
command is a corresponding command info structure if the
command is a corresponding command info structure if the
tag is a start tag, or None otherwise, and
coname is the name of a continue tag (e.g. else)
or None otherwise
"""
tag, name, args, fmt =tagre.group(0, 'name', 'args', 'fmt')
args=args and strip(args) or ''
if fmt==']':
if not command or name != command.name:
raise ParseError, ('unexpected end tag', tag)
return tag, args, None, None
elif fmt=='[' or fmt=='!':
if command and name in command.blockContinuations:
if name=='else' and args:
# Waaaaaah! Have to special case else because of
# old else start tag usage. Waaaaaaah!
l=len(args)
if not (args==sargs or
args==sargs[:l] and sargs[l:l+1] in '
\
t
\
n
'):
return tag, args, self.commands[name], None
return tag, args, None, name
try: return tag, args, self.commands[name], None
except KeyError:
raise ParseError, ('Unexpected tag', tag)
coname is the name of a continue tag (e.g. else)
or None otherwise
"""
tag, name, args, fmt =tagre.group(0, 'name', 'args', 'fmt')
args=args and strip(args) or ''
if fmt==']':
if not command or name != command.name:
raise ParseError, ('unexpected end tag', tag)
return tag, args, None, None
elif fmt=='[' or fmt=='!':
if command and name in command.blockContinuations:
if name=='else' and args:
# Waaaaaah! Have to special case else because of
# old else start tag usage. Waaaaaaah!
l=len(args)
if not (args==sargs or
args==sargs[:l] and sargs[l:l+1] in '
\
t
\
n
'):
return tag, args, self.commands[name], None
return tag, args, None, name
try: return tag, args, self.commands[name], None
except KeyError:
raise ParseError, ('Unexpected tag', tag)
else:
# Var command
args=args and ("
%
s
%
s
" % (name, args)) or name
return tag, args, Var, None
# Var command
args=args and ("
%
s
%
s
" % (name, args)) or name
return tag, args, Var, None
def varExtra(self,tagre): return tagre.group('fmt')
def parse(self,text,start=0,result=None,tagre=None):
if result is None: result=[]
if tagre is None: tagre=self.tagre()
if result is None: result=[]
if tagre is None: tagre=self.tagre()
l=tagre.search(text,start)
while l >= 0:
while l >= 0:
try: tag, args, command, coname = self._parseTag(tagre)
except ParseError, m: self.parse_error(m[0],m[1],text,l)
try: tag, args, command, coname = self._parseTag(tagre)
except ParseError, m: self.parse_error(m[0],m[1],text,l)
s=text[start:l]
if s: result.append(s)
start=l+len(tag)
s=text[start:l]
if s: result.append(s)
start=l+len(tag)
if hasattr(command,'blockContinuations'):
start=self.parse_block(text, start, result, tagre,
tag, l, args, command)
else:
try:
if command is Var: r=command(args, self.varExtra(tagre))
else: r=command(args)
if hasattr(r,'simple_form'): r=r.simple_form
result.append(r)
except ParseError, m: self.parse_error(m[0],tag,text,l)
if hasattr(command,'blockContinuations'):
start=self.parse_block(text, start, result, tagre,
tag, l, args, command)
else:
try:
if command is Var: r=command(args, self.varExtra(tagre))
else: r=command(args)
if hasattr(r,'simple_form'): r=r.simple_form
result.append(r)
except ParseError, m: self.parse_error(m[0],tag,text,l)
l=tagre.search(text,start)
l=tagre.search(text,start)
text=text[start:]
if text: result.append(text)
return result
text=text[start:]
if text: result.append(text)
return result
def skip_eol(self, text, start, eol=regex.compile('[
\
t
]*
\
n
')):
# if block open is followed by newline, then skip past newline
l=eol.match(text,start)
if l > 0: start=start+l
return start
l=eol.match(text,start)
if l > 0: start=start+l
return start
def parse_block(self, text, start, result, tagre,
stag, sloc, sargs, scommand):
stag, sloc, sargs, scommand):
start=self.skip_eol(text,start)
blocks=[]
tname=scommand.name
sname=stag
sstart=start
sa=sargs
sname=stag
sstart=start
sa=sargs
while 1:
l=tagre.search(text,start)
if l < 0: self.parse_error('No closing tag', stag, text, sloc)
try: tag, args, command, coname= self._parseTag(tagre,scommand,sa)
except ParseError, m: self.parse_error(m[0],m[1], text, l)
if command:
start=l+len(tag)
if hasattr(command, 'blockContinuations'):
# New open tag. Need to find closing tag.
start=self.parse_close(text, start, tagre, tag, l,
command, args)
else:
# Either a continuation tag or an end tag
section=self.SubTemplate(sname)
section.blocks=self.parse(text[:l],sstart)
section.cooked=None
blocks.append((tname,sargs,section))
l=tagre.search(text,start)
if l < 0: self.parse_error('No closing tag', stag, text, sloc)
try: tag, args, command, coname= self._parseTag(tagre,scommand,sa)
except ParseError, m: self.parse_error(m[0],m[1], text, l)
if command:
start=l+len(tag)
if hasattr(command, 'blockContinuations'):
# New open tag. Need to find closing tag.
start=self.parse_close(text, start, tagre, tag, l,
command, args)
else:
# Either a continuation tag or an end tag
section=self.SubTemplate(sname)
section.blocks=self.parse(text[:l],sstart)
section.cooked=None
blocks.append((tname,sargs,section))
start=self.skip_eol(text,l+len(tag))
if coname:
tname=coname
sname=tag
sargs=args
sstart=start
else:
try:
r=scommand(blocks)
if hasattr(r,'simple_form'): r=r.simple_form
result.append(r)
except ParseError, m: self.parse_error(m[0],stag,text,l)
return start
start=self.skip_eol(text,l+len(tag))
if coname:
tname=coname
sname=tag
sargs=args
sstart=start
else:
try:
r=scommand(blocks)
if hasattr(r,'simple_form'): r=r.simple_form
result.append(r)
except ParseError, m: self.parse_error(m[0],stag,text,l)
return start
def parse_close(self, text, start, tagre, stag, sloc, scommand, sa):
while 1:
l=tagre.search(text,start)
if l < 0: self.parse_error('No closing tag', stag, text, sloc)
l=tagre.search(text,start)
if l < 0: self.parse_error('No closing tag', stag, text, sloc)
try: tag, args, command, coname= self._parseTag(tagre,scommand,sa)
except ParseError, m: self.parse_error(m[0],m[1], text, l)
try: tag, args, command, coname= self._parseTag(tagre,scommand,sa)
except ParseError, m: self.parse_error(m[0],m[1], text, l)
start=l+len(tag)
if command:
if hasattr(command, 'blockContinuations'):
# New open tag. Need to find closing tag.
start=self.parse_close(text, start, tagre, tag, l,
command,args)
elif not coname: return start
start=l+len(tag)
if command:
if hasattr(command, 'blockContinuations'):
# New open tag. Need to find closing tag.
start=self.parse_close(text, start, tagre, tag, l,
command,args)
elif not coname: return start
shared_globals={}
def __init__(self, source_string='', mapping=None, __name__='<string>',
**vars):
"""
\
Create a document template from a string.
**vars):
"""
\
Create a document template from a string.
The optional parameter, 'mapping', may be used to provide a
mapping object containing defaults for values to be inserted.
"""
self.raw=source_string
self.initvars(mapping, vars)
self.setName(__name__)
The optional parameter, 'mapping', may be used to provide a
mapping object containing defaults for values to be inserted.
"""
self.raw=source_string
self.initvars(mapping, vars)
self.setName(__name__)
def name(self): return self.__name__
id=name
...
...
@@ -293,49 +293,49 @@ class String:
def setName(self,v): self.__dict__['__name__']=v
def default(self,name=None,**kw):
"""
\
Change or query default values in a document template.
"""
\
Change or query default values in a document template.
If a name is specified, the value of the named default value
before the operation is returned.
If a name is specified, the value of the named default value
before the operation is returned.
Keyword arguments are used to provide default values.
"""
if name: name=self.globals[name]
for key in kw.keys(): self.globals[key]=kw[key]
return name
Keyword arguments are used to provide default values.
"""
if name: name=self.globals[name]
for key in kw.keys(): self.globals[key]=kw[key]
return name
def var(self,name=None,**kw):
"""
\
Change or query a variable in a document template.
"""
\
Change or query a variable in a document template.
If a name is specified, the value of the named variable before
the operation is returned.
If a name is specified, the value of the named variable before
the operation is returned.
Keyword arguments are used to provide variable values.
"""
if name: name=self._vars[name]
for key in kw.keys(): self._vars[key]=kw[key]
return name
Keyword arguments are used to provide variable values.
"""
if name: name=self._vars[name]
for key in kw.keys(): self._vars[key]=kw[key]
return name
def munge(self,source_string=None,mapping=None,**vars):
"""
\
Change the text or default values for a document template.
"""
if mapping is not None or vars:
self.initvars(mapping, vars)
if source_string is not None:
self.raw=source_string
self.cook()
"""
\
Change the text or default values for a document template.
"""
if mapping is not None or vars:
self.initvars(mapping, vars)
if source_string is not None:
self.raw=source_string
self.cook()
def manage_edit(self,data,REQUEST=None):
self.munge(data)
self.munge(data)
def read_raw(self,raw=None):
return self.raw
return self.raw
def read(self,raw=None):
return self.read_raw()
return self.read_raw()
def cook(self,
cooklock=ts_regex.allocate_lock(),
...
...
@@ -348,158 +348,158 @@ class String:
cooklock.release()
def initvars(self, globals, vars):
if globals:
for k in globals.keys():
if k[:1] != '_' and not vars.has_key(k): vars[k]=globals[k]
self.globals=vars
self._vars={}
if globals:
for k in globals.keys():
if k[:1] != '_' and not vars.has_key(k): vars[k]=globals[k]
self.globals=vars
self._vars={}
__state_names__=('raw', 'globals', '__name__', '_vars')
def __getstate__(self):
r={}
for k in self.__state_names__:
try: r[k]=getattr(self,k)
except: pass
return r
r={}
for k in self.__state_names__:
try: r[k]=getattr(self,k)
except: pass
return r
def __setstate__(self,s,hack=('',{},'<string>',{},'')):
try:
for k in s.keys(): self.__dict__[k]=s[k]
except:
self.raw,self.globals,self.__dict__['name'],self._vars,dummy=(
s+hack[len(s)-len(hack):])
try:
for k in s.keys(): self.__dict__[k]=s[k]
except:
self.raw,self.globals,self.__dict__['name'],self._vars,dummy=(
s+hack[len(s)-len(hack):])
def __call__(self,client=None,mapping={},**kw):
'''
\
Generate a document from a document template.
The document will be generated by inserting values into the
format string specified when the document template was
created. Values are inserted using standard python named
string formats.
The optional argument 'client' is used to specify a object
containing values to be looked up. Values will be looked up
using getattr, so inheritence of values is supported. Note
that names beginning with '_' will not be looked up from the
client.
The optional argument, 'mapping' is used to specify a mapping
object containing values to be inserted.
Values to be inserted may also be specified using keyword
arguments.
Values will be inserted from one of several sources. The
sources, in the order in which they are consulted, are:
o Keyword arguments,
o The 'client' argument,
o The 'mapping' argument,
o The keyword arguments provided when the object was
created, and
o The 'mapping' argument provided when the template was
created.
'''
# print '============================================================'
# print '__called__'
# print self.raw
# print kw
# print client
# print mapping
# print '============================================================'
if mapping is None: mapping = {}
if not hasattr(self,'cooked'):
try: changed=self.__changed__()
except: changed=1
self.cook()
if not changed: self.__changed__(0)
pushed=None
try:
if mapping.__class__ is TemplateDict: pushed=0
except: pass
globals=self.globals
if pushed is not None:
# We were passed a TemplateDict, so we must be a sub-template
md=mapping
push=md._push
if globals:
push(self.globals)
pushed=pushed+1
else:
md=TemplateDict()
push=md._push
shared_globals=self.shared_globals
if shared_globals: push(shared_globals)
if globals: push(globals)
if mapping:
push(mapping)
if hasattr(mapping,'AUTHENTICATED_USER'):
md.AUTHENTICATED_USER=mapping['AUTHENTICATED_USER']
md.validate=self.validate
if client is not None: md.this=client
pushed=0
level=md.level
if level > 200: raise SystemError, (
'infinite recursion in document template')
md.level=level+1
if client is not None:
push(InstanceDict(client,md)) # Circ. Ref. 8-|
pushed=pushed+1
if self._vars:
push(self._vars)
pushed=pushed+1
if kw:
push(kw)
pushed=pushed+1
try:
return render_blocks(self.blocks,md)
finally:
if pushed: md._pop(pushed) # Get rid of circular reference!
md.level=level # Restore previous level
'''
\
Generate a document from a document template.
The document will be generated by inserting values into the
format string specified when the document template was
created. Values are inserted using standard python named
string formats.
The optional argument 'client' is used to specify a object
containing values to be looked up. Values will be looked up
using getattr, so inheritence of values is supported. Note
that names beginning with '_' will not be looked up from the
client.
The optional argument, 'mapping' is used to specify a mapping
object containing values to be inserted.
Values to be inserted may also be specified using keyword
arguments.
Values will be inserted from one of several sources. The
sources, in the order in which they are consulted, are:
o Keyword arguments,
o The 'client' argument,
o The 'mapping' argument,
o The keyword arguments provided when the object was
created, and
o The 'mapping' argument provided when the template was
created.
'''
# print '============================================================'
# print '__called__'
# print self.raw
# print kw
# print client
# print mapping
# print '============================================================'
if mapping is None: mapping = {}
if not hasattr(self,'cooked'):
try: changed=self.__changed__()
except: changed=1
self.cook()
if not changed: self.__changed__(0)
pushed=None
try:
if mapping.__class__ is TemplateDict: pushed=0
except: pass
globals=self.globals
if pushed is not None:
# We were passed a TemplateDict, so we must be a sub-template
md=mapping
push=md._push
if globals:
push(self.globals)
pushed=pushed+1
else:
md=TemplateDict()
push=md._push
shared_globals=self.shared_globals
if shared_globals: push(shared_globals)
if globals: push(globals)
if mapping:
push(mapping)
if hasattr(mapping,'AUTHENTICATED_USER'):
md.AUTHENTICATED_USER=mapping['AUTHENTICATED_USER']
md.validate=self.validate
if client is not None: md.this=client
pushed=0
level=md.level
if level > 200: raise SystemError, (
'infinite recursion in document template')
md.level=level+1
if client is not None:
push(InstanceDict(client,md)) # Circ. Ref. 8-|
pushed=pushed+1
if self._vars:
push(self._vars)
pushed=pushed+1
if kw:
push(kw)
pushed=pushed+1
try:
return render_blocks(self.blocks,md)
finally:
if pushed: md._pop(pushed) # Get rid of circular reference!
md.level=level # Restore previous level
validate=None
def __str__(self):
return self.read()
return self.read()
class FileMixin:
# Mix-in class to abstract certain file-related attributes
edited_source=''
__state_names__=(
String.__state_names__ +
('edited_source',))
String.__state_names__ +
('edited_source',))
def __init__(self, file_name='', mapping=None, **vars):
"""
\
Create a document template based on a named file.
"""
\
Create a document template based on a named file.
The optional parameter, 'mapping', may be used to provide a
mapping object containing defaults for values to be inserted.
"""
self.raw=file_name
self.initvars(mapping, vars)
self.setName(file_name)
The optional parameter, 'mapping', may be used to provide a
mapping object containing defaults for values to be inserted.
"""
self.raw=file_name
self.initvars(mapping, vars)
self.setName(file_name)
def read_raw(self):
if self.edited_source: return self.edited_source
if self.raw: return open(self.raw,'r').read()
return ''
if self.edited_source: return self.edited_source
if self.raw: return open(self.raw,'r').read()
return ''
class File(FileMixin, String):
"""
\
...
...
@@ -512,4 +512,3 @@ class File(FileMixin, String):
template is used the first time.
"""
def manage_edit(self,data): raise TypeError, 'cannot edit files'
lib/python/DocumentTemplate/DT_UI.py
View file @
cbd3d223
...
...
@@ -54,8 +54,8 @@
__doc__
=
'''Machinery to support through-the-web editing
$Id: DT_UI.py,v 1.
6 1998/09/14 20:48:41
jim Exp $'''
__version__
=
'$Revision: 1.
6
$'
[
11
:
-
2
]
$Id: DT_UI.py,v 1.
7 1998/09/14 22:03:33
jim Exp $'''
__version__
=
'$Revision: 1.
7
$'
[
11
:
-
2
]
from
DT_HTML
import
HTML
...
...
@@ -97,12 +97,12 @@ HTML._manage_editForm = HTML(
<!--#/if FactoryDefaultString-->
<INPUT NAME=SUBMIT TYPE="SUBMIT" VALUE="Cancel">
<!--#if HTTP_REFERER-->
<INPUT NAME="CANCEL_ACTION" TYPE="HIDDEN"
VALUE="<!--#var HTTP_REFERER-->">
<INPUT NAME="CANCEL_ACTION" TYPE="HIDDEN"
VALUE="<!--#var HTTP_REFERER-->">
<!--#else HTTP_REFERER-->
<!--#if PARENT_URL-->
<INPUT NAME="CANCEL_ACTION" TYPE="HIDDEN"
VALUE="<!--#var PARENT_URL-->">
<INPUT NAME="CANCEL_ACTION" TYPE="HIDDEN"
VALUE="<!--#var PARENT_URL-->">
<!--#/if PARENT_URL-->
<!--#/if HTTP_REFERER-->
</center>
...
...
@@ -118,13 +118,13 @@ HTML.editConfirmation=HTML(
"""<html><head><title>Change Successful</title></head><body>
<!--#if CANCEL_ACTION-->
<form action="<!--#var CANCEL_ACTION-->" method="POST">
<center>
<em><!--#var dt_edit_name--></em><br>has been changed.<br><br>
<input type=submit name="SUBMIT" value="OK">
</center>
<center>
<em><!--#var dt_edit_name--></em><br>has been changed.<br><br>
<input type=submit name="SUBMIT" value="OK">
</center>
</form></body></html>
<!--#else CANCEL_ACTION-->
<center>
<em><!--#var dt_edit_name--></em><br>has been changed.
<em><!--#var dt_edit_name--></em><br>has been changed.
</center>
<!--#/if CANCEL_ACTION-->"""
)
lib/python/DocumentTemplate/DT_Util.py
View file @
cbd3d223
...
...
@@ -51,8 +51,8 @@
# (540) 371-6909
#
##############################################################################
'''$Id: DT_Util.py,v 1.4
6 1998/09/14 20:48:41
jim Exp $'''
__version__
=
'$Revision: 1.4
6
$'
[
11
:
-
2
]
'''$Id: DT_Util.py,v 1.4
7 1998/09/14 22:03:33
jim Exp $'''
__version__
=
'$Revision: 1.4
7
$'
[
11
:
-
2
]
import
regex
,
string
,
math
,
os
from
string
import
strip
,
join
,
atoi
,
lower
,
split
,
find
...
...
@@ -65,37 +65,37 @@ ValidationError='Unauthorized'
def
html_quote
(
v
,
name
=
'(Unknown name)'
,
md
=
{},
character_entities
=
(
((
'&'
),
'&'
),
((
"<"
),
'<'
),
((
">"
),
'>'
),
((
'"'
),
'"'
))):
#"
character_entities
=
(
((
'&'
),
'&'
),
((
"<"
),
'<'
),
((
">"
),
'>'
),
((
'"'
),
'"'
))):
#"
text
=
str
(
v
)
for
re
,
name
in
character_entities
:
for
re
,
name
in
character_entities
:
if
find
(
text
,
re
)
>=
0
:
text
=
join
(
split
(
text
,
re
),
name
)
return
text
return
text
def
int_param
(
params
,
md
,
name
,
default
=
0
,
st
=
type
(
''
)):
try
:
v
=
params
[
name
]
except
:
v
=
default
if
v
:
try
:
v
=
atoi
(
v
)
except
:
v
=
md
[
v
]
if
type
(
v
)
is
st
:
v
=
atoi
(
v
)
try
:
v
=
atoi
(
v
)
except
:
v
=
md
[
v
]
if
type
(
v
)
is
st
:
v
=
atoi
(
v
)
return
v
def
careful_getattr
(
md
,
inst
,
name
):
if
name
[:
1
]
!=
'_'
:
validate
=
md
.
validate
validate
=
md
.
validate
if
validate
is
None
:
return
getattr
(
inst
,
name
)
if
validate
is
None
:
return
getattr
(
inst
,
name
)
if
hasattr
(
inst
,
'aq_acquire'
):
return
inst
.
aq_acquire
(
name
,
validate
,
md
)
if
hasattr
(
inst
,
'aq_acquire'
):
return
inst
.
aq_acquire
(
name
,
validate
,
md
)
v
=
getattr
(
inst
,
name
)
if
validate
(
inst
,
inst
,
name
,
v
,
md
):
return
v
v
=
getattr
(
inst
,
name
)
if
validate
(
inst
,
inst
,
name
,
v
,
md
):
return
v
raise
ValidationError
,
name
...
...
@@ -127,18 +127,18 @@ def careful_getitem(md, mapping, key):
def
careful_getslice
(
md
,
seq
,
*
indexes
):
v
=
len
(
indexes
)
if
v
==
2
:
v
=
seq
[
indexes
[
0
]:
indexes
[
1
]]
v
=
seq
[
indexes
[
0
]:
indexes
[
1
]]
elif
v
==
1
:
v
=
seq
[
indexes
[
0
]:]
v
=
seq
[
indexes
[
0
]:]
else
:
v
=
seq
[:]
if
type
(
seq
)
is
type
(
''
):
return
v
# Short-circuit common case
validate
=
md
.
validate
if
validate
is
not
None
:
for
e
in
v
:
if
not
validate
(
seq
,
seq
,
''
,
e
,
md
):
raise
ValidationError
,
'unauthorized access to slice member'
for
e
in
v
:
if
not
validate
(
seq
,
seq
,
''
,
e
,
md
):
raise
ValidationError
,
'unauthorized access to slice member'
return
v
...
...
@@ -149,7 +149,7 @@ except: from pDocumentTemplate import InstanceDict, TemplateDict, render_blocks
d
=
TemplateDict
.
__dict__
for
name
in
(
'None'
,
'abs'
,
'chr'
,
'divmod'
,
'float'
,
'hash'
,
'hex'
,
'int'
,
'len'
,
'max'
,
'min'
,
'oct'
,
'ord'
,
'pow'
,
'round'
,
'str'
):
'len'
,
'max'
,
'min'
,
'oct'
,
'ord'
,
'pow'
,
'round'
,
'str'
):
d
[
name
]
=
__builtins__
[
name
]
d
[
'string'
]
=
string
d
[
'math'
]
=
math
...
...
@@ -158,7 +158,7 @@ d['whrandom']=whrandom
def
test
(
self
,
*
args
):
l
=
len
(
args
)
for
i
in
range
(
1
,
l
,
2
):
if
args
[
i
-
1
]:
return
args
[
i
]
if
args
[
i
-
1
]:
return
args
[
i
]
if
l
%
2
:
return
args
[
-
1
]
...
...
@@ -211,16 +211,16 @@ class Eval(VSEval.Eval):
def
eval
(
self
,
mapping
):
d
=
{
'_vars'
:
mapping
,
'_'
:
mapping
}
code
=
self
.
code
globals
=
self
.
globals
for
name
in
self
.
used
:
try
:
d
[
name
]
=
mapping
.
getitem
(
name
,
0
)
except
KeyError
:
if
name
==
'_getattr'
:
d
[
'__builtins__'
]
=
globals
exec
compiled_getattr
in
d
code
=
self
.
code
globals
=
self
.
globals
for
name
in
self
.
used
:
try
:
d
[
name
]
=
mapping
.
getitem
(
name
,
0
)
except
KeyError
:
if
name
==
'_getattr'
:
d
[
'__builtins__'
]
=
globals
exec
compiled_getattr
in
d
return
eval
(
code
,
globals
,
d
)
return
eval
(
code
,
globals
,
d
)
def
name_param
(
params
,
tag
=
''
,
expr
=
0
,
attr
=
'name'
,
default_unnamed
=
1
):
...
...
@@ -228,10 +228,10 @@ def name_param(params,tag='',expr=0, attr='name', default_unnamed=1):
__traceback_info__
=
params
,
tag
,
expr
,
attr
#if expr and used('expr') and used('') and not used(params['']):
#
# Fix up something like: <!--#in expr="whatever" mapping-->
#
params[params['']]=default_unnamed
#
del params['']
#
# Fix up something like: <!--#in expr="whatever" mapping-->
#
params[params['']]=default_unnamed
#
del params['']
if
used
(
''
):
v
=
params
[
''
]
...
...
@@ -266,16 +266,16 @@ def name_param(params,tag='',expr=0, attr='name', default_unnamed=1):
return
params
[
''
]
elif
used
(
attr
):
if
expr
:
if
used
(
'expr'
):
raise
ParseError
,
(
'%s and expr given'
%
attr
,
tag
)
return
params
[
attr
],
None
return
params
[
attr
]
if
expr
:
if
used
(
'expr'
):
raise
ParseError
,
(
'%s and expr given'
%
attr
,
tag
)
return
params
[
attr
],
None
return
params
[
attr
]
elif
expr
and
used
(
'expr'
):
name
=
params
[
'expr'
]
expr
=
Eval
(
name
,
expr_globals
)
return
name
,
expr
name
=
params
[
'expr'
]
expr
=
Eval
(
name
,
expr_globals
)
return
name
,
expr
raise
ParseError
,
(
'No %s given'
%
attr
,
tag
)
Expr_doc
=
"""
...
...
@@ -337,17 +337,17 @@ Python expression support
ListType
=
type
([])
def
parse_params
(
text
,
result
=
None
,
tag
=
''
,
unparmre
=
regex
.
compile
(
'
\
([
\
0- ]*
\
([^
\
0- =
\
"
]+
\
)
\
)'
),
qunparmre
=
regex
.
compile
(
'
\
([
\
0- ]*
\
(
"
[^"]*"
\
)
\
)'
),
parmre
=
regex
.
compile
(
'
\
([
\
0- ]*
\
([^
\
0- =
\
"
]+
\
)=
\
([^
\
0
- =
\
"
]+
\
)
\
)'
),
qparmre
=
regex
.
compile
(
'
\
([
\
0- ]*
\
([^
\
0- =
\
"
]+
\
)=
"
\
([^
"
]*
\
)
\
"
\
)
'
),
**parms):
result
=
None
,
tag
=
''
,
unparmre
=
regex
.
compile
(
'
\
([
\
0- ]*
\
([^
\
0- =
\
"
]+
\
)
\
)'
),
qunparmre
=
regex
.
compile
(
'
\
([
\
0- ]*
\
(
"
[^"]*"
\
)
\
)'
),
parmre
=
regex
.
compile
(
'
\
([
\
0- ]*
\
([^
\
0- =
\
"
]+
\
)=
\
([^
\
0
- =
\
"
]+
\
)
\
)'
),
qparmre
=
regex
.
compile
(
'
\
([
\
0- ]*
\
([^
\
0- =
\
"
]+
\
)=
"
\
([^
"
]*
\
)
\
"
\
)
'
),
**parms):
"""Parse tag parameters
...
...
@@ -373,41 +373,41 @@ def parse_params(text,
result=result or {}
if parmre.match(text) >= 0:
name=lower(parmre.group(2))
value=parmre.group(3)
l=len(parmre.group(1))
name=lower(parmre.group(2))
value=parmre.group(3)
l=len(parmre.group(1))
elif qparmre.match(text) >= 0:
name=lower(qparmre.group(2))
value=qparmre.group(3)
l=len(qparmre.group(1))
name=lower(qparmre.group(2))
value=qparmre.group(3)
l=len(qparmre.group(1))
elif unparmre.match(text) >= 0:
name=unparmre.group(2)
l=len(unparmre.group(1))
if result:
if parms.has_key(name):
if parms[name] is None: raise ParseError, (
'
Attribute
%
s
requires
a
value
' % name, tag)
result[name]=parms[name]
else: raise ParseError, (
'
Invalid
attribute
name
,
"%s"' % name, tag)
else:
result['']=name
return apply(parse_params,(text[l:],result),parms)
name=unparmre.group(2)
l=len(unparmre.group(1))
if result:
if parms.has_key(name):
if parms[name] is None: raise ParseError, (
'
Attribute
%
s
requires
a
value
' % name, tag)
result[name]=parms[name]
else: raise ParseError, (
'
Invalid
attribute
name
,
"%s"' % name, tag)
else:
result['']=name
return apply(parse_params,(text[l:],result),parms)
elif qunparmre.match(text) >= 0:
name=qunparmre.group(2)
l=len(qunparmre.group(1))
if result: raise ParseError, (
name=qunparmre.group(2)
l=len(qunparmre.group(1))
if result: raise ParseError, (
'
Invalid
attribute
name
,
"%s"' % name, tag)
else: result['']=name
return apply(parse_params,(text[l:],result),parms)
else: result['']=name
return apply(parse_params,(text[l:],result),parms)
else:
if not text or not strip(text): return result
raise ParseError, ('
invalid
parameter
:
"%s"' % text, tag)
if not text or not strip(text): return result
raise ParseError, ('
invalid
parameter
:
"%s"' % text, tag)
if not parms.has_key(name):
raise ParseError, (
'
Invalid
attribute
name
,
"%s"' % name, tag)
raise ParseError, (
'
Invalid
attribute
name
,
"%s"' % name, tag)
if result.has_key(name):
p=parms[name]
...
...
lib/python/DocumentTemplate/DT_Var.py
View file @
cbd3d223
...
...
@@ -100,8 +100,8 @@ __doc__='''Variable insertion parameters
- Cannot be formatted with the specified format, and
- Are either the special Python value 'None' or
are false and yield an empty string when converted to
a string.
are false and yield an empty string when converted to
a string.
For example, when showing a monitary value retrieved from a
database that is either a number or a missing value, the
...
...
@@ -164,8 +164,8 @@ Evaluating expressions without rendering results
'''
# '
__rcs_id__
=
'$Id: DT_Var.py,v 1.2
2 1998/09/14 20:48:42
jim Exp $'
__version__
=
'$Revision: 1.2
2
$'
[
11
:
-
2
]
__rcs_id__
=
'$Id: DT_Var.py,v 1.2
3 1998/09/14 22:03:33
jim Exp $'
__version__
=
'$Revision: 1.2
3
$'
[
11
:
-
2
]
from
DT_Util
import
parse_params
,
name_param
,
html_quote
,
str
import
regex
,
string
,
sys
,
regex
...
...
@@ -176,92 +176,92 @@ class Var:
expr
=
None
def
__init__
(
self
,
args
,
fmt
=
's'
):
args
=
parse_params
(
args
,
name
=
''
,
lower
=
1
,
upper
=
1
,
expr
=
''
,
capitalize
=
1
,
spacify
=
1
,
null
=
''
,
fmt
=
's'
,
size
=
0
,
etc
=
'...'
,
thousands_commas
=
1
,
html_quote
=
1
,
url_quote
=
1
,
sql_quote
=
1
,
newline_to_br
=
1
)
self
.
args
=
args
self
.
modifiers
=
tuple
(
map
(
lambda
t
:
t
[
1
],
filter
(
lambda
m
,
args
=
args
,
used
=
args
.
has_key
:
used
(
m
[
0
])
and
args
[
m
[
0
]],
modifiers
)))
name
,
expr
=
name_param
(
args
,
'var'
,
1
)
self
.
__name__
,
self
.
expr
=
name
,
expr
self
.
fmt
=
fmt
if
len
(
args
)
==
1
and
fmt
==
's'
:
if
expr
is
None
:
expr
=
name
else
:
expr
=
expr
.
eval
self
.
simple_form
=
expr
,
args
=
parse_params
(
args
,
name
=
''
,
lower
=
1
,
upper
=
1
,
expr
=
''
,
capitalize
=
1
,
spacify
=
1
,
null
=
''
,
fmt
=
's'
,
size
=
0
,
etc
=
'...'
,
thousands_commas
=
1
,
html_quote
=
1
,
url_quote
=
1
,
sql_quote
=
1
,
newline_to_br
=
1
)
self
.
args
=
args
self
.
modifiers
=
tuple
(
map
(
lambda
t
:
t
[
1
],
filter
(
lambda
m
,
args
=
args
,
used
=
args
.
has_key
:
used
(
m
[
0
])
and
args
[
m
[
0
]],
modifiers
)))
name
,
expr
=
name_param
(
args
,
'var'
,
1
)
self
.
__name__
,
self
.
expr
=
name
,
expr
self
.
fmt
=
fmt
if
len
(
args
)
==
1
and
fmt
==
's'
:
if
expr
is
None
:
expr
=
name
else
:
expr
=
expr
.
eval
self
.
simple_form
=
expr
,
def
render
(
self
,
md
):
name
=
self
.
__name__
val
=
self
.
expr
if
val
is
None
:
val
=
md
[
name
]
else
:
val
=
val
.
eval
(
md
)
args
=
self
.
args
have_arg
=
args
.
has_key
__traceback_info__
=
name
,
val
,
args
# handle special formats defined using fmt= first
if
have_arg
(
'fmt'
):
fmt
=
args
[
'fmt'
]
if
have_arg
(
'null'
)
and
not
val
and
val
!=
0
:
try
:
if
hasattr
(
val
,
fmt
):
val
=
getattr
(
val
,
fmt
)()
elif
special_formats
.
has_key
(
fmt
):
val
=
special_formats
[
fmt
](
val
,
name
,
md
)
elif
fmt
==
''
:
val
=
''
else
:
val
=
fmt
%
val
except
:
t
,
v
=
sys
.
exc_type
,
sys
.
exc_value
if
val
is
None
or
not
str
(
val
):
return
args
[
'null'
]
raise
t
,
v
else
:
# We duplicate the code here to avoid exception handler
# which tends to screw up stack or leak
if
hasattr
(
val
,
fmt
):
val
=
getattr
(
val
,
fmt
)()
elif
special_formats
.
has_key
(
fmt
):
val
=
special_formats
[
fmt
](
val
,
name
,
md
)
elif
fmt
==
''
:
val
=
''
else
:
val
=
fmt
%
val
# finally, pump it through the actual string format...
fmt
=
self
.
fmt
if
fmt
==
's'
:
val
=
str
(
val
)
else
:
val
=
(
'%'
+
self
.
fmt
)
%
(
val
,)
# next, look for upper, lower, etc
for
f
in
self
.
modifiers
:
val
=
f
(
val
)
if
have_arg
(
'size'
):
size
=
args
[
'size'
]
try
:
size
=
atoi
(
size
)
except
:
raise
'Document Error'
,(
'''a <code>size</code> attribute was used in a <code>var</code>
tag with a non-integer value.'''
)
if
len
(
val
)
>
size
:
val
=
val
[:
size
]
l
=
rfind
(
val
,
' '
)
if
l
>
size
/
2
:
val
=
val
[:
l
+
1
]
if
have_arg
(
'etc'
):
l
=
args
[
'etc'
]
else
:
l
=
'...'
val
=
val
+
l
return
val
name
=
self
.
__name__
val
=
self
.
expr
if
val
is
None
:
val
=
md
[
name
]
else
:
val
=
val
.
eval
(
md
)
args
=
self
.
args
have_arg
=
args
.
has_key
__traceback_info__
=
name
,
val
,
args
# handle special formats defined using fmt= first
if
have_arg
(
'fmt'
):
fmt
=
args
[
'fmt'
]
if
have_arg
(
'null'
)
and
not
val
and
val
!=
0
:
try
:
if
hasattr
(
val
,
fmt
):
val
=
getattr
(
val
,
fmt
)()
elif
special_formats
.
has_key
(
fmt
):
val
=
special_formats
[
fmt
](
val
,
name
,
md
)
elif
fmt
==
''
:
val
=
''
else
:
val
=
fmt
%
val
except
:
t
,
v
=
sys
.
exc_type
,
sys
.
exc_value
if
val
is
None
or
not
str
(
val
):
return
args
[
'null'
]
raise
t
,
v
else
:
# We duplicate the code here to avoid exception handler
# which tends to screw up stack or leak
if
hasattr
(
val
,
fmt
):
val
=
getattr
(
val
,
fmt
)()
elif
special_formats
.
has_key
(
fmt
):
val
=
special_formats
[
fmt
](
val
,
name
,
md
)
elif
fmt
==
''
:
val
=
''
else
:
val
=
fmt
%
val
# finally, pump it through the actual string format...
fmt
=
self
.
fmt
if
fmt
==
's'
:
val
=
str
(
val
)
else
:
val
=
(
'%'
+
self
.
fmt
)
%
(
val
,)
# next, look for upper, lower, etc
for
f
in
self
.
modifiers
:
val
=
f
(
val
)
if
have_arg
(
'size'
):
size
=
args
[
'size'
]
try
:
size
=
atoi
(
size
)
except
:
raise
'Document Error'
,(
'''a <code>size</code> attribute was used in a <code>var</code>
tag with a non-integer value.'''
)
if
len
(
val
)
>
size
:
val
=
val
[:
size
]
l
=
rfind
(
val
,
' '
)
if
l
>
size
/
2
:
val
=
val
[:
l
+
1
]
if
have_arg
(
'etc'
):
l
=
args
[
'etc'
]
else
:
l
=
'...'
val
=
val
+
l
return
val
__call__
=
render
...
...
@@ -270,11 +270,11 @@ class Call:
expr
=
None
def
__init__
(
self
,
args
):
args
=
parse_params
(
args
,
name
=
''
,
expr
=
''
)
name
,
expr
=
name_param
(
args
,
'call'
,
1
)
if
expr
is
None
:
expr
=
name
else
:
expr
=
expr
.
eval
self
.
simple_form
=
expr
,
None
args
=
parse_params
(
args
,
name
=
''
,
expr
=
''
)
name
,
expr
=
name_param
(
args
,
'call'
,
1
)
if
expr
is
None
:
expr
=
name
else
:
expr
=
expr
.
eval
self
.
simple_form
=
expr
,
None
def
url_quote
(
v
,
name
=
'(Unknown name)'
,
md
=
{}):
...
...
@@ -363,7 +363,7 @@ def spacify(val):
return
val
modifiers
=
(
html_quote
,
url_quote
,
newline_to_br
,
string
.
lower
,
string
.
upper
,
string
.
capitalize
,
spacify
,
thousands_commas
,
sql_quote
)
string
.
capitalize
,
spacify
,
thousands_commas
,
sql_quote
)
modifiers
=
map
(
lambda
f
:
(
f
.
__name__
,
f
),
modifiers
)
class
Comment
:
...
...
@@ -386,7 +386,6 @@ class Comment:
def
__init__
(
self
,
args
,
fmt
=
''
):
pass
def
render
(
self
,
md
):
return
''
return
''
__call__
=
render
lib/python/DocumentTemplate/DT_With.py
View file @
cbd3d223
...
...
@@ -75,8 +75,8 @@
'''
__rcs_id__
=
'$Id: DT_With.py,v 1.
5 1998/09/14 20:48:42
jim Exp $'
__version__
=
'$Revision: 1.
5
$'
[
11
:
-
2
]
__rcs_id__
=
'$Id: DT_With.py,v 1.
6 1998/09/14 22:03:33
jim Exp $'
__version__
=
'$Revision: 1.
6
$'
[
11
:
-
2
]
from
DT_Util
import
parse_params
,
name_param
,
InstanceDict
,
render_blocks
,
str
...
...
@@ -86,26 +86,26 @@ class With:
mapping
=
None
def
__init__
(
self
,
blocks
):
tname
,
args
,
section
=
blocks
[
0
]
args
=
parse_params
(
args
,
name
=
''
,
expr
=
''
,
mapping
=
1
)
name
,
expr
=
name_param
(
args
,
'with'
,
1
)
if
expr
is
None
:
expr
=
name
else
:
expr
=
expr
.
eval
self
.
__name__
,
self
.
expr
=
name
,
expr
self
.
section
=
section
.
blocks
if
args
.
has_key
(
'mapping'
)
and
args
[
'mapping'
]:
self
.
mapping
=
1
tname
,
args
,
section
=
blocks
[
0
]
args
=
parse_params
(
args
,
name
=
''
,
expr
=
''
,
mapping
=
1
)
name
,
expr
=
name_param
(
args
,
'with'
,
1
)
if
expr
is
None
:
expr
=
name
else
:
expr
=
expr
.
eval
self
.
__name__
,
self
.
expr
=
name
,
expr
self
.
section
=
section
.
blocks
if
args
.
has_key
(
'mapping'
)
and
args
[
'mapping'
]:
self
.
mapping
=
1
def
render
(
self
,
md
):
expr
=
self
.
expr
if
type
(
expr
)
is
type
(
''
):
v
=
md
[
expr
]
else
:
v
=
expr
(
md
)
if
self
.
mapping
:
md
.
_push
(
v
)
else
:
if
type
(
v
)
is
type
(())
and
len
(
v
)
==
1
:
v
=
v
[
0
]
md
.
_push
(
InstanceDict
(
v
,
md
))
expr
=
self
.
expr
if
type
(
expr
)
is
type
(
''
):
v
=
md
[
expr
]
else
:
v
=
expr
(
md
)
if
self
.
mapping
:
md
.
_push
(
v
)
else
:
if
type
(
v
)
is
type
(())
and
len
(
v
)
==
1
:
v
=
v
[
0
]
md
.
_push
(
InstanceDict
(
v
,
md
))
try
:
return
render_blocks
(
self
.
section
,
md
)
finally
:
md
.
_pop
(
1
)
try
:
return
render_blocks
(
self
.
section
,
md
)
finally
:
md
.
_pop
(
1
)
__call__
=
render
lib/python/DocumentTemplate/DTtest.py
View file @
cbd3d223
...
...
@@ -55,8 +55,8 @@
"""Document Template Tests
"""
__rcs_id__
=
'$Id: DTtest.py,v 1.
8 1998/09/14 20:48:42
jim Exp $'
__version__
=
'$Revision: 1.
8
$'
[
11
:
-
2
]
__rcs_id__
=
'$Id: DTtest.py,v 1.
9 1998/09/14 22:03:34
jim Exp $'
__version__
=
'$Revision: 1.
9
$'
[
11
:
-
2
]
from
DocumentTemplate
import
*
import
sys
...
...
@@ -71,7 +71,7 @@ class Bruce:
def
__len__
(
self
):
return
7
def
__getitem__
(
self
,
index
):
if
(
type
(
index
)
is
type
(
1
)
and
(
index
<
0
or
index
>
6
)):
raise
IndexError
,
index
(
index
<
0
or
index
>
6
)):
raise
IndexError
,
index
return
self
isDocTemp
=
0
def
__getattr__
(
self
,
name
):
...
...
@@ -85,12 +85,12 @@ class arg:
class
argv
:
def
__init__
(
self
):
import
sys
args
=
self
.
args
=
[]
for
aa
in
sys
.
argv
[
1
:]:
args
.
append
(
arg
(
len
(
args
)
+
1
,
aa
))
import
sys
args
=
self
.
args
=
[]
for
aa
in
sys
.
argv
[
1
:]:
args
.
append
(
arg
(
len
(
args
)
+
1
,
aa
))
def
items
(
self
):
return
map
(
lambda
a
:
(
'spam%d'
%
a
.
num
,
a
),
self
.
args
)
return
map
(
lambda
a
:
(
'spam%d'
%
a
.
num
,
a
),
self
.
args
)
def
values
(
self
):
return
self
.
args
...
...
@@ -99,25 +99,25 @@ def test1():
aa
=
argv
()
ss
=
String
(
"""
\
"""
\
%(comment)[ blah %(comment)]
<html><head><title>Test of documentation templates</title></head>
<body>
%(if args)[
<dl><dt>The arguments to this test program were:<p>
<dd>
<ul>
%(in args)[
<li>Argument number %(num)d was %(arg)s
%(in args)]
</ul></dl><p>
%(if args)]
<html><head><title>Test of documentation templates</title></head>
<body>
%(if args)[
<dl><dt>The arguments to this test program were:<p>
<dd>
<ul>
%(in args)[
<li>Argument number %(num)d was %(arg)s
%(in args)]
</ul></dl><p>
%(if args)]
%(else args)[
No arguments were given.<p>
No arguments were given.<p>
%(else args)]
And thats da trooth.
</body></html>
"""
)
And thats da trooth.
</body></html>
"""
)
print
ss
(
aa
)
...
...
@@ -129,8 +129,8 @@ def test1():
print
str
(
ss
)
try
:
ss
(
hello
=
1
,
world
=
2
)
print
'test if test failed'
ss
(
hello
=
1
,
world
=
2
)
print
'test if test failed'
except
:
pass
# Test nested templates
...
...
@@ -144,24 +144,24 @@ def test2():
aa
=
argv
()
print
HTML
(
'''
\
<html><head><title>Test of documentation templates</title></head>
<body>
<!--#if values-->
The arguments were:
<!--#in
values-->
<!--#var
sequence-roman-->.
Argument <!--#var
num fmt=d--> was <!--#var arg-->
<!--#/in values-->
<!--#else values-->
No arguments were given.<p>
<!--#/if values-->
And I
\
'
m 100% sure!
</body></html>
'''
)(
aa
)
'''
\
<html><head><title>Test of documentation templates</title></head>
<body>
<!--#if values-->
The arguments were:
<!--#in
values-->
<!--#var
sequence-roman-->.
Argument <!--#var
num fmt=d--> was <!--#var arg-->
<!--#/in values-->
<!--#else values-->
No arguments were given.<p>
<!--#/if values-->
And I
\
'
m 100% sure!
</body></html>
'''
)(
aa
)
def
test3
():
test2
()
...
...
@@ -169,39 +169,39 @@ def test3():
aa
=
argv
()
h
=
HTML
(
'''
\
<html><head><title>Test of documentation templates</title></head>
<body>
<!--#if args-->
The arguments were:
<!--#in args size=size end=end-->
<!--#if previous-sequence-->
'''
\
<html><head><title>Test of documentation templates</title></head>
<body>
<!--#if args-->
The arguments were:
<!--#in args size=size end=end-->
<!--#if previous-sequence-->
(<!--#var previous-sequence-start-arg-->-
<!--#var previous-sequence-end-arg-->)
<!--#/if previous-sequence-->
<!--#if sequence-start-->
<dl>
<!--#/if sequence-start-->
<dt><!--#var sequence-arg-->.</dt>
<dd>Argument <!--#var num fmt=d--> was <!--#var arg--></dd>
<!--#if next-sequence-->
<!--#var previous-sequence-end-arg-->)
<!--#/if previous-sequence-->
<!--#if sequence-start-->
<dl>
<!--#/if sequence-start-->
<dt><!--#var sequence-arg-->.</dt>
<dd>Argument <!--#var num fmt=d--> was <!--#var arg--></dd>
<!--#if next-sequence-->
(<!--#var next-sequence-start-arg-->-
<!--#var next-sequence-end-arg-->)
<!--#/if next-sequence-->
<!--#/in args-->
</dl>
<!--#else args-->
No arguments were given.<p>
<!--#/if args-->
And I
\
'
m 100% sure!
</body></html>
'''
)
<!--#/if next-sequence-->
<!--#/in args-->
</dl>
<!--#else args-->
No arguments were given.<p>
<!--#/if args-->
And I
\
'
m 100% sure!
</body></html>
'''
)
size
,
orphan
=
5
,
0
for
end
in
range
(
20
):
end
=
end
+
1
print
'='
*
60
,
'
\
n
'
print
h
(
aa
,
size
=
size
,
orphan
=
orphan
,
end
=
end
)
end
=
end
+
1
print
'='
*
60
,
'
\
n
'
print
h
(
aa
,
size
=
size
,
orphan
=
orphan
,
end
=
end
)
def
test3_okay
(
key
,
val
):
print
'Testing'
,
key
...
...
@@ -213,178 +213,178 @@ def test4():
def
item2
(
key
,
**
kw
):
return
kw
class
item_class
:
def
__init__
(
self
,
key
,
**
kw
):
for
k
in
kw
.
keys
():
self
.
__dict__
[
k
]
=
kw
[
k
]
def
__init__
(
self
,
key
,
**
kw
):
for
k
in
kw
.
keys
():
self
.
__dict__
[
k
]
=
kw
[
k
]
items
=
(
item
(
1
,
dealer
=
'Bay Chevy'
,
make
=
'Chevrolet'
,
model
=
'Caprice'
,
year
=
96
),
item
(
2
,
dealer
=
'Bay Chevy'
,
make
=
'Chevrolet'
,
model
=
'Nova'
,
year
=
96
),
item
(
4
,
dealer
=
'Bay Chevy'
,
make
=
'Chevrolet'
,
model
=
'Nova'
,
year
=
96
),
item
(
5
,
dealer
=
'Bay Chevy'
,
make
=
'Chevrolet'
,
model
=
'Nova'
,
year
=
96
),
item
(
3
,
dealer
=
'Bay Chevy'
,
make
=
'Chevrolet'
,
model
=
'Corvett'
,
year
=
96
),
item
(
6
,
dealer
=
'Bay Chevy'
,
make
=
'Chevrolet'
,
model
=
'Lumina'
,
year
=
96
),
item
(
7
,
dealer
=
'Bay Chevy'
,
make
=
'Chevrolet'
,
model
=
'Lumina'
,
year
=
96
),
item
(
8
,
dealer
=
'Bay Chevy'
,
make
=
'Chevrolet'
,
model
=
'Lumina'
,
year
=
95
),
item
(
9
,
dealer
=
'Bay Chevy'
,
make
=
'Chevrolet'
,
model
=
'Corsica'
,
year
=
96
),
item
(
10
,
dealer
=
'Bay Chevy'
,
make
=
'Chevrolet'
,
model
=
'Corsica'
,
year
=
96
),
item
(
11
,
dealer
=
'Bay Chevy'
,
make
=
'Toyota'
,
model
=
'Camry'
,
year
=
95
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Olds'
,
model
=
'Ciera'
,
year
=
96
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Olds'
,
model
=
'Ciera'
,
year
=
96
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Olds'
,
model
=
'Ciera'
,
year
=
96
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Olds'
,
model
=
'Cutlass'
,
year
=
96
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Olds'
,
model
=
'Cutlas'
,
year
=
95
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Dodge'
,
model
=
'Shadow'
,
year
=
93
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Jeep'
,
model
=
'Cheroke'
,
year
=
94
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Toyota'
,
model
=
'Previa'
,
year
=
92
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Toyota'
,
model
=
'Celica'
,
year
=
93
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Toyota'
,
model
=
'Camry'
,
year
=
93
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Honda'
,
model
=
'Accord'
,
year
=
94
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Honda'
,
model
=
'Accord'
,
year
=
92
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Honda'
,
model
=
'Civic'
,
year
=
94
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Honda'
,
model
=
'Civix'
,
year
=
93
),
item
(
1
,
dealer
=
'Spam Chev'
,
make
=
'Chevrolet'
,
model
=
'Caprice'
,
year
=
96
),
item
(
2
,
dealer
=
'Spam Chev'
,
make
=
'Chevrolet'
,
model
=
'Nova'
,
year
=
96
),
item
(
4
,
dealer
=
'Spam Chev'
,
make
=
'Chevrolet'
,
model
=
'Nova'
,
year
=
96
),
item
(
5
,
dealer
=
'Spam Chev'
,
make
=
'Chevrolet'
,
model
=
'Nova'
,
year
=
96
),
item
(
3
,
dealer
=
'Spam Chev'
,
make
=
'Chevrolet'
,
model
=
'Corvett'
,
year
=
96
),
item
(
6
,
dealer
=
'Spam Chev'
,
make
=
'Chevrolet'
,
model
=
'Lumina'
,
year
=
96
),
item
(
7
,
dealer
=
'Spam Chev'
,
make
=
'Chevrolet'
,
model
=
'Lumina'
,
year
=
96
),
item
(
8
,
dealer
=
'Spam Chev'
,
make
=
'Chevrolet'
,
model
=
'Lumina'
,
year
=
95
),
item
(
9
,
dealer
=
'Spam Chev'
,
make
=
'Chevrolet'
,
model
=
'Corsica'
,
year
=
96
),
item
(
10
,
dealer
=
'Spam Chev'
,
make
=
'Chevrolet'
,
model
=
'Corsica'
,
year
=
96
),
item
(
11
,
dealer
=
'Spam Chevy'
,
make
=
'Toyota'
,
model
=
'Camry'
,
year
=
95
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Olds'
,
model
=
'Ciera'
,
year
=
96
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Olds'
,
model
=
'Ciera'
,
year
=
96
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Olds'
,
model
=
'Ciera'
,
year
=
96
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Olds'
,
model
=
'Cutlass'
,
year
=
96
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Olds'
,
model
=
'Cutlas'
,
year
=
95
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Dodge'
,
model
=
'Shadow'
,
year
=
93
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Jeep'
,
model
=
'Cheroke'
,
year
=
94
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Toyota'
,
model
=
'Previa'
,
year
=
92
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Toyota'
,
model
=
'Celica'
,
year
=
93
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Toyota'
,
model
=
'Camry'
,
year
=
93
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Honda'
,
model
=
'Accord'
,
year
=
94
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Honda'
,
model
=
'Accord'
,
year
=
92
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Honda'
,
model
=
'Civic'
,
year
=
94
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Honda'
,
model
=
'Civix'
,
year
=
93
),
)
item
(
1
,
dealer
=
'Bay Chevy'
,
make
=
'Chevrolet'
,
model
=
'Caprice'
,
year
=
96
),
item
(
2
,
dealer
=
'Bay Chevy'
,
make
=
'Chevrolet'
,
model
=
'Nova'
,
year
=
96
),
item
(
4
,
dealer
=
'Bay Chevy'
,
make
=
'Chevrolet'
,
model
=
'Nova'
,
year
=
96
),
item
(
5
,
dealer
=
'Bay Chevy'
,
make
=
'Chevrolet'
,
model
=
'Nova'
,
year
=
96
),
item
(
3
,
dealer
=
'Bay Chevy'
,
make
=
'Chevrolet'
,
model
=
'Corvett'
,
year
=
96
),
item
(
6
,
dealer
=
'Bay Chevy'
,
make
=
'Chevrolet'
,
model
=
'Lumina'
,
year
=
96
),
item
(
7
,
dealer
=
'Bay Chevy'
,
make
=
'Chevrolet'
,
model
=
'Lumina'
,
year
=
96
),
item
(
8
,
dealer
=
'Bay Chevy'
,
make
=
'Chevrolet'
,
model
=
'Lumina'
,
year
=
95
),
item
(
9
,
dealer
=
'Bay Chevy'
,
make
=
'Chevrolet'
,
model
=
'Corsica'
,
year
=
96
),
item
(
10
,
dealer
=
'Bay Chevy'
,
make
=
'Chevrolet'
,
model
=
'Corsica'
,
year
=
96
),
item
(
11
,
dealer
=
'Bay Chevy'
,
make
=
'Toyota'
,
model
=
'Camry'
,
year
=
95
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Olds'
,
model
=
'Ciera'
,
year
=
96
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Olds'
,
model
=
'Ciera'
,
year
=
96
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Olds'
,
model
=
'Ciera'
,
year
=
96
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Olds'
,
model
=
'Cutlass'
,
year
=
96
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Olds'
,
model
=
'Cutlas'
,
year
=
95
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Dodge'
,
model
=
'Shadow'
,
year
=
93
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Jeep'
,
model
=
'Cheroke'
,
year
=
94
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Toyota'
,
model
=
'Previa'
,
year
=
92
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Toyota'
,
model
=
'Celica'
,
year
=
93
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Toyota'
,
model
=
'Camry'
,
year
=
93
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Honda'
,
model
=
'Accord'
,
year
=
94
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Honda'
,
model
=
'Accord'
,
year
=
92
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Honda'
,
model
=
'Civic'
,
year
=
94
),
item
(
12
,
dealer
=
'Colman Olds'
,
make
=
'Honda'
,
model
=
'Civix'
,
year
=
93
),
item
(
1
,
dealer
=
'Spam Chev'
,
make
=
'Chevrolet'
,
model
=
'Caprice'
,
year
=
96
),
item
(
2
,
dealer
=
'Spam Chev'
,
make
=
'Chevrolet'
,
model
=
'Nova'
,
year
=
96
),
item
(
4
,
dealer
=
'Spam Chev'
,
make
=
'Chevrolet'
,
model
=
'Nova'
,
year
=
96
),
item
(
5
,
dealer
=
'Spam Chev'
,
make
=
'Chevrolet'
,
model
=
'Nova'
,
year
=
96
),
item
(
3
,
dealer
=
'Spam Chev'
,
make
=
'Chevrolet'
,
model
=
'Corvett'
,
year
=
96
),
item
(
6
,
dealer
=
'Spam Chev'
,
make
=
'Chevrolet'
,
model
=
'Lumina'
,
year
=
96
),
item
(
7
,
dealer
=
'Spam Chev'
,
make
=
'Chevrolet'
,
model
=
'Lumina'
,
year
=
96
),
item
(
8
,
dealer
=
'Spam Chev'
,
make
=
'Chevrolet'
,
model
=
'Lumina'
,
year
=
95
),
item
(
9
,
dealer
=
'Spam Chev'
,
make
=
'Chevrolet'
,
model
=
'Corsica'
,
year
=
96
),
item
(
10
,
dealer
=
'Spam Chev'
,
make
=
'Chevrolet'
,
model
=
'Corsica'
,
year
=
96
),
item
(
11
,
dealer
=
'Spam Chevy'
,
make
=
'Toyota'
,
model
=
'Camry'
,
year
=
95
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Olds'
,
model
=
'Ciera'
,
year
=
96
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Olds'
,
model
=
'Ciera'
,
year
=
96
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Olds'
,
model
=
'Ciera'
,
year
=
96
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Olds'
,
model
=
'Cutlass'
,
year
=
96
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Olds'
,
model
=
'Cutlas'
,
year
=
95
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Dodge'
,
model
=
'Shadow'
,
year
=
93
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Jeep'
,
model
=
'Cheroke'
,
year
=
94
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Toyota'
,
model
=
'Previa'
,
year
=
92
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Toyota'
,
model
=
'Celica'
,
year
=
93
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Toyota'
,
model
=
'Camry'
,
year
=
93
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Honda'
,
model
=
'Accord'
,
year
=
94
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Honda'
,
model
=
'Accord'
,
year
=
92
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Honda'
,
model
=
'Civic'
,
year
=
94
),
item
(
12
,
dealer
=
'Spam Olds'
,
make
=
'Honda'
,
model
=
'Civix'
,
year
=
93
),
)
html
=
HTML
(
'''
\
<html><head><title>Inventory by Dealer</title></head><body>
<dl>
<!--#in inventory mapping size=5 start=first_ad-->
<!--#if previous-sequence-->
<!--#in
previous-batches mapping-->
(<!--#var batch-start-var-dealer-->
<!--#var batch-start-var-year-->
<!--#var batch-start-var-make-->
<!--#var batch-start-var-model-->
-
<!--#var batch-end-var-dealer-->
<!--#var batch-end-var-year-->
<!--#var batch-end-var-make-->
<!--#var batch-end-var-model-->
)
<!--#/in previous-batches-->
<!--#/if previous-sequence-->
<!--#if first-dealer-->
<dt><!--#var dealer--></dt><dd>
<!--#/if first-dealer-->
<!--#var year--> <!--#var make--> <!--#var model--> <p>
<!--#if last-dealer-->
</dd>
<!--#/if last-dealer-->
<!--#if next-sequence-->
<!--#in next-batches mapping-->
(<!--#var batch-start-var-dealer-->
<!--#var batch-start-var-year-->
<!--#var batch-start-var-make-->
<!--#var batch-start-var-model-->
-
<!--#var batch-end-var-dealer-->
<!--#var batch-end-var-year-->
<!--#var batch-end-var-make-->
<!--#var batch-end-var-model-->
)
<!--#/in next-batches-->
<!--#/if next-sequence-->
<!--#/in inventory-->
</dl>
</body></html>
'''
)
'''
\
<html><head><title>Inventory by Dealer</title></head><body>
<dl>
<!--#in inventory mapping size=5 start=first_ad-->
<!--#if previous-sequence-->
<!--#in
previous-batches mapping-->
(<!--#var batch-start-var-dealer-->
<!--#var batch-start-var-year-->
<!--#var batch-start-var-make-->
<!--#var batch-start-var-model-->
-
<!--#var batch-end-var-dealer-->
<!--#var batch-end-var-year-->
<!--#var batch-end-var-make-->
<!--#var batch-end-var-model-->
)
<!--#/in previous-batches-->
<!--#/if previous-sequence-->
<!--#if first-dealer-->
<dt><!--#var dealer--></dt><dd>
<!--#/if first-dealer-->
<!--#var year--> <!--#var make--> <!--#var model--> <p>
<!--#if last-dealer-->
</dd>
<!--#/if last-dealer-->
<!--#if next-sequence-->
<!--#in next-batches mapping-->
(<!--#var batch-start-var-dealer-->
<!--#var batch-start-var-year-->
<!--#var batch-start-var-make-->
<!--#var batch-start-var-model-->
-
<!--#var batch-end-var-dealer-->
<!--#var batch-end-var-year-->
<!--#var batch-end-var-make-->
<!--#var batch-end-var-model-->
)
<!--#/in next-batches-->
<!--#/if next-sequence-->
<!--#/in inventory-->
</dl>
</body></html>
'''
)
print
html
(
inventory
=
items
,
first_ad
=
15
)
def
test5
():
html
=
HTML
(
'''
\
<html><head><title>Affiliate Manager Affiliate Menu</title></head><body>
<CENTER>
<FONT SIZE="+2">Affiliate Manager Menu</FONT>
<p>
<!--#if affiliates-->
Select an affiliate to visit:<br>
<UL>
<!--#in affiliates-->
<LI><A HREF="<!--#var PARENT_URL-->/<!--#var ID-->/">
<!--#var name--></A></LI>
<!--#/in affiliates-->
</UL>
<!--#/if affiliates-->
<p>
<A HREF="<!--#var PARENT_URL-->/add_affiliate_form">Add an affiliate</A>
<!--#if affiliates-->
* <A HREF="<!--#var PARENT_URL-->/delete_affiliates_form">
Delete affiliates</A>
<!--#/if affiliates-->
</p>
</CENTER>
</body>
</html>'''
)
'''
\
<html><head><title>Affiliate Manager Affiliate Menu</title></head><body>
<CENTER>
<FONT SIZE="+2">Affiliate Manager Menu</FONT>
<p>
<!--#if affiliates-->
Select an affiliate to visit:<br>
<UL>
<!--#in affiliates-->
<LI><A HREF="<!--#var PARENT_URL-->/<!--#var ID-->/">
<!--#var name--></A></LI>
<!--#/in affiliates-->
</UL>
<!--#/if affiliates-->
<p>
<A HREF="<!--#var PARENT_URL-->/add_affiliate_form">Add an affiliate</A>
<!--#if affiliates-->
* <A HREF="<!--#var PARENT_URL-->/delete_affiliates_form">
Delete affiliates</A>
<!--#/if affiliates-->
</p>
</CENTER>
</body>
</html>'''
)
print
html
(
affiliates
=
[],
PARENT_URL
=
'www'
)
def
test6
():
def
d
(
**
kw
):
return
kw
data
=
(
d
(
name
=
'jim'
,
age
=
38
),
# d(name='kak', age=40),
d
(
name
=
'will'
,
age
=
7
),
d
(
name
=
'drew'
,
age
=
4
),
d
(
name
=
'ches'
,
age
=
1
),
)
# d(name='kak', age=40),
d
(
name
=
'will'
,
age
=
7
),
d
(
name
=
'drew'
,
age
=
4
),
d
(
name
=
'ches'
,
age
=
1
),
)
html
=
HTML
(
"""Ages:
\
n
<!--#in data mapping-->
<!--#if sequence-end-->
---------------
for variable name:
min: <!--#var min-name-->
max: <!--#var max-name-->
count: <!--#var count-name-->
total: <!--#var total-name-->
median: <!--#var median-name-->
---------------
for variable age:
min: <!--#var min-age-->
max: <!--#var max-age-->
count: <!--#var count-age-->
total: <!--#var total-age-->
median: <!--#var median-age-->
mean: <!--#var mean-age-->
s.d. <!--#var standard-deviation-age-->
---------------
<!--#/if sequence-end-->
<!--#/in data-->
"""
)
"""Ages:
\
n
<!--#in data mapping-->
<!--#if sequence-end-->
---------------
for variable name:
min: <!--#var min-name-->
max: <!--#var max-name-->
count: <!--#var count-name-->
total: <!--#var total-name-->
median: <!--#var median-name-->
---------------
for variable age:
min: <!--#var min-age-->
max: <!--#var max-age-->
count: <!--#var count-age-->
total: <!--#var total-age-->
median: <!--#var median-age-->
mean: <!--#var mean-age-->
s.d. <!--#var standard-deviation-age-->
---------------
<!--#/if sequence-end-->
<!--#/in data-->
"""
)
print
html
(
data
=
data
)
def
test7
():
...
...
@@ -395,7 +395,7 @@ def test7():
"""
)
html
.
names
({
'name'
:
'name'
,
'date'
:
'date'
})
print
html
(
date
=
DateTime
.
DateTime
(),
name
=
'todays_date'
)
name
=
'todays_date'
)
def
test8
():
import
DateTime
...
...
@@ -404,36 +404,36 @@ def test8():
%(date fmt=year)s/%(date fmt=month)s/%(date fmt=day)s
"""
)
print
html
(
date
=
DateTime
.
DateTime
(),
name
=
'todays_date'
)
name
=
'todays_date'
)
def
test9
():
html
=
HTML
(
"""
"""
<!--#in spam-->
<!--#in sequence-item-->
<!--#var sequence-item-->
<!--#/in sequence-item-->
<!--#/in spam-->
"""
)
"""
)
print
html
(
spam
=
[[
1
,
2
,
3
],[
4
,
5
,
6
]])
def
test9a
():
html
=
HTML
(
"""
<!--#in spam-->
<!--#in sequence-item-->
<!--#var sequence-item-->
<!--#/in sequence-item-->
<!--#/in spam-->
"""
)
"""
<!--#in spam-->
<!--#in sequence-item-->
<!--#var sequence-item-->
<!--#/in sequence-item-->
<!--#/in spam-->
"""
)
print
html
(
spam
=
[[
1
,
2
,
3
],[
4
,
5
,
6
]])
def
test10
():
#import Missing
html
=
HTML
(
"""
<!--#var spam fmt="$%.2f bob's your uncle" null="spam%eggs!|"-->
"""
)
#'
"""
<!--#var spam fmt="$%.2f bob's your uncle" null="spam%eggs!|"-->
"""
)
#'
print
html
(
spam
=
42
)
print
html
(
spam
=
None
)
#print html(spam=Missing.Value)
...
...
@@ -442,17 +442,17 @@ def test10():
def
test11
():
#import Missing
html
=
HTML
(
"""
<!--#var spam -->
html: <!--#var spam fmt=html-quote-->
url: <!--#var spam fmt=url-quote-->
multi: <!--#var spam fmt=multi-line-->
dollars: <!--#var spam fmt=whole-dollars-->
cents: <!--#var spam fmt=dollars-and-cents-->
dollars,: <!--#var spam fmt=dollars-with-commas-->
cents,: <!--#var spam fmt=dollars-and-cents-with-commas-->
"""
)
"""
<!--#var spam -->
html: <!--#var spam fmt=html-quote-->
url: <!--#var spam fmt=url-quote-->
multi: <!--#var spam fmt=multi-line-->
dollars: <!--#var spam fmt=whole-dollars-->
cents: <!--#var spam fmt=dollars-and-cents-->
dollars,: <!--#var spam fmt=dollars-with-commas-->
cents,: <!--#var spam fmt=dollars-and-cents-with-commas-->
"""
)
print
html
(
spam
=
4200000
)
print
html
(
spam
=
None
)
...
...
@@ -462,30 +462,30 @@ def test11():
class
test12ob
:
def
__init__
(
self
,
**
kw
):
for
k
,
v
in
kw
.
items
():
self
.
__dict__
[
k
]
=
v
for
k
,
v
in
kw
.
items
():
self
.
__dict__
[
k
]
=
v
def
puke
(
self
):
raise
'Puke'
,
'raaalf'
raise
'Puke'
,
'raaalf'
def
test12
():
class
foo
:
def
__len__
(
self
):
return
9
def
__getitem__
(
self
,
i
):
if
i
>=
9
:
raise
IndexError
,
i
return
test12ob
(
index
=
i
,
value
=
'item %s'
%
i
)
def
__len__
(
self
):
return
9
def
__getitem__
(
self
,
i
):
if
i
>=
9
:
raise
IndexError
,
i
return
test12ob
(
index
=
i
,
value
=
'item %s'
%
i
)
html
=
HTML
(
"""
<!--#if spam-->
<!--#in spam-->
<!--#var value-->
<!--#var puke-->
<!--#/in spam-->
<!--#/if spam-->
"""
)
"""
<!--#if spam-->
<!--#in spam-->
<!--#var value-->
<!--#var puke-->
<!--#/in spam-->
<!--#/if spam-->
"""
)
try
:
print
html
(
spam
=
foo
())
except
:
return
raise
'DocumentTemplate bug'
,
(
'Puke error not properly propigated in test 12'
)
'Puke error not properly propigated in test 12'
)
def
test13
():
"Test automatic rendering of callable obnjects"
...
...
@@ -523,47 +523,46 @@ def test15():
print
v
def
main
():
import
traceback
print
'Test 1'
,
'='
*
60
try
:
test1
()
except
:
traceback
.
print_exc
()
print
'Test 2'
,
'='
*
60
try
:
test2
()
except
:
traceback
.
print_exc
()
print
'Test 3'
,
'='
*
60
try
:
test3
()
except
:
traceback
.
print_exc
()
print
'Test 4'
,
'='
*
60
try
:
test4
()
except
:
traceback
.
print_exc
()
print
'Test 5'
,
'='
*
60
try
:
test5
()
except
:
traceback
.
print_exc
()
print
'Test 6'
,
'='
*
60
try
:
test6
()
except
:
traceback
.
print_exc
()
print
'Test 9'
,
'='
*
60
try
:
test9
()
except
:
traceback
.
print_exc
()
print
'Test 9a'
,
'='
*
60
try
:
test9a
()
except
:
traceback
.
print_exc
()
print
'Test 10'
,
'='
*
60
try
:
test10
()
except
:
traceback
.
print_exc
()
print
'Test 11'
,
'='
*
60
try
:
test11
()
except
:
traceback
.
print_exc
()
print
'Test 14'
,
'='
*
60
try
:
test14
()
except
:
traceback
.
print_exc
()
print
'Test 15'
,
'='
*
60
try
:
test15
()
except
:
traceback
.
print_exc
()
import
traceback
print
'Test 1'
,
'='
*
60
try
:
test1
()
except
:
traceback
.
print_exc
()
print
'Test 2'
,
'='
*
60
try
:
test2
()
except
:
traceback
.
print_exc
()
print
'Test 3'
,
'='
*
60
try
:
test3
()
except
:
traceback
.
print_exc
()
print
'Test 4'
,
'='
*
60
try
:
test4
()
except
:
traceback
.
print_exc
()
print
'Test 5'
,
'='
*
60
try
:
test5
()
except
:
traceback
.
print_exc
()
print
'Test 6'
,
'='
*
60
try
:
test6
()
except
:
traceback
.
print_exc
()
print
'Test 9'
,
'='
*
60
try
:
test9
()
except
:
traceback
.
print_exc
()
print
'Test 9a'
,
'='
*
60
try
:
test9a
()
except
:
traceback
.
print_exc
()
print
'Test 10'
,
'='
*
60
try
:
test10
()
except
:
traceback
.
print_exc
()
print
'Test 11'
,
'='
*
60
try
:
test11
()
except
:
traceback
.
print_exc
()
print
'Test 14'
,
'='
*
60
try
:
test14
()
except
:
traceback
.
print_exc
()
print
'Test 15'
,
'='
*
60
try
:
test15
()
except
:
traceback
.
print_exc
()
if
__name__
==
"__main__"
:
try
:
command
=
sys
.
argv
[
1
]
except
:
command
=
'main'
globals
()[
command
]()
lib/python/DocumentTemplate/DTtest_basicIn.py
View file @
cbd3d223
...
...
@@ -57,7 +57,7 @@ def d(**kw): return kw
class
D
:
def
__init__
(
self
,
**
kw
):
for
k
,
v
in
kw
.
items
():
self
.
__dict__
[
k
]
=
v
for
k
,
v
in
kw
.
items
():
self
.
__dict__
[
k
]
=
v
def
__repr__
(
self
):
return
"D(%s)"
%
`self.__dict__`
...
...
lib/python/DocumentTemplate/VSEval.py
View file @
cbd3d223
...
...
@@ -54,8 +54,8 @@
"""Very Safe Python Expressions
"""
__rcs_id__
=
'$Id: VSEval.py,v 1.1
8 1998/09/14 20:48:43
jim Exp $'
__version__
=
'$Revision: 1.1
8
$'
[
11
:
-
2
]
__rcs_id__
=
'$Id: VSEval.py,v 1.1
9 1998/09/14 22:03:34
jim Exp $'
__version__
=
'$Revision: 1.1
9
$'
[
11
:
-
2
]
from
string
import
translate
import
string
...
...
@@ -73,12 +73,12 @@ def careful_mul(env, *factors):
s
=
None
r
=
1
for
factor
in
factors
:
try
:
l
=
len
(
factor
)
s
=
1
except
:
l
=
factor
if
s
and
(
l
*
r
)
>
1000
:
raise
TypeError
,
'Illegal sequence repeat'
r
=
r
*
factor
try
:
l
=
len
(
factor
)
s
=
1
except
:
l
=
factor
if
s
and
(
l
*
r
)
>
1000
:
raise
TypeError
,
'Illegal sequence repeat'
r
=
r
*
factor
return
r
...
...
@@ -109,68 +109,68 @@ class Eval:
"""
def
__init__
(
self
,
expr
,
globals
=
default_globals
):
"""Create a 'safe' expression
"""Create a 'safe' expression
where:
where:
expr -- a string containing the expression to be evaluated.
expr -- a string containing the expression to be evaluated.
globals -- A global namespace.
"""
globals -- A global namespace.
"""
global
gparse
if
gparse
is
None
:
import
gparse
self
.
__name__
=
expr
expr
=
translate
(
expr
,
nltosp
)
self
.
expr
=
expr
self
.
globals
=
globals
co
=
compile
(
expr
,
'<string>'
,
'eval'
)
names
=
list
(
co
.
co_names
)
# Check for valid names, disallowing names that begin with '_' or
# 'manage'. This is a DC specific rule and probably needs to be
# made customizable!
for
name
in
names
:
if
name
[:
1
]
==
'_'
and
name
not
in
(
'_'
,
'_vars'
,
'_getattr'
):
raise
TypeError
,
'illegal name used in expression'
used
=
{}
i
=
0
code
=
co
.
co_code
l
=
len
(
code
)
LOAD_NAME
=
101
HAVE_ARGUMENT
=
90
def
HAS_ARG
(
op
):
((
op
)
>=
HAVE_ARGUMENT
)
while
(
i
<
l
):
c
=
ord
(
code
[
i
])
if
c
==
LOAD_NAME
:
name
=
names
[
ord
(
code
[
i
+
1
])
+
256
*
ord
(
code
[
i
+
2
])]
used
[
name
]
=
1
i
=
i
+
3
elif
c
>=
HAVE_ARGUMENT
:
i
=
i
+
3
else
:
i
=
i
+
1
self
.
code
=
gparse
.
compile
(
expr
,
'<string>'
,
'eval'
)
self
.
used
=
tuple
(
used
.
keys
())
self
.
__name__
=
expr
expr
=
translate
(
expr
,
nltosp
)
self
.
expr
=
expr
self
.
globals
=
globals
co
=
compile
(
expr
,
'<string>'
,
'eval'
)
names
=
list
(
co
.
co_names
)
# Check for valid names, disallowing names that begin with '_' or
# 'manage'. This is a DC specific rule and probably needs to be
# made customizable!
for
name
in
names
:
if
name
[:
1
]
==
'_'
and
name
not
in
(
'_'
,
'_vars'
,
'_getattr'
):
raise
TypeError
,
'illegal name used in expression'
used
=
{}
i
=
0
code
=
co
.
co_code
l
=
len
(
code
)
LOAD_NAME
=
101
HAVE_ARGUMENT
=
90
def
HAS_ARG
(
op
):
((
op
)
>=
HAVE_ARGUMENT
)
while
(
i
<
l
):
c
=
ord
(
code
[
i
])
if
c
==
LOAD_NAME
:
name
=
names
[
ord
(
code
[
i
+
1
])
+
256
*
ord
(
code
[
i
+
2
])]
used
[
name
]
=
1
i
=
i
+
3
elif
c
>=
HAVE_ARGUMENT
:
i
=
i
+
3
else
:
i
=
i
+
1
self
.
code
=
gparse
.
compile
(
expr
,
'<string>'
,
'eval'
)
self
.
used
=
tuple
(
used
.
keys
())
def
eval
(
self
,
mapping
):
d
=
{
'_vars'
:
mapping
}
code
=
self
.
code
globals
=
self
.
globals
for
name
in
self
.
used
:
try
:
d
[
name
]
=
mapping
.
getitem
(
name
,
0
)
except
KeyError
:
if
name
==
'_getattr'
:
d
[
'__builtins__'
]
=
globals
exec
compiled_getattr
in
d
code
=
self
.
code
globals
=
self
.
globals
for
name
in
self
.
used
:
try
:
d
[
name
]
=
mapping
.
getitem
(
name
,
0
)
except
KeyError
:
if
name
==
'_getattr'
:
d
[
'__builtins__'
]
=
globals
exec
compiled_getattr
in
d
return
eval
(
code
,
globals
,
d
)
return
eval
(
code
,
globals
,
d
)
def
__call__
(
self
,
**
kw
):
return
eval
(
self
.
code
,
self
.
globals
,
kw
)
return
eval
(
self
.
code
,
self
.
globals
,
kw
)
compiled_getattr
=
compile
(
'def _getattr(o,n): return __guarded_getattr__(_vars,o,n)'
,
...
...
lib/python/DocumentTemplate/release_notes
View file @
cbd3d223
DocumentTemplate releases
2.2
This release has a number of new features and bug fixes.
Features
- There is a new user's guide in HTML and PDF formats with
table of contents and index.
-
Import of some modules is delayed providing 30% faster imports
.
-
AFAIK DocumentTemplate is now thread-safe
.
- Several occurrences of 'from some_module import *' have been
eliminated.
- There is a new open-source copyright.
-
No longer enable the through-the-web-editing interface by default
.
-
Import of some modules is delayed providing 30% faster imports
.
-
Made regex use thread safe
.
-
No longer enable the through-the-web-editing interface by default
.
- Added short-hand expr usage:
...
...
@@ -20,6 +25,11 @@ DocumentTemplate releases
<!--#some_tag expr="foo.bar"-->
Bugs fixed
- Several occurrences of 'from some_module import *' have been
eliminated.
- Fixed bugs in error reporting.
- Handle valueless attributes a bit better.
...
...
@@ -120,5 +130,5 @@ DocumentTemplate releases
- New 'in' tag variables for getting information about the start and
end indexes of the current batch.
"Download DocumentTemplate 2.
1":DocumentTemplate-2.1
.tar.gz.
"Download DocumentTemplate 2.
2":DocumentTemplate-2.2
.tar.gz.
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