Commit cbd3d223 authored by Jim Fulton's avatar Jim Fulton

untabified

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