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
3e57bf37
Commit
3e57bf37
authored
Aug 27, 1997
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial
parent
d8b33db7
Changes
15
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
4049 additions
and
0 deletions
+4049
-0
lib/python/DocumentTemplate/DT_Doc.py
lib/python/DocumentTemplate/DT_Doc.py
+323
-0
lib/python/DocumentTemplate/DT_HTML.py
lib/python/DocumentTemplate/DT_HTML.py
+170
-0
lib/python/DocumentTemplate/DT_If.py
lib/python/DocumentTemplate/DT_If.py
+180
-0
lib/python/DocumentTemplate/DT_In.py
lib/python/DocumentTemplate/DT_In.py
+720
-0
lib/python/DocumentTemplate/DT_String.py
lib/python/DocumentTemplate/DT_String.py
+427
-0
lib/python/DocumentTemplate/DT_UI.py
lib/python/DocumentTemplate/DT_UI.py
+165
-0
lib/python/DocumentTemplate/DT_Util.py
lib/python/DocumentTemplate/DT_Util.py
+159
-0
lib/python/DocumentTemplate/DT_Var.py
lib/python/DocumentTemplate/DT_Var.py
+261
-0
lib/python/DocumentTemplate/DTtest.py
lib/python/DocumentTemplate/DTtest.py
+553
-0
lib/python/DocumentTemplate/DTtest_basicIn.py
lib/python/DocumentTemplate/DTtest_basicIn.py
+52
-0
lib/python/DocumentTemplate/DocumentTemplate.py
lib/python/DocumentTemplate/DocumentTemplate.py
+222
-0
lib/python/DocumentTemplate/Setup
lib/python/DocumentTemplate/Setup
+20
-0
lib/python/DocumentTemplate/__init__.py
lib/python/DocumentTemplate/__init__.py
+79
-0
lib/python/DocumentTemplate/cDocumentTemplate.c
lib/python/DocumentTemplate/cDocumentTemplate.c
+502
-0
lib/python/DocumentTemplate/pDocumentTemplate.py
lib/python/DocumentTemplate/pDocumentTemplate.py
+216
-0
No files found.
lib/python/DocumentTemplate/DT_Doc.py
0 → 100644
View file @
3e57bf37
This diff is collapsed.
Click to expand it.
lib/python/DocumentTemplate/DT_HTML.py
0 → 100644
View file @
3e57bf37
"""HTML formated DocumentTemplates
$Id: DT_HTML.py,v 1.1 1997/08/27 18:55:41 jim Exp $"""
from
DT_String
import
String
,
FileMixin
import
DT_Doc
,
DT_String
,
regex
from
regsub
import
gsub
class
HTML
(
DT_String
.
String
):
__doc__
=
DT_Doc
.
HTML__doc__
def
tagre
(
self
):
return
regex
.
symcomp
(
'<!--#'
# beginning
'
\
(<e
n
d>/
\
|e
n
d
\
)?
'
# end tag marker
'
\
(
<
name
>
[
a
-
z
]
+
\
)
' # tag name
'
[
\
0
-
]
*
' # space after tag name
'
\
(
<
args
>
\
([
^>
"]+
\
(
"
[^"
]
*
"
\
)?
\
)*
\
)
'
# arguments
'-->' # end
, regex.casefold)
def parseTag(self, tagre, command=None):
"""Parse a tag using an already matched re
Return: tag, args, command, coname
where: tag is the tag,
args is the tag
\
'
s argument string,
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')
if end:
if not command or name != command.name:
raise ParseError, 'unexpected end tag'
return tag, args, None, None
if command and name in command.blockContinuations:
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)
def quotedHTML(self,
character_entities=(
(regex.compile('&'), '&'),
(regex.compile("
<
"), '<' ),
(regex.compile("
>
"), '>' ),
(regex.compile('"'), '
&
quot
;
'))): #"
text=self.read_raw()
for re,name in character_entities:
text=gsub(re,name,text)
return text
def __str__(self):
return self.quotedHTML()
def management_interface(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''' #"
self._manage_editForm.validator(self.validate)
return self._manage_editForm(
self,
mapping=REQUEST,
__str__=str(self),
vars=self._names.items(),
PARENT_URL=PARENT_URL
)
manage_editDocument=manage=manage_editForm
def validate(self, key, value=None):
if os.environ.has_key(key): return 1
return 0
class HTMLDefault(HTML):
'''
\
HTML document templates that edit themselves through copy.
This is to make a distinction from HTML objects that should edit
themselves in place.
'''
copy_class=HTML
def manage_edit(self,data,PARENTS,URL1,REQUEST):
'
edit
a
template
'
newHTML=self.copy_class(data,self.globals,self.__name__,
self._names, self._validator)
setattr(PARENTS[1],URL1[rfind(URL1,'
/
')+1:],newHTML)
return self.editConfirmation(self,REQUEST)
class HTMLFile(FileMixin, HTML):
"""
\
HTML Document templates read from files.
If the object is pickled, the file name, rather
than the file contents is pickled. When the object is
unpickled, then the file will be re-read to obtain the string.
Note that the file will not be read until the document
template is used the first time.
"""
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)
def manage_editForm(self, PARENT_URL, REQUEST):
'''Display doc template editing form''' #"
self._manage_editForm.validator(self.validate)
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),
vars=self._names.items(),
FactoryDefaultString=FactoryDefaultString,
)
manage_editDocument=manage=manage_editForm
def manage_edit(self,data,
PARENTS=[],URL1='',URL2='',REQUEST='', SUBMIT='',
crlf=regex.compile('
\
r
\
n
\
|
\
n
\
r')):
'
edit
a
template
'
if SUBMIT==FactoryDefaultString: return self.manage_default(REQUEST)
data=gsub(crlf,'
\
n
',data)
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)
##########################################################################
#
# $Log: DT_HTML.py,v $
# Revision 1.1 1997/08/27 18:55:41 jim
# initial
#
lib/python/DocumentTemplate/DT_If.py
0 → 100644
View file @
3e57bf37
__doc__
=
'''Conditional insertion
Conditional insertion is performed using 'if' and 'else'
commands.
To include text when an object is true using the EPFS
format, use::
%(if name)[
text
%(if name)]
To include text when an object is true using the HTML
format, use::
<!--#if name-->
text
<!--#/if name-->
where 'name' is the name bound to the object.
To include text when an object is false using the EPFS
format, use::
%(else name)[
text
%(else name)]
To include text when an object is false using the HTML
format, use::
<!--#else name-->
text
<!--#/else name-->
Finally to include text when an object is true and to
include different text when the object is false using the
EPFS format, use::
%(if name)[
true text
%(if name)]
%(else name)[
false text
%(else name)]
and to include text when an object is true and to
include different text when the object is false using the
HTML format, use::
<!--#if name-->
true text
<!--#else name-->
false text
<!--#/if name-->
Note that if a variable is nor defined, it is considered to be false.
'''
############################################################################
# Copyright
#
# Copyright 1996 Digital Creations, L.C., 910 Princess Anne
# Street, Suite 300, Fredericksburg, Virginia 22401 U.S.A. All
# rights reserved. Copyright in this software is owned by DCLC,
# unless otherwise indicated. Permission to use, copy and
# distribute this software is hereby granted, provided that the
# above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear. Note that
# any product, process or technology described in this software
# may be the subject of other Intellectual Property rights
# reserved by Digital Creations, L.C. and are not licensed
# hereunder.
#
# Trademarks
#
# Digital Creations & DCLC, are trademarks of Digital Creations, L.C..
# All other trademarks are owned by their respective companies.
#
# No Warranty
#
# The software is provided "as is" without warranty of any kind,
# either express or implied, including, but not limited to, the
# implied warranties of merchantability, fitness for a particular
# purpose, or non-infringement. This software could include
# technical inaccuracies or typographical errors. Changes are
# periodically made to the software; these changes will be
# incorporated in new editions of the software. DCLC may make
# improvements and/or changes in this software at any time
# without notice.
#
# Limitation Of Liability
#
# In no event will DCLC be liable for direct, indirect, special,
# incidental, economic, cover, or consequential damages arising
# out of the use of or inability to use this software even if
# advised of the possibility of such damages. Some states do not
# allow the exclusion or limitation of implied warranties or
# limitation of liability for incidental or consequential
# damages, so the above limitation or exclusion may not apply to
# you.
#
#
# If you have questions regarding this software,
# contact:
#
# Jim Fulton, jim@digicool.com
#
# (540) 371-6909
#
############################################################################
__rcs_id__
=
'$Id: DT_If.py,v 1.1 1997/08/27 18:55:42 jim Exp $'
__version__
=
'$Revision: 1.1 $'
[
11
:
-
2
]
from
DT_Util
import
*
class
If
:
blockContinuations
=
'else'
,
'elif'
name
=
'if'
elses
=
None
def
__init__
(
self
,
blocks
):
tname
,
args
,
section
=
blocks
[
0
]
args
=
parse_params
(
args
,
name
=
''
)
name
=
name_param
(
args
)
self
.
__name__
=
name
self
.
sections
=
[(
name
,
section
)]
if
blocks
[
-
1
][
0
]
==
'else'
:
tname
,
args
,
section
=
blocks
[
0
]
blocks
=
blocks
[:
-
1
]
args
=
parse_params
(
args
,
name
=
''
)
if
args
:
ename
=
name_param
(
args
)
if
ename
!=
name
:
raise
ParseError
,
'name in else does not match if'
self
.
elses
=
section
for
tname
,
args
,
section
in
blocks
[
1
:]:
if
tname
==
'else'
:
raise
ParseError
,
'more than one else tag for a single if tag'
name
=
name_param
(
args
)
self
.
sections
.
append
((
name
,
section
))
def
render
(
self
,
md
):
for
name
,
section
in
self
.
sections
:
try
:
v
=
md
[
name
]
except
:
v
=
None
if
v
:
return
section
(
None
,
md
)
if
self
.
elses
:
return
self
.
elses
(
None
,
md
)
return
''
__call__
=
render
class
Else
:
name
=
'else'
blockContinuations
=
()
def
__init__
(
self
,
blocks
):
tname
,
args
,
section
=
blocks
[
0
]
args
=
parse_params
(
args
,
name
=
''
)
name
=
name_param
(
args
)
self
.
__name__
=
name
self
.
section
=
section
def
render
(
self
,
md
):
try
:
v
=
md
[
self
.
__name__
]
except
:
v
=
None
if
not
v
:
return
self
.
section
(
None
,
md
)
return
''
__call__
=
render
##########################################################################
#
# $Log: DT_If.py,v $
# Revision 1.1 1997/08/27 18:55:42 jim
# initial
#
lib/python/DocumentTemplate/DT_In.py
0 → 100644
View file @
3e57bf37
This diff is collapsed.
Click to expand it.
lib/python/DocumentTemplate/DT_String.py
0 → 100644
View file @
3e57bf37
This diff is collapsed.
Click to expand it.
lib/python/DocumentTemplate/DT_UI.py
0 → 100644
View file @
3e57bf37
__doc__
=
'''Machinery to support through-the-web editing
$Id: DT_UI.py,v 1.1 1997/08/27 18:55:43 jim Exp $'''
############################################################################
# Copyright
#
# Copyright 1996 Digital Creations, L.C., 910 Princess Anne
# Street, Suite 300, Fredericksburg, Virginia 22401 U.S.A. All
# rights reserved. Copyright in this software is owned by DCLC,
# unless otherwise indicated. Permission to use, copy and
# distribute this software is hereby granted, provided that the
# above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear. Note that
# any product, process or technology described in this software
# may be the subject of other Intellectual Property rights
# reserved by Digital Creations, L.C. and are not licensed
# hereunder.
#
# Trademarks
#
# Digital Creations & DCLC, are trademarks of Digital Creations, L.C..
# All other trademarks are owned by their respective companies.
#
# No Warranty
#
# The software is provided "as is" without warranty of any kind,
# either express or implied, including, but not limited to, the
# implied warranties of merchantability, fitness for a particular
# purpose, or non-infringement. This software could include
# technical inaccuracies or typographical errors. Changes are
# periodically made to the software; these changes will be
# incorporated in new editions of the software. DCLC may make
# improvements and/or changes in this software at any time
# without notice.
#
# Limitation Of Liability
#
# In no event will DCLC be liable for direct, indirect, special,
# incidental, economic, cover, or consequential damages arising
# out of the use of or inability to use this software even if
# advised of the possibility of such damages. Some states do not
# allow the exclusion or limitation of implied warranties or
# limitation of liability for incidental or consequential
# damages, so the above limitation or exclusion may not apply to
# you.
#
#
# If you have questions regarding this software,
# contact:
#
# Jim Fulton, jim@digicool.com
#
# (540) 371-6909
#
############################################################################
__version__
=
'$Revision: 1.1 $'
[
11
:
-
2
]
from
DT_HTML
import
HTML
FactoryDefaultString
=
"Factory Default"
HTML
.
document_template_edit_header
=
'<h2>Document Template Editor</h2>'
HTML
.
document_template_form_header
=
''
HTML
.
document_template_edit_footer
=
(
"""<FONT SIZE="-1">
<I><A HREF="http://www.digicool.com/products/copyright.html">
© 1997 Digital Creations, L.L.C.</A></I></FONT>"""
)
HTML
.
document_template_edit_width
=
58
HTML
.
_manage_editForm
=
HTML
(
"""<HTML>
<HEAD>
<TITLE>HTML Template Editor</TITLE>
</HEAD>
<BODY bgcolor="#FFFFFF">
<!--#var document_template_edit_header-->
<em><!--#var PATH_INFO--></em><br>
<FORM name="editform" ACTION="<!--#var PARENT_URL-->/manage_edit" METHOD="POST">
<!--#var document_template_form_header-->
Document template source:
<center>
<br>
<TEXTAREA NAME="data:text" cols="<!--#var document_template_edit_width-->"
rows="20"><!--#var __str__--></TEXTAREA>
<br>
<INPUT NAME=SUBMIT TYPE="SUBMIT" VALUE="Change">
<INPUT NAME=SUBMIT TYPE="RESET" VALUE="Reset">
<INPUT NAME="dt_edit_name" TYPE="HIDDEN"
VALUE="<!--#var PATH_INFO-->">
<!--#if FactoryDefaultString-->
<INPUT NAME=SUBMIT TYPE="SUBMIT"
VALUE="<!--#var FactoryDefaultString-->">
<!--#/if FactoryDefaultString-->
<INPUT NAME=SUBMIT TYPE="SUBMIT" VALUE="Cancel">
<!--#if 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-->">
<!--#/if PARENT_URL-->
<!--#/if HTTP_REFERER-->
</center>
</FORM>
<!--#if vars-->
<p>The following variables may be used in this template:</p>
<table border>
<tr>
<th>Variables
<th>Description
<!--#in vars-->
<tr>
<td><!--#var sequence-key--></td>
<td><!--#var __str__--></td>
</tr>
<!--#/in vars-->
</table>
<!--#/if vars-->
<BR CLEAR="ALL">
<!--#var document_template_edit_footer-->
</BODY>
</HTML>"""
,
#"
__names__
=
{
'HTTP_REFERER'
:
'Referring URL'
,
'PARENT_URL'
:
"This page's parent"
,
'document_template_edit_header'
:
"(internal)"
,
'document_template_edit_footer'
:
"(internal)"
,
'__str__'
:
"(internal)"
,
'vars'
:
'list of DTML variables you can manipulate'
,
'descrip'
:
'desciption of DTML variables you can manipulate'
,
})
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>
</form></body></html>
<!--#else CANCEL_ACTION-->
<center>
<em><!--#var dt_edit_name--></em><br>has been changed.
</center>
<!--#/if CANCEL_ACTION-->"""
,
#"
__names__
=
{
'CANCEL_ACTION'
:
'???'
,
'PARENT_URL'
:
"This page's parent"
,
})
############################################################################
# $Log: DT_UI.py,v $
# Revision 1.1 1997/08/27 18:55:43 jim
# initial
#
lib/python/DocumentTemplate/DT_Util.py
0 → 100644
View file @
3e57bf37
'''$Id: DT_Util.py,v 1.1 1997/08/27 18:55:43 jim Exp $'''
############################################################################
# Copyright
#
# Copyright 1996 Digital Creations, L.C., 910 Princess Anne
# Street, Suite 300, Fredericksburg, Virginia 22401 U.S.A. All
# rights reserved. Copyright in this software is owned by DCLC,
# unless otherwise indicated. Permission to use, copy and
# distribute this software is hereby granted, provided that the
# above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear. Note that
# any product, process or technology described in this software
# may be the subject of other Intellectual Property rights
# reserved by Digital Creations, L.C. and are not licensed
# hereunder.
#
# Trademarks
#
# Digital Creations & DCLC, are trademarks of Digital Creations, L.C..
# All other trademarks are owned by their respective companies.
#
# No Warranty
#
# The software is provided "as is" without warranty of any kind,
# either express or implied, including, but not limited to, the
# implied warranties of merchantability, fitness for a particular
# purpose, or non-infringement. This software could include
# technical inaccuracies or typographical errors. Changes are
# periodically made to the software; these changes will be
# incorporated in new editions of the software. DCLC may make
# improvements and/or changes in this software at any time
# without notice.
#
# Limitation Of Liability
#
# In no event will DCLC be liable for direct, indirect, special,
# incidental, economic, cover, or consequential damages arising
# out of the use of or inability to use this software even if
# advised of the possibility of such damages. Some states do not
# allow the exclusion or limitation of implied warranties or
# limitation of liability for incidental or consequential
# damages, so the above limitation or exclusion may not apply to
# you.
#
#
# If you have questions regarding this software,
# contact:
#
# Jim Fulton, jim@digicool.com
#
# (540) 371-6909
#
############################################################################
__version__
=
'$Revision: 1.1 $'
[
11
:
-
2
]
import
sys
,
regex
,
string
,
types
,
math
,
os
from
string
import
rfind
,
strip
,
joinfields
,
atoi
,
lower
,
upper
,
capitalize
from
types
import
*
from
regsub
import
gsub
,
sub
,
split
from
__builtin__
import
*
ParseError
=
'Document Template Parse Error'
def
int_param
(
params
,
md
,
name
,
default
=
0
):
try
:
v
=
params
[
name
]
except
:
v
=
default
if
v
:
try
:
v
=
atoi
(
v
)
except
:
v
=
md
[
v
]
if
type
(
v
)
==
types
.
StringType
:
v
=
atoi
(
v
)
return
v
class
func_code
:
def
__init__
(
self
,
varnames
=
(
'self'
,
'REQUEST'
)):
self
.
co_varnames
=
varnames
self
.
co_argcount
=
len
(
varnames
)
def
name_param
(
params
):
if
params
.
has_key
(
''
):
if
params
.
has_key
(
'name'
):
raise
ParseError
,
'Name given twice'
return
params
[
''
]
elif
params
.
has_key
(
'name'
):
return
params
[
'name'
]
raise
ParseError
,
'No name given'
def
parse_params
(
text
,
result
=
None
,
unparmre
=
regex
.
compile
(
'
\
([
\
0- ]*
\
([^
\
0- =
\
"
]+
\
)
\
)'
),
parmre
=
regex
.
compile
(
'
\
([
\
0- ]*
\
([^
\
0- =
\
"
]+
\
)=
\
([^
\
0
- =
\
"
]+
\
)
\
)'
),
qparmre
=
regex
.
compile
(
'
\
([
\
0- ]*
\
([^
\
0- =
\
"
]+
\
)=
"
\
([^
"
]*
\
)
\
"
\
)
'
),
**parms):
"""Parse tag parameters
The format of tag parameters consists of 1 or more parameter
specifications separated by whitespace. Each specification
consists of an unnamed and unquoted value, a valueless name, or a
name-value pair. A name-value pair consists of a name and a
quoted or unquoted value separated by an '
=
'.
The input parameter, text, gives the text to be parsed. The
keyword parameters give valid parameter names and default values.
If a specification is not a name-value pair and it is not the
first specification that is not a name-value pair and it is a
valid parameter name, then it is treated as a name-value pair with
a value as given in the keyword argument. Otherwise, if it is not
a name-value pair, it is treated as an unnamed value.
The data are parsed into a dictionary mapping names to values.
Unnamed values are mapped from the name '""'. Only one value may
be given for a name and there may be only one unnamed value. """
result=result or {}
if parmre.match(text) >= 0:
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))
elif unparmre.match(text) >= 0:
name=unparmre.group(2)
l=len(unparmre.group(1))
if result.has_key(''):
if parms.has_key(name): result[name]=parms[name]
else: raise InvalidParameter, name
else:
result['']=name
return apply(parse_params,(text[l:],result),parms)
else:
if not text or not strip(text): return result
raise InvalidParameter, text
if not parms.has_key(name): raise ParseError, name
result[name]=value
text=strip(text[l:])
if text: return apply(parse_params,(text,result),parms)
else: return result
try: from cDocumentTemplate import InstanceDict, TemplateDict, render_blocks
except: from pDocumentTemplate import InstanceDict, TemplateDict, render_blocks
############################################################################
# $Log: DT_Util.py,v $
# Revision 1.1 1997/08/27 18:55:43 jim
# initial
#
lib/python/DocumentTemplate/DT_Var.py
0 → 100644
View file @
3e57bf37
#!/usr/local/bin/python
# $What$
__doc__
=
'''Variable insertion parameters
When inserting variables, parameters may be specified to
control how the data will be formatted. In HTML source, the
'fmt' parameter is used to specify a C-style or custom format
to be used when inserting an object. In EPFS source, the 'fmt'
parameter is only used for custom formats, a C-style format is
specified after the closing parenthesis.
Custom formats
A custom format is used when outputing user-defined
objects. The value of a custom format is a method name to
be invoked on the object being inserted. The method should
return an object that, when converted to a string, yields
the desired text. For example, the HTML source::
<!--#var date fmt=DayOfWeek-->
Inserts the result of calling the method 'DayOfWeek' of the
object bound to the variable 'date', with no arguments.
In addition to object methods, serveral additional custom
formats are available:
html-quote -- Convert characters that have special meaning
in HTML to HTML character entities.
url-quote -- Convert characters that have special meaning
in URLS to HTML character entities using decimal values.
multi-line -- Convert newlines and carriage-return and
newline combinations to break tags.
whole-dollars -- Show a numeric value with a dollar symbol.
dollar-with-commas -- Show a numeric value with a dollar
symbol and commas showing thousands, millions, and so on.
dollars-and-cents -- Show a numeric value with a dollar
symbol and two decimal places.
dollar-and-cents-with-commas -- Show a numeric value with a
dollar symbol and two decimal places
and commas showing thousands, millions, and so on.
Note that when using the EPFS source format, both a
C-style and a custom format may be provided. In this case,
the C-Style format is applied to the result of calling
the custom formatting method.
Null values
In some applications, and especially in database applications,
data variables may alternate between "good" and "null" or
"missing" values. A format that is used for good values may be
inappropriate for null values. For this reason, the 'null'
parameter can be used to specify text to be used for null
values. Null values are defined as values that:
- Cannot be formatted with the specified format, and
- Are either the special Python value 'None' or 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
following variable insertion might be used::
<!--#var cost fmt="$%.2d" null=
\
'
n/a
\
'
-->
String manipulation
The parameters 'lower' and 'upper' may be provided to cause the
case of the inserted text to be changed.
The parameter 'capitalize' may be provided to cause the first
character of the inserted value to be converted to upper case.
The parameter 'spacify' may be provided to cause underscores in
the inserted value to be converted to spaces.
'''
__rcs_id__
=
'$Id: DT_Var.py,v 1.1 1997/08/27 18:55:44 jim Exp $'
############################################################################
# Copyright
#
# Copyright 1996 Digital Creations, L.C., 910 Princess Anne
# Street, Suite 300, Fredericksburg, Virginia 22401 U.S.A. All
# rights reserved. Copyright in this software is owned by DCLC,
# unless otherwise indicated. Permission to use, copy and
# distribute this software is hereby granted, provided that the
# above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear. Note that
# any product, process or technology described in this software
# may be the subject of other Intellectual Property rights
# reserved by Digital Creations, L.C. and are not licensed
# hereunder.
#
# Trademarks
#
# Digital Creations & DCLC, are trademarks of Digital Creations, L.C..
# All other trademarks are owned by their respective companies.
#
# No Warranty
#
# The software is provided "as is" without warranty of any kind,
# either express or implied, including, but not limited to, the
# implied warranties of merchantability, fitness for a particular
# purpose, or non-infringement. This software could include
# technical inaccuracies or typographical errors. Changes are
# periodically made to the software; these changes will be
# incorporated in new editions of the software. DCLC may make
# improvements and/or changes in this software at any time
# without notice.
#
# Limitation Of Liability
#
# In no event will DCLC be liable for direct, indirect, special,
# incidental, economic, cover, or consequential damages arising
# out of the use of or inability to use this software even if
# advised of the possibility of such damages. Some states do not
# allow the exclusion or limitation of implied warranties or
# limitation of liability for incidental or consequential
# damages, so the above limitation or exclusion may not apply to
# you.
#
#
# If you have questions regarding this software,
# contact:
#
# Jim Fulton, jim@digicool.com
#
# (540) 371-6909
#
############################################################################
__version__
=
'$Revision: 1.1 $'
[
11
:
-
2
]
from
DT_Util
import
*
class
Var
:
name
=
'var'
def
__init__
(
self
,
args
,
fmt
=
''
):
args
=
parse_params
(
args
,
name
=
''
,
lower
=
1
,
upper
=
1
,
capitalize
=
1
,
spacify
=
1
,
null
=
''
,
fmt
=
's'
)
self
.
args
=
args
if
args
.
has_key
(
'name'
):
name
=
args
if
args
.
has_key
(
''
):
raise
ParseError
,
'Two named given in var'
elif
args
.
has_key
(
''
):
name
=
args
[
''
]
else
:
raise
ParseError
,
'No name given in var'
self
.
__name__
=
name
self
.
fmt
=
fmt
def
render
(
self
,
md
):
name
=
self
.
__name__
val
=
md
[
name
]
__traceback_info__
=
name
,
val
# handle special formats defined using fmt= first
if
self
.
args
.
has_key
(
'fmt'
):
try
:
# first try a parameterless method of val
val
=
getattr
(
val
,
self
.
args
[
'fmt'
])()
except
AttributeError
:
try
:
# failing that, try a special format
val
=
special_formats
[
self
.
args
[
'fmt'
]](
val
)
except
KeyError
:
try
:
# last chance - a format string itself?
val
=
self
.
args
[
'fmt'
]
%
val
except
:
pass
# next, look for upper, lower, etc
if
self
.
args
.
has_key
(
'upper'
):
val
=
upper
(
val
)
if
self
.
args
.
has_key
(
'lower'
):
val
=
lower
(
val
)
if
self
.
args
.
has_key
(
'capitalize'
):
val
=
capitalize
(
val
)
if
self
.
args
.
has_key
(
'spacify'
):
val
=
gsub
(
'_'
,
' '
,
val
)
# after this, if it's null and a null= option was given, return that
if
not
val
and
self
.
args
.
has_key
(
'null'
):
return
self
.
args
[
'null'
]
# finally, pump it through the actual string format...
return
(
'%'
+
self
.
fmt
)
%
val
__call__
=
render
def
html_quote
(
v
,
character_entities
=
(
(
regex
.
compile
(
'&'
),
'&'
),
(
regex
.
compile
(
"<"
),
'<'
),
(
regex
.
compile
(
">"
),
'>'
),
(
regex
.
compile
(
'"'
),
'"'
))):
#"
text
=
str
(
v
)
for
re
,
name
in
character_entities
:
text
=
gsub
(
re
,
name
,
text
)
return
text
def
url_quote
(
v
):
import
urllib
return
urllib
.
quote
(
str
(
v
))
def
multi_line
(
v
,
nl
=
regex
.
compile
(
'
\
r
?
\
n
'
)):
return
gsub
(
nl
,
'<br>
\
n
'
,
str
(
v
))
def
whole_dollars
(
v
):
try
:
return
"$%d"
%
v
except
:
return
''
def
dollars_and_cents
(
v
):
try
:
return
"$%.2f"
%
v
except
:
return
''
def
commatify
(
v
,
thou
=
regex
.
compile
(
"
\
([
0
-9]
\
)
\
([0-9][0-9][0-9]
\
([,.]
\
|$
\
)
\
)"
)):
v
=
str
(
v
)
while
thou
.
search
(
v
)
>=
0
:
v
=
sub
(
thou
,
"
\
\
1,
\
\
2"
,
v
)
return
v
def
whole_dollars_with_commas
(
v
):
try
:
v
=
"$%d"
%
v
except
:
v
=
''
return
commatify
(
v
)
def
dollars_and_cents_with_commas
(
v
):
try
:
v
=
"$%.2f"
%
v
except
:
v
=
''
return
commatify
(
v
)
special_formats
=
{
'html-quote'
:
html_quote
,
'url-quote'
:
url_quote
,
'multi-line'
:
multi_line
,
'whole-dollars'
:
whole_dollars
,
'dollars-and-cents'
:
dollars_and_cents
,
'dollars-with-commas'
:
whole_dollars_with_commas
,
'dollars-and-cents-with-commas'
:
dollars_and_cents_with_commas
,
}
############################################################################
# $Log: DT_Var.py,v $
# Revision 1.1 1997/08/27 18:55:44 jim
# initial
#
#
lib/python/DocumentTemplate/DTtest.py
0 → 100644
View file @
3e57bf37
This diff is collapsed.
Click to expand it.
lib/python/DocumentTemplate/DTtest_basicIn.py
0 → 100644
View file @
3e57bf37
from
DocumentTemplate
import
HTML
,
HTMLFile
,
String
,
File
def
d
(
**
kw
):
return
kw
class
D
:
def
__init__
(
self
,
**
kw
):
for
k
,
v
in
kw
.
items
():
self
.
__dict__
[
k
]
=
v
def
__repr__
(
self
):
return
"D(%s)"
%
`self.__dict__`
xxx
=
(
D
(
name
=
1
),
D
(
name
=
2
),
D
(
name
=
3
))
data
=
(
d
(
name
=
'jim'
,
age
=
39
),
d
(
name
=
'kak'
,
age
=
29
),
d
(
name
=
'will'
,
age
=
8
),
d
(
name
=
'andrew'
,
age
=
5
),
d
(
name
=
'chessie'
,
age
=
2
),
)
html
=
"""
<!--#in data mapping-->
<!--#var name-->, <!--#var age-->
<!--#else-->
<!--#in xxx -->
<!--#var name-->
<!--#/in-->
Sorry, no data
<!--#/in-->
"""
print
'='
*
74
print
HTML
(
html
)(
data
=
data
,
xxx
=
xxx
)
print
'='
*
74
print
HTML
(
html
)(
xxx
=
xxx
)
print
'='
*
74
s
=
"""
%(in data mapping)[
%(name)s, %(age)s
%(else)[
%(in xxx)[
%(name)s
%(in)]
Sorry, no data
%(in)]
"""
print
'='
*
74
print
String
(
s
)(
data
=
data
,
xxx
=
xxx
)
print
'='
*
74
print
String
(
s
)(
xxx
=
xxx
)
print
'='
*
74
lib/python/DocumentTemplate/DocumentTemplate.py
0 → 100644
View file @
3e57bf37
#!/usr/local/bin/python
# $What$
from
DT_Util
import
*
import
DT_Doc
,
DT_Var
,
DT_In
,
DT_If
__doc__
=
DT_Doc
.
__doc__
%
{
'In'
:
DT_In
.
__doc__
,
'If'
:
DT_If
.
__doc__
,
'Var'
:
DT_Var
.
__doc__
,
'id'
:
'$Id: DocumentTemplate.py,v 1.1 1997/08/27 18:55:45 jim Exp $'
}
############################################################################
# Copyright
#
# Copyright 1996 Digital Creations, L.C., 910 Princess Anne
# Street, Suite 300, Fredericksburg, Virginia 22401 U.S.A. All
# rights reserved. Copyright in this software is owned by DCLC,
# unless otherwise indicated. Permission to use, copy and
# distribute this software is hereby granted, provided that the
# above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear. Note that
# any product, process or technology described in this software
# may be the subject of other Intellectual Property rights
# reserved by Digital Creations, L.C. and are not licensed
# hereunder.
#
# Trademarks
#
# Digital Creations & DCLC, are trademarks of Digital Creations, L.C..
# All other trademarks are owned by their respective companies.
#
# No Warranty
#
# The software is provided "as is" without warranty of any kind,
# either express or implied, including, but not limited to, the
# implied warranties of merchantability, fitness for a particular
# purpose, or non-infringement. This software could include
# technical inaccuracies or typographical errors. Changes are
# periodically made to the software; these changes will be
# incorporated in new editions of the software. DCLC may make
# improvements and/or changes in this software at any time
# without notice.
#
# Limitation Of Liability
#
# In no event will DCLC be liable for direct, indirect, special,
# incidental, economic, cover, or consequential damages arising
# out of the use of or inability to use this software even if
# advised of the possibility of such damages. Some states do not
# allow the exclusion or limitation of implied warranties or
# limitation of liability for incidental or consequential
# damages, so the above limitation or exclusion may not apply to
# you.
#
#
# If you have questions regarding this software,
# contact:
#
# Jim Fulton, jim@digicool.com
#
# (540) 371-6909
#
############################################################################
__version__
=
'$Revision: 1.1 $'
[
11
:
-
2
]
ParseError
=
'Document Template Parse Error'
from
DT_String
import
String
,
File
from
DT_HTML
import
HTML
,
HTMLFile
import
DT_UI
# Install HTML editing
############################################################################
# $Log: DocumentTemplate.py,v $
# Revision 1.1 1997/08/27 18:55:45 jim
# initial
#
# Revision 1.13 1997/08/19 19:15:51 jim
# Escaped some quotes in strings to make python-mode happy.
# Moved Python implementation of things implemented in cDocumentTemplate
# to pDocumentTemplate.
#
# Revision 1.12 1997/08/06 14:06:16 jim
# Added id method.
#
# Revision 1.11 1997/08/05 21:44:59 jim
# Changed the way InstanceDicts call template attributes to avoid
# problem with instance attributes overriding kw arguments.
#
# Revision 1.10 1997/07/07 18:50:08 jim
# Many new features including:
#
# - Better tracebacks from In, Var, etc.,
# - shared globals so that you can have DT class-specific globals.
# - Now can say /if or endif, and in or endin.
#
# Revision 1.9 1997/04/30 15:20:28 jim
# Made editing window skinnier for now.
# Added a variable, document_template_edit_width to control editing
# width.
#
# Revision 1.8 1997/04/21 20:34:57 jim
# Removed code to quote %es, since we don't use Python's rendering
# machinery any more.
#
# Revision 1.7 1997/04/14 12:07:34 jim
# Changed user interface to get edit display name from
# PATH_INFO and to give precedence to HTTP_REFERER over PARENT_URL as a
# post-editing destination.
#
# Revision 1.6 1997/04/12 17:28:42 jim
# Prettified editing.
#
# Revision 1.5 1997/04/11 19:30:47 jim
# Took out Skip's print statements.
#
# Revision 1.4 1997/04/09 22:23:43 jim
# Major changes to use new rendering machinery.
#
# Validation is mainly disabled. It will be reenabled in a future
# revision.
#
# TemplateDict, InstanceDict and core rendering loop written in C.
#
# Revision 1.3 1997/04/08 02:07:36 jim
# Changed to use MultiMapping module, rather than cMultiMapping.
#
# Revision 1.2 1997/03/14 17:25:08 jim
# Fixed bug that prevented exception propigation from #if blocks.
#
# Added code to prevent uneeded saving of persistent DTs when the state
# changes during rendering.
#
# Revision 1.1 1997/03/08 14:50:14 jim
# I screwed up on hacking CVS and lost older revisions.
#
# Revision 1.19 1997/01/30 22:13:16 jim
# Fixed bug in __setstate__.
#
# Revision 1.18 1997/01/29 23:40:32 jim
# Integrated and debugged Skip's validation updates.
#
# Changed if and else to treat undefined objects as false.
#
# Changed editing logic for File classes so that edited objects are
# still file objects. This means you can subclass File (HTMLFile)
# classes without having to subclass String (HTML).
#
# Moved log section of comments to bottom of file.
#
# Revision 1.17 1996/12/02 14:41:23 jim
# Fixed bug in parsing if constructs.
#
# Revision 1.16 1996/10/24 17:17:43 jim
# Renamed edit and editForm to manage_edit and manage_editForm.
# (The name editForm is retained temporarily, until we make sure we
# don't use it anywhere, which we shouldn't be anyway.
#
# Added allow groups definitions for manage_edit and manage_editForm.
#
# Revision 1.15 1996/10/15 20:43:33 jim
# Fixed bug in edit confirmation that caused server to hang due to
# getting a post with no input fields.
#
# Revision 1.14 1996/10/02 18:43:42 jim
# Added several special formats.
#
# Revision 1.13 1996/09/18 21:37:03 jim
# Took out !@@$# print statement!
#
# Revision 1.12 1996/09/18 14:49:38 jim
# Added null option for var and allowed custom C format strings, such as
# $ %.2f.
#
# Revision 1.11 1996/09/17 21:45:25 jim
# Added user-defined formats.
# Fixed orphans to match definition.
# Made handling of batch parameters more robust so pages that specify
# parameters don't have to cast to int.
# Updated docs.
#
# Revision 1.10 1996/08/30 22:39:02 jfulton
# *** empty log message ***
#
# Revision 1.9 1996/08/30 17:12:13 jfulton
# *** empty log message ***
#
# Revision 1.8 1996/08/28 21:12:04 jfulton
# Many fixes
# and roman numerals.
#
# Revision 1.7 1996/08/20 23:24:50 jfulton
# Added default method.
# Made mapping arg in __call__ check for None.
# Updated tests.
#
# Revision 1.6 1996/08/16 19:10:59 jfulton
# Added batch sequence processing.
# Improved error propigation.
# Other things I've already forgotten.
#
# Revision 1.5 1996/08/07 20:04:18 jfulton
# Fixed bug in do_vars
#
# Revision 1.4 1996/08/06 19:31:57 jfulton
# Added new HTML syntax and updated docs.
#
# Revision 1.3 1996/08/05 11:31:00 jfulton
# Added HTML class that does HTML quoting.
# Added conditional insertion (if and else) and explicit iteration (in).
# Added testing and mutating methods.
# Fixed bug in __setstate__.
# Updated doc string.
#
# Revision 1.2 1996/07/30 21:01:08 jfulton
# Added logic to prevent instance dicts from divuldging names that start
# with _.
#
# Revision 1.1 1996/07/30 20:56:39 jfulton
# *** empty log message ***
#
#
lib/python/DocumentTemplate/Setup
View file @
3e57bf37
*shared*
cDocumentTemplate cDocumentTemplate.c -I../ExtensionClass
# install DT_Dict.py
# install DT_Doc.py
# install DT_HTML.py
# install DT_If.py
# install DT_In.py
# install DT_String.py
# install DT_UI.py
# install DT_Util.py
# install DT_Var.py
# install DT_render.py
# install DTtest.py
# install DTtest_basicIn.py
# install DocumentTemplate.py
# install Setup
# install __init__.py
# install cDocumentTemplate.c
# install pDocumentTemplate.py
lib/python/DocumentTemplate/__init__.py
0 → 100644
View file @
3e57bf37
#!/bin/env python
##############################################################################
#
# Copyright
#
# Copyright 1996 Digital Creations, L.C., 910 Princess Anne
# Street, Suite 300, Fredericksburg, Virginia 22401 U.S.A. All
# rights reserved. Copyright in this software is owned by DCLC,
# unless otherwise indicated. Permission to use, copy and
# distribute this software is hereby granted, provided that the
# above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear. Note that
# any product, process or technology described in this software
# may be the subject of other Intellectual Property rights
# reserved by Digital Creations, L.C. and are not licensed
# hereunder.
#
# Trademarks
#
# Digital Creations & DCLC, are trademarks of Digital Creations, L.C..
# All other trademarks are owned by their respective companies.
#
# No Warranty
#
# The software is provided "as is" without warranty of any kind,
# either express or implied, including, but not limited to, the
# implied warranties of merchantability, fitness for a particular
# purpose, or non-infringement. This software could include
# technical inaccuracies or typographical errors. Changes are
# periodically made to the software; these changes will be
# incorporated in new editions of the software. DCLC may make
# improvements and/or changes in this software at any time
# without notice.
#
# Limitation Of Liability
#
# In no event will DCLC be liable for direct, indirect, special,
# incidental, economic, cover, or consequential damages arising
# out of the use of or inability to use this software even if
# advised of the possibility of such damages. Some states do not
# allow the exclusion or limitation of implied warranties or
# limitation of liability for incidental or consequential
# damages, so the above limitation or exclusion may not apply to
# you.
#
#
# If you have questions regarding this software, contact:
#
# Digital Creations, L.C.
# 910 Princess Ann Street
# Fredericksburge, Virginia 22401
#
# info@digicool.com
#
# (540) 371-6909
#
##############################################################################
__doc__
=
'''Package wrapper for Document Template
This wrapper allows the (now many) document template modules to be
segregated in a separate package.
$Id: __init__.py,v 1.1 1997/08/27 18:55:46 jim Exp $'''
__version__
=
'$Revision: 1.1 $'
[
11
:
-
2
]
import
DocumentTemplate
__
.
String
=
DocumentTemplate
.
String
__
.
File
=
DocumentTemplate
.
File
__
.
HTML
=
DocumentTemplate
.
HTML
__
.
HTMLFile
=
DocumentTemplate
.
HTMLFile
##############################################################################
#
# $Log: __init__.py,v $
# Revision 1.1 1997/08/27 18:55:46 jim
# initial
#
#
lib/python/DocumentTemplate/cDocumentTemplate.c
0 → 100644
View file @
3e57bf37
This diff is collapsed.
Click to expand it.
lib/python/DocumentTemplate/pDocumentTemplate.py
0 → 100644
View file @
3e57bf37
#!/bin/env python
##############################################################################
#
# Copyright
#
# Copyright 1996 Digital Creations, L.C., 910 Princess Anne
# Street, Suite 300, Fredericksburg, Virginia 22401 U.S.A. All
# rights reserved. Copyright in this software is owned by DCLC,
# unless otherwise indicated. Permission to use, copy and
# distribute this software is hereby granted, provided that the
# above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear. Note that
# any product, process or technology described in this software
# may be the subject of other Intellectual Property rights
# reserved by Digital Creations, L.C. and are not licensed
# hereunder.
#
# Trademarks
#
# Digital Creations & DCLC, are trademarks of Digital Creations, L.C..
# All other trademarks are owned by their respective companies.
#
# No Warranty
#
# The software is provided "as is" without warranty of any kind,
# either express or implied, including, but not limited to, the
# implied warranties of merchantability, fitness for a particular
# purpose, or non-infringement. This software could include
# technical inaccuracies or typographical errors. Changes are
# periodically made to the software; these changes will be
# incorporated in new editions of the software. DCLC may make
# improvements and/or changes in this software at any time
# without notice.
#
# Limitation Of Liability
#
# In no event will DCLC be liable for direct, indirect, special,
# incidental, economic, cover, or consequential damages arising
# out of the use of or inability to use this software even if
# advised of the possibility of such damages. Some states do not
# allow the exclusion or limitation of implied warranties or
# limitation of liability for incidental or consequential
# damages, so the above limitation or exclusion may not apply to
# you.
#
#
# If you have questions regarding this software, contact:
#
# Digital Creations, L.C.
# 910 Princess Ann Street
# Fredericksburge, Virginia 22401
#
# info@digicool.com
#
# (540) 371-6909
#
##############################################################################
__doc__
=
'''Python implementations of document template some features
$Id: pDocumentTemplate.py,v 1.1 1997/08/27 18:55:47 jim Exp $'''
__version__
=
'$Revision: 1.1 $'
[
11
:
-
2
]
import
regex
,
string
StringType
=
type
(
''
)
isFunctionType
=
{}
for
name
in
[
'BuiltinFunctionType'
,
'BuiltinMethodType'
,
'ClassType'
,
'FunctionType'
,
'LambdaType'
,
'MethodType'
]:
try
:
isFunctionType
[
getattr
(
types
,
name
)]
=
1
except
:
pass
try
:
# Add function and method types from Extension Classes
import
ExtensionClass
isFunctionType
[
ExtensionClass
.
PythonMethodType
]
=
1
isFunctionType
[
ExtensionClass
.
ExtensionMethodType
]
=
1
except
:
pass
isFunctionType
=
isFunctionType
.
has_key
class
InstanceDict
:
def
__init__
(
self
,
o
,
namespace
):
self
.
self
=
o
self
.
cache
=
{}
self
.
namespace
=
namespace
def
has_key
(
self
,
key
):
return
hasattr
(
self
.
self
,
key
)
def
keys
(
self
):
return
self
.
self
.
__dict__
.
keys
()
def
__repr__
(
self
):
return
'InstanceDict(%s)'
%
str
(
self
.
self
)
def
__getitem__
(
self
,
key
):
# sys.stderr.write("Inst %s\n" % str((key,self)))
try
:
r
=
self
.
cache
[
key
]
except
:
if
key
[:
1
]
==
'_'
:
if
key
!=
'__str__'
:
raise
KeyError
,
key
# Don't divuldge private data
r
=
str
(
self
.
self
)
else
:
try
:
r
=
getattr
(
self
.
self
,
key
)
except
AttributeError
:
raise
KeyError
,
key
if
isFunctionType
(
type
(
r
)):
r
=
r
()
try
:
isDocTemp
=
r
.
isDocTemp
except
:
isDocTemp
=
0
if
isDocTemp
:
# There's no point in passing self, since we're
# already in the name space
#r=r(self.self,self.namespace)
r
=
r
(
None
,
self
.
namespace
)
# We won't cache results of rendering
else
:
self
.
cache
[
key
]
=
r
# sys.stderr.write("RI %s\n" % str((key,r)))
return
r
class
MultiMapping
:
def
__init__
(
self
):
self
.
dicts
=
[]
def
__getitem__
(
self
,
key
):
for
d
in
self
.
dicts
:
try
:
return
d
[
key
]
except
KeyError
,
AttributeError
:
pass
raise
KeyError
,
key
def
push
(
self
,
d
):
self
.
dicts
.
insert
(
0
,
d
)
def
pop
(
self
,
n
):
del
self
.
dicts
[:
n
]
def
keys
(
self
):
kz
=
[]
for
d
in
self
.
dicts
:
kz
=
kz
+
d
.
keys
()
return
kz
class
TemplateDict
:
def
__init__
(
self
):
m
=
self
.
dicts
=
MultiMapping
()
self
.
pop
=
m
.
pop
self
.
push
=
m
.
push
try
:
self
.
keys
=
m
.
keys
except
:
pass
# if names is None: self._names = {}
# else: self._names = names
# self._validator = validator
# self._do_validation=names or validator
def
setValidation
(
self
,
names
,
validator
):
r
=
self
.
_names
,
self
.
_validator
if
names
is
None
:
self
.
_names
=
{}
else
:
self
.
_names
=
names
self
.
_validator
=
validator
self
.
_do_validation
=
names
or
validator
return
r
def
__getitem__
(
self
,
key
):
# sys.stderr.write("MD %s\n" % str((key,self)))
# do_validation=self._do_validation
v
=
self
.
dicts
[
key
]
# validate before calling?
# if do_validation: self.validate(key, v)
# if isFunctionType(type(v)):
try
:
isDocTemp
=
v
.
isDocTemp
except
:
isDocTemp
=
None
if
isDocTemp
:
v
=
v
(
None
,
self
)
else
:
try
:
v
=
v
()
except
(
AttributeError
,
TypeError
):
pass
return
v
_namepat
=
regex
.
compile
(
'[^a-z0-9_]'
,
regex
.
casefold
)
def
validate
(
self
,
key
,
value
=
None
):
"Check key/value for access - raise KeyError if invalid access."
# names containing other than normal identifier chars are okay
# names in the programmer-provided list of names are okay
# key/value pairs the validator function approves are okay
if
(
self
.
_namepat
.
search
(
key
)
!=
-
1
or
self
.
_names
.
has_key
(
key
)
or
(
type
(
self
.
_validator
)
==
FunctionType
and
self
.
_validator
(
key
,
value
))):
return
# everything else is verboten...
raise
KeyError
,
key
def
render_blocks
(
self
,
md
):
rendered
=
[]
for
section
in
self
.
blocks
:
if
type
(
section
)
is
not
StringType
:
section
=
section
(
md
)
if
section
:
rendered
.
append
(
section
)
rendered
=
string
.
join
(
rendered
,
''
)
return
rendered
##############################################################################
#
# $Log: pDocumentTemplate.py,v $
# Revision 1.1 1997/08/27 18:55:47 jim
# initial
#
# Revision 1.1 1997/08/13 13:24:58 jim
# *** empty log message ***
#
#
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