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
3305e327
Commit
3305e327
authored
Mar 04, 1998
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extended the parse_name utility to handle other name-like tags.
parent
cf626173
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
14 deletions
+20
-14
lib/python/DocumentTemplate/DT_Util.py
lib/python/DocumentTemplate/DT_Util.py
+20
-14
No files found.
lib/python/DocumentTemplate/DT_Util.py
View file @
3305e327
'''$Id: DT_Util.py,v 1.2
2 1998/01/13 19:35:55
jim Exp $'''
'''$Id: DT_Util.py,v 1.2
3 1998/03/04 18:18:40
jim Exp $'''
############################################################################
############################################################################
# Copyright
# Copyright
...
@@ -52,7 +52,7 @@
...
@@ -52,7 +52,7 @@
# (540) 371-6909
# (540) 371-6909
#
#
############################################################################
############################################################################
__version__
=
'$Revision: 1.2
2
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.2
3
$'
[
11
:
-
2
]
import
sys
,
regex
,
string
,
types
,
math
,
os
import
sys
,
regex
,
string
,
types
,
math
,
os
from
string
import
rfind
,
strip
,
joinfields
,
atoi
,
lower
,
upper
,
capitalize
from
string
import
rfind
,
strip
,
joinfields
,
atoi
,
lower
,
upper
,
capitalize
...
@@ -62,6 +62,7 @@ from __builtin__ import *
...
@@ -62,6 +62,7 @@ from __builtin__ import *
import
VSEval
import
VSEval
ParseError
=
'Document Template Parse Error'
ParseError
=
'Document Template Parse Error'
ValidationError
=
'ValidationError'
def
int_param
(
params
,
md
,
name
,
default
=
0
):
def
int_param
(
params
,
md
,
name
,
default
=
0
):
try
:
v
=
params
[
name
]
try
:
v
=
params
[
name
]
...
@@ -89,7 +90,7 @@ def careful_getattr(md, inst, name):
...
@@ -89,7 +90,7 @@ def careful_getattr(md, inst, name):
v
=
getattr
(
inst
,
name
)
v
=
getattr
(
inst
,
name
)
if
validate
(
inst
,
inst
,
name
,
v
,
md
):
return
v
if
validate
(
inst
,
inst
,
name
,
v
,
md
):
return
v
raise
Attribute
Error
,
name
raise
Validation
Error
,
name
def
careful_getitem
(
md
,
mapping
,
key
):
def
careful_getitem
(
md
,
mapping
,
key
):
v
=
mapping
[
key
]
v
=
mapping
[
key
]
...
@@ -98,7 +99,7 @@ def careful_getitem(md, mapping, key):
...
@@ -98,7 +99,7 @@ def careful_getitem(md, mapping, key):
validate
=
md
.
validate
validate
=
md
.
validate
if
validate
is
None
or
validate
(
mapping
,
mapping
,
key
,
v
,
md
):
return
v
if
validate
is
None
or
validate
(
mapping
,
mapping
,
key
,
v
,
md
):
return
v
raise
KeyError
,
key
raise
Validation
,
key
def
careful_getslice
(
md
,
seq
,
*
indexes
):
def
careful_getslice
(
md
,
seq
,
*
indexes
):
v
=
len
(
indexes
)
v
=
len
(
indexes
)
...
@@ -114,7 +115,7 @@ def careful_getslice(md, seq, *indexes):
...
@@ -114,7 +115,7 @@ def careful_getslice(md, seq, *indexes):
if
validate
is
not
None
:
if
validate
is
not
None
:
for
e
in
v
:
for
e
in
v
:
if
not
validate
(
seq
,
seq
,
''
,
e
,
md
):
if
not
validate
(
seq
,
seq
,
''
,
e
,
md
):
raise
Type
Error
,
'unauthorized access to slice member'
raise
Validation
Error
,
'unauthorized access to slice member'
return
v
return
v
...
@@ -150,26 +151,28 @@ expr_globals={
...
@@ -150,26 +151,28 @@ expr_globals={
'__guarded_getslice__'
:
careful_getslice
,
'__guarded_getslice__'
:
careful_getslice
,
}
}
def
name_param
(
params
,
tag
=
''
,
expr
=
0
):
def
name_param
(
params
,
tag
=
''
,
expr
=
0
,
attr
=
'name'
):
used
=
params
.
has_key
used
=
params
.
has_key
if
used
(
''
):
if
used
(
''
):
if
used
(
'name'
):
if
used
(
attr
):
raise
ParseError
,
_tm
(
'Two
names were given'
,
tag
)
raise
ParseError
,
_tm
(
'Two
%s values were given'
,
(
attr
,
tag
)
)
if
expr
:
if
expr
:
if
used
(
'expr'
):
raise
ParseError
,
_tm
(
'name and expr given'
,
tag
)
if
used
(
'expr'
):
raise
ParseError
,
_tm
(
'%s and expr given'
,
(
attr
,
tag
))
return
params
[
''
],
None
return
params
[
''
],
None
return
params
[
''
]
return
params
[
''
]
elif
used
(
'name'
):
elif
used
(
attr
):
if
expr
:
if
expr
:
if
used
(
'expr'
):
raise
ParseError
,
_tm
(
'name and expr given'
,
tag
)
if
used
(
'expr'
):
return
params
[
'name'
],
None
raise
ParseError
,
_tm
(
'%s and expr given'
,
(
attr
,
tag
))
return
params
[
'name'
]
return
params
[
attr
],
None
return
params
[
attr
]
elif
expr
and
used
(
'expr'
):
elif
expr
and
used
(
'expr'
):
name
=
params
[
'expr'
]
name
=
params
[
'expr'
]
expr
=
VSEval
.
Eval
(
name
,
expr_globals
)
expr
=
VSEval
.
Eval
(
name
,
expr_globals
)
return
name
,
expr
return
name
,
expr
raise
ParseError
,
(
'No
name given'
,
tag
)
raise
ParseError
,
(
'No
%s given'
,
(
attr
,
tag
)
)
Expr_doc
=
"""
Expr_doc
=
"""
...
@@ -304,6 +307,9 @@ except: from pDocumentTemplate import InstanceDict, TemplateDict, render_blocks
...
@@ -304,6 +307,9 @@ except: from pDocumentTemplate import InstanceDict, TemplateDict, render_blocks
############################################################################
############################################################################
# $Log: DT_Util.py,v $
# $Log: DT_Util.py,v $
# Revision 1.23 1998/03/04 18:18:40 jim
# Extended the parse_name utility to handle other name-like tags.
#
# Revision 1.22 1998/01/13 19:35:55 jim
# Revision 1.22 1998/01/13 19:35:55 jim
# Added rand and whrand.
# Added rand and whrand.
#
#
...
...
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