Commit cbd3d223 authored by Jim Fulton's avatar Jim Fulton

untabified

parent cad7d8e1
This diff is collapsed.
...@@ -117,8 +117,8 @@ __doc__='''Conditional insertion ...@@ -117,8 +117,8 @@ __doc__='''Conditional insertion
variable is not reevaluated. variable is not reevaluated.
''' '''
__rcs_id__='$Id: DT_If.py,v 1.13 1998/09/14 20:48:39 jim Exp $' __rcs_id__='$Id: DT_If.py,v 1.14 1998/09/14 22:03:31 jim Exp $'
__version__='$Revision: 1.13 $'[11:-2] __version__='$Revision: 1.14 $'[11:-2]
from DT_Util import ParseError, parse_params, name_param, str from DT_Util import ParseError, parse_params, name_param, str
...@@ -130,53 +130,52 @@ class If: ...@@ -130,53 +130,52 @@ class If:
def __init__(self, blocks): def __init__(self, blocks):
tname, args, section = blocks[0] tname, args, section = blocks[0]
args=parse_params(args, name='', expr='') args=parse_params(args, name='', expr='')
name,expr=name_param(args,'if',1) name,expr=name_param(args,'if',1)
self.__name__= name self.__name__= name
if expr is None: cond=name if expr is None: cond=name
else: cond=expr.eval else: cond=expr.eval
sections=[cond, section.blocks] sections=[cond, section.blocks]
if blocks[-1][0]=='else': if blocks[-1][0]=='else':
tname, args, section = blocks[-1] tname, args, section = blocks[-1]
del blocks[-1] del blocks[-1]
args=parse_params(args, name='') args=parse_params(args, name='')
if args: if args:
ename,expr=name_param(args,'else',1) ename,expr=name_param(args,'else',1)
if ename != name: if ename != name:
raise ParseError, ('name in else does not match if', 'in') raise ParseError, ('name in else does not match if', 'in')
elses=section.blocks elses=section.blocks
else: elses=None else: elses=None
for tname, args, section in blocks[1:]: for tname, args, section in blocks[1:]:
if tname=='else': if tname=='else':
raise ParseError, ( raise ParseError, (
'more than one else tag for a single if tag', 'in') 'more than one else tag for a single if tag', 'in')
args=parse_params(args, name='', expr='') args=parse_params(args, name='', expr='')
name,expr=name_param(args,'elif',1) name,expr=name_param(args,'elif',1)
if expr is None: cond=name if expr is None: cond=name
else: cond=expr.eval else: cond=expr.eval
sections.append(cond) sections.append(cond)
sections.append(section.blocks) sections.append(section.blocks)
if elses is not None: sections.append(elses) if elses is not None: sections.append(elses)
self.simple_form=tuple(sections) self.simple_form=tuple(sections)
class Unless: class Unless:
name='unless' name='unless'
blockContinuations=() blockContinuations=()
def __init__(self, blocks): def __init__(self, blocks):
tname, args, section = blocks[0] tname, args, section = blocks[0]
args=parse_params(args, name='', expr='') args=parse_params(args, name='', expr='')
name,expr=name_param(args,'unless',1) name,expr=name_param(args,'unless',1)
if expr is None: cond=name if expr is None: cond=name
else: cond=expr.eval else: cond=expr.eval
self.simple_form=(cond,None,section.blocks) self.simple_form=(cond,None,section.blocks)
class Else(Unless): class Else(Unless):
# The else tag is included for backward compatibility and is deprecated. # The else tag is included for backward compatibility and is deprecated.
name='else' name='else'
This diff is collapsed.
This diff is collapsed.
...@@ -65,8 +65,8 @@ ...@@ -65,8 +65,8 @@
<!--#/if--> <!--#/if-->
''' '''
__rcs_id__='$Id: DT_Raise.py,v 1.8 1998/09/14 20:48:40 jim Exp $' __rcs_id__='$Id: DT_Raise.py,v 1.9 1998/09/14 22:03:32 jim Exp $'
__version__='$Revision: 1.8 $'[11:-2] __version__='$Revision: 1.9 $'[11:-2]
from DT_Util import parse_params, name_param, render_blocks, str from DT_Util import parse_params, name_param, render_blocks, str
...@@ -77,25 +77,24 @@ class Raise: ...@@ -77,25 +77,24 @@ class Raise:
def __init__(self, blocks): def __init__(self, blocks):
tname, args, section = blocks[0] tname, args, section = blocks[0]
self.section=section.blocks self.section=section.blocks
args=parse_params(args, type='', expr='') args=parse_params(args, type='', expr='')
self.__name__, self.expr = name_param(args, 'raise', 1, attr='type') self.__name__, self.expr = name_param(args, 'raise', 1, attr='type')
def render(self,md): def render(self,md):
expr=self.expr expr=self.expr
if expr is None: if expr is None:
t=self.__name__ t=self.__name__
if t[-5:]=='Error' and __builtins__.has_key(t): if t[-5:]=='Error' and __builtins__.has_key(t):
t=__builtins__[t] t=__builtins__[t]
else: else:
try: t=expr.eval(md) try: t=expr.eval(md)
except: t='Invalid Error Type Expression' except: t='Invalid Error Type Expression'
try: v=render_blocks(self.section,md) try: v=render_blocks(self.section,md)
except: v='Invalid Error Value' except: v='Invalid Error Value'
raise t, v raise t, v
__call__=render __call__=render
This diff is collapsed.
...@@ -54,8 +54,8 @@ ...@@ -54,8 +54,8 @@
__doc__='''Machinery to support through-the-web editing __doc__='''Machinery to support through-the-web editing
$Id: DT_UI.py,v 1.6 1998/09/14 20:48:41 jim Exp $''' $Id: DT_UI.py,v 1.7 1998/09/14 22:03:33 jim Exp $'''
__version__='$Revision: 1.6 $'[11:-2] __version__='$Revision: 1.7 $'[11:-2]
from DT_HTML import HTML from DT_HTML import HTML
...@@ -97,12 +97,12 @@ HTML._manage_editForm = HTML( ...@@ -97,12 +97,12 @@ HTML._manage_editForm = HTML(
<!--#/if FactoryDefaultString--> <!--#/if FactoryDefaultString-->
<INPUT NAME=SUBMIT TYPE="SUBMIT" VALUE="Cancel"> <INPUT NAME=SUBMIT TYPE="SUBMIT" VALUE="Cancel">
<!--#if HTTP_REFERER--> <!--#if HTTP_REFERER-->
<INPUT NAME="CANCEL_ACTION" TYPE="HIDDEN" <INPUT NAME="CANCEL_ACTION" TYPE="HIDDEN"
VALUE="<!--#var HTTP_REFERER-->"> VALUE="<!--#var HTTP_REFERER-->">
<!--#else HTTP_REFERER--> <!--#else HTTP_REFERER-->
<!--#if PARENT_URL--> <!--#if PARENT_URL-->
<INPUT NAME="CANCEL_ACTION" TYPE="HIDDEN" <INPUT NAME="CANCEL_ACTION" TYPE="HIDDEN"
VALUE="<!--#var PARENT_URL-->"> VALUE="<!--#var PARENT_URL-->">
<!--#/if PARENT_URL--> <!--#/if PARENT_URL-->
<!--#/if HTTP_REFERER--> <!--#/if HTTP_REFERER-->
</center> </center>
...@@ -118,13 +118,13 @@ HTML.editConfirmation=HTML( ...@@ -118,13 +118,13 @@ HTML.editConfirmation=HTML(
"""<html><head><title>Change Successful</title></head><body> """<html><head><title>Change Successful</title></head><body>
<!--#if CANCEL_ACTION--> <!--#if CANCEL_ACTION-->
<form action="<!--#var CANCEL_ACTION-->" method="POST"> <form action="<!--#var CANCEL_ACTION-->" method="POST">
<center> <center>
<em><!--#var dt_edit_name--></em><br>has been changed.<br><br> <em><!--#var dt_edit_name--></em><br>has been changed.<br><br>
<input type=submit name="SUBMIT" value="OK"> <input type=submit name="SUBMIT" value="OK">
</center> </center>
</form></body></html> </form></body></html>
<!--#else CANCEL_ACTION--> <!--#else CANCEL_ACTION-->
<center> <center>
<em><!--#var dt_edit_name--></em><br>has been changed. <em><!--#var dt_edit_name--></em><br>has been changed.
</center> </center>
<!--#/if CANCEL_ACTION-->""") <!--#/if CANCEL_ACTION-->""")
...@@ -51,8 +51,8 @@ ...@@ -51,8 +51,8 @@
# (540) 371-6909 # (540) 371-6909
# #
############################################################################## ##############################################################################
'''$Id: DT_Util.py,v 1.46 1998/09/14 20:48:41 jim Exp $''' '''$Id: DT_Util.py,v 1.47 1998/09/14 22:03:33 jim Exp $'''
__version__='$Revision: 1.46 $'[11:-2] __version__='$Revision: 1.47 $'[11:-2]
import regex, string, math, os import regex, string, math, os
from string import strip, join, atoi, lower, split, find from string import strip, join, atoi, lower, split, find
...@@ -65,37 +65,37 @@ ValidationError='Unauthorized' ...@@ -65,37 +65,37 @@ ValidationError='Unauthorized'
def html_quote(v, name='(Unknown name)', md={}, def html_quote(v, name='(Unknown name)', md={},
character_entities=( character_entities=(
(('&'), '&amp;'), (('&'), '&amp;'),
(("<"), '&lt;' ), (("<"), '&lt;' ),
((">"), '&gt;' ), ((">"), '&gt;' ),
(('"'), '&quot;'))): #" (('"'), '&quot;'))): #"
text=str(v) 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) 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('')): def int_param(params,md,name,default=0, st=type('')):
try: v=params[name] try: v=params[name]
except: v=default except: v=default
if v: if v:
try: v=atoi(v) try: v=atoi(v)
except: except:
v=md[v] v=md[v]
if type(v) is st: v=atoi(v) if type(v) is st: v=atoi(v)
return v return v
def careful_getattr(md, inst, name): def careful_getattr(md, inst, name):
if name[:1]!='_': 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'): if hasattr(inst,'aq_acquire'):
return inst.aq_acquire(name, validate, md) return inst.aq_acquire(name, validate, md)
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 ValidationError, name raise ValidationError, name
...@@ -127,18 +127,18 @@ def careful_getitem(md, mapping, key): ...@@ -127,18 +127,18 @@ def careful_getitem(md, mapping, key):
def careful_getslice(md, seq, *indexes): def careful_getslice(md, seq, *indexes):
v=len(indexes) v=len(indexes)
if v==2: if v==2:
v=seq[indexes[0]:indexes[1]] v=seq[indexes[0]:indexes[1]]
elif v==1: elif v==1:
v=seq[indexes[0]:] v=seq[indexes[0]:]
else: v=seq[:] else: v=seq[:]
if type(seq) is type(''): return v # Short-circuit common case if type(seq) is type(''): return v # Short-circuit common case
validate=md.validate validate=md.validate
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 ValidationError, 'unauthorized access to slice member' raise ValidationError, 'unauthorized access to slice member'
return v return v
...@@ -149,7 +149,7 @@ except: from pDocumentTemplate import InstanceDict, TemplateDict, render_blocks ...@@ -149,7 +149,7 @@ except: from pDocumentTemplate import InstanceDict, TemplateDict, render_blocks
d=TemplateDict.__dict__ d=TemplateDict.__dict__
for name in ('None', 'abs', 'chr', 'divmod', 'float', 'hash', 'hex', 'int', 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[name]=__builtins__[name]
d['string']=string d['string']=string
d['math']=math d['math']=math
...@@ -158,7 +158,7 @@ d['whrandom']=whrandom ...@@ -158,7 +158,7 @@ d['whrandom']=whrandom
def test(self, *args): def test(self, *args):
l=len(args) l=len(args)
for i in range(1, l, 2): 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] if l%2: return args[-1]
...@@ -211,16 +211,16 @@ class Eval(VSEval.Eval): ...@@ -211,16 +211,16 @@ class Eval(VSEval.Eval):
def eval(self, mapping): def eval(self, mapping):
d={'_vars': mapping, '_': mapping} d={'_vars': mapping, '_': mapping}
code=self.code code=self.code
globals=self.globals globals=self.globals
for name in self.used: for name in self.used:
try: d[name]=mapping.getitem(name,0) try: d[name]=mapping.getitem(name,0)
except KeyError: except KeyError:
if name=='_getattr': if name=='_getattr':
d['__builtins__']=globals d['__builtins__']=globals
exec compiled_getattr in d 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): 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): ...@@ -228,10 +228,10 @@ def name_param(params,tag='',expr=0, attr='name', default_unnamed=1):
__traceback_info__=params, tag, expr, attr __traceback_info__=params, tag, expr, attr
#if expr and used('expr') and used('') and not used(params['']): #if expr and used('expr') and used('') and not used(params['']):
# # Fix up something like: <!--#in expr="whatever" mapping--> # # Fix up something like: <!--#in expr="whatever" mapping-->
# params[params['']]=default_unnamed # params[params['']]=default_unnamed
# del params[''] # del params['']
if used(''): if used(''):
v=params[''] v=params['']
...@@ -266,16 +266,16 @@ def name_param(params,tag='',expr=0, attr='name', default_unnamed=1): ...@@ -266,16 +266,16 @@ def name_param(params,tag='',expr=0, attr='name', default_unnamed=1):
return params[''] return params['']
elif used(attr): elif used(attr):
if expr: if expr:
if used('expr'): if used('expr'):
raise ParseError, ('%s and expr given' % attr, tag) raise ParseError, ('%s and expr given' % attr, tag)
return params[attr],None return params[attr],None
return params[attr] return params[attr]
elif expr and used('expr'): elif expr and used('expr'):
name=params['expr'] name=params['expr']
expr=Eval(name, expr_globals) expr=Eval(name, expr_globals)
return name, expr return name, expr
raise ParseError, ('No %s given' % attr, tag) raise ParseError, ('No %s given' % attr, tag)
Expr_doc=""" Expr_doc="""
...@@ -337,17 +337,17 @@ Python expression support ...@@ -337,17 +337,17 @@ Python expression support
ListType=type([]) ListType=type([])
def parse_params(text, def parse_params(text,
result=None, result=None,
tag='', tag='',
unparmre=regex.compile( unparmre=regex.compile(
'\([\0- ]*\([^\0- =\"]+\)\)'), '\([\0- ]*\([^\0- =\"]+\)\)'),
qunparmre=regex.compile( qunparmre=regex.compile(
'\([\0- ]*\("[^"]*"\)\)'), '\([\0- ]*\("[^"]*"\)\)'),
parmre=regex.compile( parmre=regex.compile(
'\([\0- ]*\([^\0- =\"]+\)=\([^\0- =\"]+\)\)'), '\([\0- ]*\([^\0- =\"]+\)=\([^\0- =\"]+\)\)'),
qparmre=regex.compile( qparmre=regex.compile(
'\([\0- ]*\([^\0- =\"]+\)="\([^"]*\)\"\)'), '\([\0- ]*\([^\0- =\"]+\)="\([^"]*\)\"\)'),
**parms): **parms):
"""Parse tag parameters """Parse tag parameters
...@@ -373,41 +373,41 @@ def parse_params(text, ...@@ -373,41 +373,41 @@ def parse_params(text,
result=result or {} result=result or {}
if parmre.match(text) >= 0: if parmre.match(text) >= 0:
name=lower(parmre.group(2)) name=lower(parmre.group(2))
value=parmre.group(3) value=parmre.group(3)
l=len(parmre.group(1)) l=len(parmre.group(1))
elif qparmre.match(text) >= 0: elif qparmre.match(text) >= 0:
name=lower(qparmre.group(2)) name=lower(qparmre.group(2))
value=qparmre.group(3) value=qparmre.group(3)
l=len(qparmre.group(1)) l=len(qparmre.group(1))
elif unparmre.match(text) >= 0: elif unparmre.match(text) >= 0:
name=unparmre.group(2) name=unparmre.group(2)
l=len(unparmre.group(1)) l=len(unparmre.group(1))
if result: if result:
if parms.has_key(name): if parms.has_key(name):
if parms[name] is None: raise ParseError, ( if parms[name] is None: raise ParseError, (
'Attribute %s requires a value' % name, tag) 'Attribute %s requires a value' % name, tag)
result[name]=parms[name] result[name]=parms[name]
else: raise ParseError, ( else: raise ParseError, (
'Invalid attribute name, "%s"' % name, tag) 'Invalid attribute name, "%s"' % name, tag)
else: else:
result['']=name result['']=name
return apply(parse_params,(text[l:],result),parms) return apply(parse_params,(text[l:],result),parms)
elif qunparmre.match(text) >= 0: elif qunparmre.match(text) >= 0:
name=qunparmre.group(2) name=qunparmre.group(2)
l=len(qunparmre.group(1)) l=len(qunparmre.group(1))
if result: raise ParseError, ( if result: raise ParseError, (
'Invalid attribute name, "%s"' % name, tag) 'Invalid attribute name, "%s"' % name, tag)
else: result['']=name else: result['']=name
return apply(parse_params,(text[l:],result),parms) return apply(parse_params,(text[l:],result),parms)
else: else:
if not text or not strip(text): return result if not text or not strip(text): return result
raise ParseError, ('invalid parameter: "%s"' % text, tag) raise ParseError, ('invalid parameter: "%s"' % text, tag)
if not parms.has_key(name): if not parms.has_key(name):
raise ParseError, ( raise ParseError, (
'Invalid attribute name, "%s"' % name, tag) 'Invalid attribute name, "%s"' % name, tag)
if result.has_key(name): if result.has_key(name):
p=parms[name] p=parms[name]
......
...@@ -100,8 +100,8 @@ __doc__='''Variable insertion parameters ...@@ -100,8 +100,8 @@ __doc__='''Variable insertion parameters
- Cannot be formatted with the specified format, and - Cannot be formatted with the specified format, and
- Are either the special Python value 'None' or - Are either the special Python value 'None' or
are false and yield an empty string when converted to are false and yield an empty string when converted to
a string. a string.
For example, when showing a monitary value retrieved from a For example, when showing a monitary value retrieved from a
database that is either a number or a missing value, the database that is either a number or a missing value, the
...@@ -164,8 +164,8 @@ Evaluating expressions without rendering results ...@@ -164,8 +164,8 @@ Evaluating expressions without rendering results
''' # ' ''' # '
__rcs_id__='$Id: DT_Var.py,v 1.22 1998/09/14 20:48:42 jim Exp $' __rcs_id__='$Id: DT_Var.py,v 1.23 1998/09/14 22:03:33 jim Exp $'
__version__='$Revision: 1.22 $'[11:-2] __version__='$Revision: 1.23 $'[11:-2]
from DT_Util import parse_params, name_param, html_quote, str from DT_Util import parse_params, name_param, html_quote, str
import regex, string, sys, regex import regex, string, sys, regex
...@@ -176,92 +176,92 @@ class Var: ...@@ -176,92 +176,92 @@ class Var:
expr=None expr=None
def __init__(self, args, fmt='s'): def __init__(self, args, fmt='s'):
args = parse_params(args, name='', lower=1, upper=1, expr='', args = parse_params(args, name='', lower=1, upper=1, expr='',
capitalize=1, spacify=1, null='', fmt='s', capitalize=1, spacify=1, null='', fmt='s',
size=0, etc='...', thousands_commas=1, size=0, etc='...', thousands_commas=1,
html_quote=1, url_quote=1, sql_quote=1, html_quote=1, url_quote=1, sql_quote=1,
newline_to_br=1) newline_to_br=1)
self.args=args self.args=args
self.modifiers=tuple( self.modifiers=tuple(
map(lambda t: t[1], map(lambda t: t[1],
filter(lambda m, args=args, used=args.has_key: filter(lambda m, args=args, used=args.has_key:
used(m[0]) and args[m[0]], used(m[0]) and args[m[0]],
modifiers))) modifiers)))
name, expr = name_param(args,'var',1) name, expr = name_param(args,'var',1)
self.__name__, self.expr = name, expr self.__name__, self.expr = name, expr
self.fmt = fmt self.fmt = fmt
if len(args)==1 and fmt=='s': if len(args)==1 and fmt=='s':
if expr is None: expr=name if expr is None: expr=name
else: expr=expr.eval else: expr=expr.eval
self.simple_form=expr, self.simple_form=expr,
def render(self, md): def render(self, md):
name=self.__name__ name=self.__name__
val=self.expr val=self.expr
if val is None: if val is None:
val = md[name] val = md[name]
else: else:
val=val.eval(md) val=val.eval(md)
args=self.args args=self.args
have_arg=args.has_key have_arg=args.has_key
__traceback_info__=name, val, args __traceback_info__=name, val, args
# handle special formats defined using fmt= first # handle special formats defined using fmt= first
if have_arg('fmt'): if have_arg('fmt'):
fmt=args['fmt'] fmt=args['fmt']
if have_arg('null') and not val and val != 0: if have_arg('null') and not val and val != 0:
try: try:
if hasattr(val, fmt): if hasattr(val, fmt):
val = getattr(val,fmt)() val = getattr(val,fmt)()
elif special_formats.has_key(fmt): elif special_formats.has_key(fmt):
val = special_formats[fmt](val, name, md) val = special_formats[fmt](val, name, md)
elif fmt=='': val='' elif fmt=='': val=''
else: val = fmt % val else: val = fmt % val
except: except:
t, v = sys.exc_type, sys.exc_value t, v = sys.exc_type, sys.exc_value
if val is None or not str(val): return args['null'] if val is None or not str(val): return args['null']
raise t, v raise t, v
else: else:
# We duplicate the code here to avoid exception handler # We duplicate the code here to avoid exception handler
# which tends to screw up stack or leak # which tends to screw up stack or leak
if hasattr(val, fmt): if hasattr(val, fmt):
val = getattr(val,fmt)() val = getattr(val,fmt)()
elif special_formats.has_key(fmt): elif special_formats.has_key(fmt):
val = special_formats[fmt](val, name, md) val = special_formats[fmt](val, name, md)
elif fmt=='': val='' elif fmt=='': val=''
else: val = fmt % val else: val = fmt % val
# finally, pump it through the actual string format... # finally, pump it through the actual string format...
fmt=self.fmt fmt=self.fmt
if fmt=='s': val=str(val) if fmt=='s': val=str(val)
else: val = ('%'+self.fmt) % (val,) else: val = ('%'+self.fmt) % (val,)
# next, look for upper, lower, etc # next, look for upper, lower, etc
for f in self.modifiers: val=f(val) for f in self.modifiers: val=f(val)
if have_arg('size'): if have_arg('size'):
size=args['size'] size=args['size']
try: size=atoi(size) try: size=atoi(size)
except: raise 'Document Error',( except: raise 'Document Error',(
'''a <code>size</code> attribute was used in a <code>var</code> '''a <code>size</code> attribute was used in a <code>var</code>
tag with a non-integer value.''') tag with a non-integer value.''')
if len(val) > size: if len(val) > size:
val=val[:size] val=val[:size]
l=rfind(val,' ') l=rfind(val,' ')
if l > size/2: if l > size/2:
val=val[:l+1] val=val[:l+1]
if have_arg('etc'): l=args['etc'] if have_arg('etc'): l=args['etc']
else: l='...' else: l='...'
val=val+l val=val+l
return val return val
__call__=render __call__=render
...@@ -270,11 +270,11 @@ class Call: ...@@ -270,11 +270,11 @@ class Call:
expr=None expr=None
def __init__(self, args): def __init__(self, args):
args = parse_params(args, name='', expr='') args = parse_params(args, name='', expr='')
name, expr = name_param(args,'call',1) name, expr = name_param(args,'call',1)
if expr is None: expr=name if expr is None: expr=name
else: expr=expr.eval else: expr=expr.eval
self.simple_form=expr,None self.simple_form=expr,None
def url_quote(v, name='(Unknown name)', md={}): def url_quote(v, name='(Unknown name)', md={}):
...@@ -363,7 +363,7 @@ def spacify(val): ...@@ -363,7 +363,7 @@ def spacify(val):
return val return val
modifiers=(html_quote, url_quote, newline_to_br, string.lower, string.upper, 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) modifiers=map(lambda f: (f.__name__, f), modifiers)
class Comment: class Comment:
...@@ -386,7 +386,6 @@ class Comment: ...@@ -386,7 +386,6 @@ class Comment:
def __init__(self, args, fmt=''): pass def __init__(self, args, fmt=''): pass
def render(self, md): def render(self, md):
return '' return ''
__call__=render __call__=render
...@@ -75,8 +75,8 @@ ...@@ -75,8 +75,8 @@
''' '''
__rcs_id__='$Id: DT_With.py,v 1.5 1998/09/14 20:48:42 jim Exp $' __rcs_id__='$Id: DT_With.py,v 1.6 1998/09/14 22:03:33 jim Exp $'
__version__='$Revision: 1.5 $'[11:-2] __version__='$Revision: 1.6 $'[11:-2]
from DT_Util import parse_params, name_param, InstanceDict, render_blocks, str from DT_Util import parse_params, name_param, InstanceDict, render_blocks, str
...@@ -86,26 +86,26 @@ class With: ...@@ -86,26 +86,26 @@ class With:
mapping=None mapping=None
def __init__(self, blocks): def __init__(self, blocks):
tname, args, section = blocks[0] tname, args, section = blocks[0]
args=parse_params(args, name='', expr='', mapping=1) args=parse_params(args, name='', expr='', mapping=1)
name,expr=name_param(args,'with',1) name,expr=name_param(args,'with',1)
if expr is None: expr=name if expr is None: expr=name
else: expr=expr.eval else: expr=expr.eval
self.__name__, self.expr = name, expr self.__name__, self.expr = name, expr
self.section=section.blocks self.section=section.blocks
if args.has_key('mapping') and args['mapping']: self.mapping=1 if args.has_key('mapping') and args['mapping']: self.mapping=1
def render(self, md): def render(self, md):
expr=self.expr expr=self.expr
if type(expr) is type(''): v=md[expr] if type(expr) is type(''): v=md[expr]
else: v=expr(md) else: v=expr(md)
if self.mapping: md._push(v) if self.mapping: md._push(v)
else: else:
if type(v) is type(()) and len(v)==1: v=v[0] if type(v) is type(()) and len(v)==1: v=v[0]
md._push(InstanceDict(v,md)) md._push(InstanceDict(v,md))
try: return render_blocks(self.section, md) try: return render_blocks(self.section, md)
finally: md._pop(1) finally: md._pop(1)
__call__=render __call__=render
This diff is collapsed.
...@@ -57,7 +57,7 @@ def d(**kw): return kw ...@@ -57,7 +57,7 @@ def d(**kw): return kw
class D: class D:
def __init__(self, **kw): 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__` def __repr__(self): return "D(%s)" % `self.__dict__`
......
...@@ -54,8 +54,8 @@ ...@@ -54,8 +54,8 @@
"""Very Safe Python Expressions """Very Safe Python Expressions
""" """
__rcs_id__='$Id: VSEval.py,v 1.18 1998/09/14 20:48:43 jim Exp $' __rcs_id__='$Id: VSEval.py,v 1.19 1998/09/14 22:03:34 jim Exp $'
__version__='$Revision: 1.18 $'[11:-2] __version__='$Revision: 1.19 $'[11:-2]
from string import translate from string import translate
import string import string
...@@ -73,12 +73,12 @@ def careful_mul(env, *factors): ...@@ -73,12 +73,12 @@ def careful_mul(env, *factors):
s=None s=None
r=1 r=1
for factor in factors: for factor in factors:
try: try:
l=len(factor) l=len(factor)
s=1 s=1
except: l=factor except: l=factor
if s and (l*r) > 1000: raise TypeError, 'Illegal sequence repeat' if s and (l*r) > 1000: raise TypeError, 'Illegal sequence repeat'
r=r*factor r=r*factor
return r return r
...@@ -109,68 +109,68 @@ class Eval: ...@@ -109,68 +109,68 @@ class Eval:
""" """
def __init__(self, expr, globals=default_globals): 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 global gparse
if gparse is None: import gparse if gparse is None: import gparse
self.__name__=expr self.__name__=expr
expr=translate(expr,nltosp) expr=translate(expr,nltosp)
self.expr=expr self.expr=expr
self.globals=globals self.globals=globals
co=compile(expr,'<string>','eval') co=compile(expr,'<string>','eval')
names=list(co.co_names) names=list(co.co_names)
# Check for valid names, disallowing names that begin with '_' or # Check for valid names, disallowing names that begin with '_' or
# 'manage'. This is a DC specific rule and probably needs to be # 'manage'. This is a DC specific rule and probably needs to be
# made customizable! # made customizable!
for name in names: for name in names:
if name[:1]=='_' and name not in ('_', '_vars', '_getattr'): if name[:1]=='_' and name not in ('_', '_vars', '_getattr'):
raise TypeError, 'illegal name used in expression' raise TypeError, 'illegal name used in expression'
used={} used={}
i=0 i=0
code=co.co_code code=co.co_code
l=len(code) l=len(code)
LOAD_NAME=101 LOAD_NAME=101
HAVE_ARGUMENT=90 HAVE_ARGUMENT=90
def HAS_ARG(op): ((op) >= HAVE_ARGUMENT) def HAS_ARG(op): ((op) >= HAVE_ARGUMENT)
while(i < l): while(i < l):
c=ord(code[i]) c=ord(code[i])
if c==LOAD_NAME: if c==LOAD_NAME:
name=names[ord(code[i+1])+256*ord(code[i+2])] name=names[ord(code[i+1])+256*ord(code[i+2])]
used[name]=1 used[name]=1
i=i+3 i=i+3
elif c >= HAVE_ARGUMENT: i=i+3 elif c >= HAVE_ARGUMENT: i=i+3
else: i=i+1 else: i=i+1
self.code=gparse.compile(expr,'<string>','eval') self.code=gparse.compile(expr,'<string>','eval')
self.used=tuple(used.keys()) self.used=tuple(used.keys())
def eval(self, mapping): def eval(self, mapping):
d={'_vars': mapping} d={'_vars': mapping}
code=self.code code=self.code
globals=self.globals globals=self.globals
for name in self.used: for name in self.used:
try: d[name]=mapping.getitem(name,0) try: d[name]=mapping.getitem(name,0)
except KeyError: except KeyError:
if name=='_getattr': if name=='_getattr':
d['__builtins__']=globals d['__builtins__']=globals
exec compiled_getattr in d exec compiled_getattr in d
return eval(code,globals,d) return eval(code,globals,d)
def __call__(self, **kw): def __call__(self, **kw):
return eval(self.code, self.globals, kw) return eval(self.code, self.globals, kw)
compiled_getattr=compile( compiled_getattr=compile(
'def _getattr(o,n): return __guarded_getattr__(_vars,o,n)', 'def _getattr(o,n): return __guarded_getattr__(_vars,o,n)',
......
DocumentTemplate releases 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 - There is a new user's guide in HTML and PDF formats with
table of contents and index. 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 - There is a new open-source copyright.
eliminated.
- 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: - Added short-hand expr usage:
...@@ -20,6 +25,11 @@ DocumentTemplate releases ...@@ -20,6 +25,11 @@ DocumentTemplate releases
<!--#some_tag expr="foo.bar"--> <!--#some_tag expr="foo.bar"-->
Bugs fixed
- Several occurrences of 'from some_module import *' have been
eliminated.
- Fixed bugs in error reporting. - Fixed bugs in error reporting.
- Handle valueless attributes a bit better. - Handle valueless attributes a bit better.
...@@ -120,5 +130,5 @@ DocumentTemplate releases ...@@ -120,5 +130,5 @@ DocumentTemplate releases
- New 'in' tag variables for getting information about the start and - New 'in' tag variables for getting information about the start and
end indexes of the current batch. end indexes of the current batch.
"Download DocumentTemplate 2.1":DocumentTemplate-2.1.tar.gz. "Download DocumentTemplate 2.2":DocumentTemplate-2.2.tar.gz.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment