Skip to content

Commit

Permalink
Added an 'only' flag attribute that can be used to prevent
Browse files Browse the repository at this point in the history
inclusion of enclosing namespaces.
  • Loading branch information
Jim Fulton committed Mar 4, 1999
1 parent c9f206f commit e4c49b5
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions DT_With.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,36 +105,45 @@
'''

__rcs_id__='$Id: DT_With.py,v 1.7 1998/12/04 20:15:28 jim Exp $'
__version__='$Revision: 1.7 $'[11:-2]
__rcs_id__='$Id: DT_With.py,v 1.8 1999/03/04 18:39:31 jim Exp $'
__version__='$Revision: 1.8 $'[11:-2]

from DT_Util import parse_params, name_param, InstanceDict, render_blocks, str

from DT_Util import TemplateDict
class With:
blockContinuations=()
name='with'
mapping=None

def __init__(self, blocks):
tname, args, section = blocks[0]
args=parse_params(args, name='', expr='', mapping=1)
args=parse_params(args, name='', expr='', mapping=1, only=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
if args.has_key('only') and args['only']: self.only=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 not self.mapping:
if type(v) is type(()) and len(v)==1: v=v[0]
md._push(InstanceDict(v,md))
v=InstanceDict(v,md)

if self.only:
_md=md
md=TemplateDict()
if hasattr(_md, 'AUTHENTICATED_USER'):
md.AUTHENTICATED_USER=_md.AUTHENTICATED_USER
if hasattr(_md, 'validate'):
md.validate=_md.validate

md._push(v)
try: return render_blocks(self.section, md)
finally: md._pop(1)

Expand Down

0 comments on commit e4c49b5

Please sign in to comment.