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
4f997c7e
Commit
4f997c7e
authored
Sep 02, 1997
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
*** empty log message ***
parent
ad6ca610
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
216 additions
and
213 deletions
+216
-213
lib/python/DocumentTemplate/pDocumentTemplate.py
lib/python/DocumentTemplate/pDocumentTemplate.py
+216
-213
No files found.
lib/python/DocumentTemplate/pDocumentTemplate.py
View file @
4f997c7e
#!/bin/env python
#!/bin/env python
##############################################################################
##############################################################################
#
#
# Copyright
# Copyright
#
#
# Copyright 1996 Digital Creations, L.C., 910 Princess Anne
# Copyright 1996 Digital Creations, L.C., 910 Princess Anne
# Street, Suite 300, Fredericksburg, Virginia 22401 U.S.A. All
# Street, Suite 300, Fredericksburg, Virginia 22401 U.S.A. All
# rights reserved. Copyright in this software is owned by DCLC,
# rights reserved. Copyright in this software is owned by DCLC,
# unless otherwise indicated. Permission to use, copy and
# unless otherwise indicated. Permission to use, copy and
# distribute this software is hereby granted, provided that the
# distribute this software is hereby granted, provided that the
# above copyright notice appear in all copies and that both that
# above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear. Note that
# copyright notice and this permission notice appear. Note that
# any product, process or technology described in this software
# any product, process or technology described in this software
# may be the subject of other Intellectual Property rights
# may be the subject of other Intellectual Property rights
# reserved by Digital Creations, L.C. and are not licensed
# reserved by Digital Creations, L.C. and are not licensed
# hereunder.
# hereunder.
#
#
# Trademarks
# Trademarks
#
#
# Digital Creations & DCLC, are trademarks of Digital Creations, L.C..
# Digital Creations & DCLC, are trademarks of Digital Creations, L.C..
# All other trademarks are owned by their respective companies.
# All other trademarks are owned by their respective companies.
#
#
# No Warranty
# No Warranty
#
#
# The software is provided "as is" without warranty of any kind,
# The software is provided "as is" without warranty of any kind,
# either express or implied, including, but not limited to, the
# either express or implied, including, but not limited to, the
# implied warranties of merchantability, fitness for a particular
# implied warranties of merchantability, fitness for a particular
# purpose, or non-infringement. This software could include
# purpose, or non-infringement. This software could include
# technical inaccuracies or typographical errors. Changes are
# technical inaccuracies or typographical errors. Changes are
# periodically made to the software; these changes will be
# periodically made to the software; these changes will be
# incorporated in new editions of the software. DCLC may make
# incorporated in new editions of the software. DCLC may make
# improvements and/or changes in this software at any time
# improvements and/or changes in this software at any time
# without notice.
# without notice.
#
#
# Limitation Of Liability
# Limitation Of Liability
#
#
# In no event will DCLC be liable for direct, indirect, special,
# In no event will DCLC be liable for direct, indirect, special,
# incidental, economic, cover, or consequential damages arising
# incidental, economic, cover, or consequential damages arising
# out of the use of or inability to use this software even if
# out of the use of or inability to use this software even if
# advised of the possibility of such damages. Some states do not
# advised of the possibility of such damages. Some states do not
# allow the exclusion or limitation of implied warranties or
# allow the exclusion or limitation of implied warranties or
# limitation of liability for incidental or consequential
# limitation of liability for incidental or consequential
# damages, so the above limitation or exclusion may not apply to
# damages, so the above limitation or exclusion may not apply to
# you.
# you.
#
#
#
#
# If you have questions regarding this software, contact:
# If you have questions regarding this software, contact:
#
#
# Digital Creations, L.C.
# Digital Creations, L.C.
# 910 Princess Ann Street
# 910 Princess Ann Street
# Fredericksburge, Virginia 22401
# Fredericksburge, Virginia 22401
#
#
# info@digicool.com
# info@digicool.com
#
#
# (540) 371-6909
# (540) 371-6909
#
#
##############################################################################
##############################################################################
__doc__
=
'''Python implementations of document template some features
__doc__
=
'''Python implementations of document template some features
$Id: pDocumentTemplate.py,v 1.
1 1997/08/27 18:55:47 jim Exp $'''
$Id: pDocumentTemplate.py,v 1.
2 1997/09/02 19:02:51 jim Exp $'''
__version__
=
'$Revision: 1.
1 $'
[
11
:
-
2
]
__version__
=
'$Revision: 1.
2 $'
[
11
:
-
2
]
import
regex
,
string
import
regex
,
string
StringType
=
type
(
''
)
StringType
=
type
(
''
)
isFunctionType
=
{}
isFunctionType
=
{}
for
name
in
[
'BuiltinFunctionType'
,
'BuiltinMethodType'
,
'ClassType'
,
for
name
in
[
'BuiltinFunctionType'
,
'BuiltinMethodType'
,
'ClassType'
,
'FunctionType'
,
'LambdaType'
,
'MethodType'
]:
'FunctionType'
,
'LambdaType'
,
'MethodType'
]:
try
:
isFunctionType
[
getattr
(
types
,
name
)]
=
1
try
:
isFunctionType
[
getattr
(
types
,
name
)]
=
1
except
:
pass
except
:
pass
try
:
# Add function and method types from Extension Classes
try
:
# Add function and method types from Extension Classes
import
ExtensionClass
import
ExtensionClass
isFunctionType
[
ExtensionClass
.
PythonMethodType
]
=
1
isFunctionType
[
ExtensionClass
.
PythonMethodType
]
=
1
isFunctionType
[
ExtensionClass
.
ExtensionMethodType
]
=
1
isFunctionType
[
ExtensionClass
.
ExtensionMethodType
]
=
1
except
:
pass
except
:
pass
isFunctionType
=
isFunctionType
.
has_key
isFunctionType
=
isFunctionType
.
has_key
class
InstanceDict
:
class
InstanceDict
:
def
__init__
(
self
,
o
,
namespace
):
def
__init__
(
self
,
o
,
namespace
):
self
.
self
=
o
self
.
self
=
o
self
.
cache
=
{}
self
.
cache
=
{}
self
.
namespace
=
namespace
self
.
namespace
=
namespace
def
has_key
(
self
,
key
):
def
has_key
(
self
,
key
):
return
hasattr
(
self
.
self
,
key
)
return
hasattr
(
self
.
self
,
key
)
def
keys
(
self
):
def
keys
(
self
):
return
self
.
self
.
__dict__
.
keys
()
return
self
.
self
.
__dict__
.
keys
()
def
__repr__
(
self
):
return
'InstanceDict(%s)'
%
str
(
self
.
self
)
def
__repr__
(
self
):
return
'InstanceDict(%s)'
%
str
(
self
.
self
)
def
__getitem__
(
self
,
key
):
def
__getitem__
(
self
,
key
):
# sys.stderr.write("Inst %s\n" % str((key,self)))
# sys.stderr.write("Inst %s\n" % str((key,self)))
try
:
try
:
r
=
self
.
cache
[
key
]
r
=
self
.
cache
[
key
]
except
:
except
:
if
key
[:
1
]
==
'_'
:
if
key
[:
1
]
==
'_'
:
if
key
!=
'__str__'
:
if
key
!=
'__str__'
:
raise
KeyError
,
key
# Don't divuldge private data
raise
KeyError
,
key
# Don't divuldge private data
r
=
str
(
self
.
self
)
r
=
str
(
self
.
self
)
else
:
else
:
try
:
r
=
getattr
(
self
.
self
,
key
)
try
:
r
=
getattr
(
self
.
self
,
key
)
except
AttributeError
:
raise
KeyError
,
key
except
AttributeError
:
raise
KeyError
,
key
if
isFunctionType
(
type
(
r
)):
if
isFunctionType
(
type
(
r
)):
r
=
r
()
r
=
r
()
try
:
isDocTemp
=
r
.
isDocTemp
try
:
isDocTemp
=
r
.
isDocTemp
except
:
isDocTemp
=
0
except
:
isDocTemp
=
0
if
isDocTemp
:
if
isDocTemp
:
# There's no point in passing self, since we're
# There's no point in passing self, since we're
# already in the name space
# already in the name space
#r=r(self.self,self.namespace)
#r=r(self.self,self.namespace)
r
=
r
(
None
,
self
.
namespace
)
r
=
r
(
None
,
self
.
namespace
)
# We won't cache results of rendering
# We won't cache results of rendering
else
:
else
:
self
.
cache
[
key
]
=
r
self
.
cache
[
key
]
=
r
# sys.stderr.write("RI %s\n" % str((key,r)))
# sys.stderr.write("RI %s\n" % str((key,r)))
return
r
return
r
class
MultiMapping
:
class
MultiMapping
:
def
__init__
(
self
):
self
.
dicts
=
[]
def
__init__
(
self
):
self
.
dicts
=
[]
def
__getitem__
(
self
,
key
):
def
__getitem__
(
self
,
key
):
for
d
in
self
.
dicts
:
for
d
in
self
.
dicts
:
try
:
return
d
[
key
]
try
:
return
d
[
key
]
except
KeyError
,
AttributeError
:
pass
except
KeyError
,
AttributeError
:
pass
raise
KeyError
,
key
raise
KeyError
,
key
def
push
(
self
,
d
):
self
.
dicts
.
insert
(
0
,
d
)
def
push
(
self
,
d
):
self
.
dicts
.
insert
(
0
,
d
)
def
pop
(
self
,
n
):
del
self
.
dicts
[:
n
]
def
pop
(
self
,
n
):
del
self
.
dicts
[:
n
]
def
keys
(
self
):
def
keys
(
self
):
kz
=
[]
kz
=
[]
for
d
in
self
.
dicts
:
for
d
in
self
.
dicts
:
kz
=
kz
+
d
.
keys
()
kz
=
kz
+
d
.
keys
()
return
kz
return
kz
class
TemplateDict
:
class
TemplateDict
:
def
__init__
(
self
):
def
__init__
(
self
):
m
=
self
.
dicts
=
MultiMapping
()
m
=
self
.
dicts
=
MultiMapping
()
self
.
pop
=
m
.
pop
self
.
pop
=
m
.
pop
self
.
push
=
m
.
push
self
.
push
=
m
.
push
try
:
self
.
keys
=
m
.
keys
try
:
self
.
keys
=
m
.
keys
except
:
pass
except
:
pass
# if names is None: self._names = {}
# if names is None: self._names = {}
# else: self._names = names
# else: self._names = names
# self._validator = validator
# self._validator = validator
# self._do_validation=names or validator
# self._do_validation=names or validator
def
setValidation
(
self
,
names
,
validator
):
def
setValidation
(
self
,
names
,
validator
):
r
=
self
.
_names
,
self
.
_validator
r
=
self
.
_names
,
self
.
_validator
if
names
is
None
:
self
.
_names
=
{}
if
names
is
None
:
self
.
_names
=
{}
else
:
self
.
_names
=
names
else
:
self
.
_names
=
names
self
.
_validator
=
validator
self
.
_validator
=
validator
self
.
_do_validation
=
names
or
validator
self
.
_do_validation
=
names
or
validator
return
r
return
r
def
__getitem__
(
self
,
key
):
def
__getitem__
(
self
,
key
):
# sys.stderr.write("MD %s\n" % str((key,self)))
# sys.stderr.write("MD %s\n" % str((key,self)))
# do_validation=self._do_validation
# do_validation=self._do_validation
v
=
self
.
dicts
[
key
]
v
=
self
.
dicts
[
key
]
# validate before calling?
# validate before calling?
# if do_validation: self.validate(key, v)
# if do_validation: self.validate(key, v)
# if isFunctionType(type(v)):
# if isFunctionType(type(v)):
try
:
isDocTemp
=
v
.
isDocTemp
try
:
isDocTemp
=
v
.
isDocTemp
except
:
isDocTemp
=
None
except
:
isDocTemp
=
None
if
isDocTemp
:
v
=
v
(
None
,
self
)
if
isDocTemp
:
v
=
v
(
None
,
self
)
else
:
else
:
try
:
v
=
v
()
try
:
v
=
v
()
except
(
AttributeError
,
TypeError
):
pass
except
(
AttributeError
,
TypeError
):
pass
return
v
return
v
_namepat
=
regex
.
compile
(
'[^a-z0-9_]'
,
regex
.
casefold
)
_namepat
=
regex
.
compile
(
'[^a-z0-9_]'
,
regex
.
casefold
)
def
validate
(
self
,
key
,
value
=
None
):
def
validate
(
self
,
key
,
value
=
None
):
"Check key/value for access - raise KeyError if invalid access."
"Check key/value for access - raise KeyError if invalid access."
# names containing other than normal identifier chars are okay
# names containing other than normal identifier chars are okay
# names in the programmer-provided list of names are okay
# names in the programmer-provided list of names are okay
# key/value pairs the validator function approves are okay
# key/value pairs the validator function approves are okay
if
(
self
.
_namepat
.
search
(
key
)
!=
-
1
or
if
(
self
.
_namepat
.
search
(
key
)
!=
-
1
or
self
.
_names
.
has_key
(
key
)
or
self
.
_names
.
has_key
(
key
)
or
(
type
(
self
.
_validator
)
==
FunctionType
and
(
type
(
self
.
_validator
)
==
FunctionType
and
self
.
_validator
(
key
,
value
))):
return
self
.
_validator
(
key
,
value
))):
return
# everything else is verboten...
# everything else is verboten...
raise
KeyError
,
key
raise
KeyError
,
key
def
render_blocks
(
self
,
md
):
def
render_blocks
(
self
,
md
):
rendered
=
[]
rendered
=
[]
for
section
in
self
.
blocks
:
for
section
in
self
.
blocks
:
if
type
(
section
)
is
not
StringType
:
if
type
(
section
)
is
not
StringType
:
section
=
section
(
md
)
section
=
section
(
md
)
if
section
:
rendered
.
append
(
section
)
if
section
:
rendered
.
append
(
section
)
rendered
=
string
.
join
(
rendered
,
''
)
rendered
=
string
.
join
(
rendered
,
''
)
return
rendered
return
rendered
##############################################################################
##############################################################################
#
#
# $Log: pDocumentTemplate.py,v $
# $Log: pDocumentTemplate.py,v $
# Revision 1.2 1997/09/02 19:02:51 jim
# *** empty log message ***
#
# Revision 1.1 1997/08/27 18:55:47 jim
# Revision 1.1 1997/08/27 18:55:47 jim
# initial
# initial
#
#
# Revision 1.1 1997/08/13 13:24:58 jim
# Revision 1.1 1997/08/13 13:24:58 jim
# *** empty log message ***
# *** 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