Commit 7c473b10 authored by Jim Fulton's avatar Jim Fulton

Added expr to unless.

parent eea8b328
...@@ -117,8 +117,8 @@ __doc__='''Conditional insertion ...@@ -117,8 +117,8 @@ __doc__='''Conditional insertion
# (540) 371-6909 # (540) 371-6909
# #
############################################################################ ############################################################################
__rcs_id__='$Id: DT_If.py,v 1.7 1998/01/14 18:03:25 jim Exp $' __rcs_id__='$Id: DT_If.py,v 1.8 1998/01/14 18:23:42 jim Exp $'
__version__='$Revision: 1.7 $'[11:-2] __version__='$Revision: 1.8 $'[11:-2]
from DT_Util import * from DT_Util import *
import sys import sys
...@@ -166,10 +166,10 @@ class If: ...@@ -166,10 +166,10 @@ class If:
if ev is not name: if ev is not name:
raise KeyError, name, sys.exc_traceback raise KeyError, name, sys.exc_traceback
v=None v=None
cache[name]=v
else: else:
v=expr.eval(md) v=expr.eval(md)
cache[name]=v
if v: return section(None,md) if v: return section(None,md)
if self.elses: return self.elses(None, md) if self.elses: return self.elses(None, md)
...@@ -186,13 +186,16 @@ class Unless: ...@@ -186,13 +186,16 @@ class Unless:
def __init__(self, blocks): def __init__(self, blocks):
tname, args, section = blocks[0] tname, args, section = blocks[0]
args=parse_params(args, name='') args=parse_params(args, name='', expr='')
name=name_param(args) name,expr=name_param(args,'unless',1)
self.__name__ = name self.__name__ = name
self.section=section self.section=section
self.expr=expr
def render(self,md): def render(self,md):
name=self.__name__ name=self.__name__
expr=self.expr
if expr is None:
try: v=md[name] try: v=md[name]
except KeyError, ev: except KeyError, ev:
if ev is not name: raise KeyError, name, sys.exc_traceback if ev is not name: raise KeyError, name, sys.exc_traceback
...@@ -201,6 +204,9 @@ class Unless: ...@@ -201,6 +204,9 @@ class Unless:
md._push({name:v}) md._push({name:v})
try: return self.section(None,md) try: return self.section(None,md)
finally: md._pop(1) finally: md._pop(1)
else:
if not expr.eval(md): return self.section(None,md)
return '' return ''
__call__=render __call__=render
...@@ -213,6 +219,9 @@ class Else(Unless): ...@@ -213,6 +219,9 @@ class Else(Unless):
########################################################################## ##########################################################################
# #
# $Log: DT_If.py,v $ # $Log: DT_If.py,v $
# Revision 1.8 1998/01/14 18:23:42 jim
# Added expr to unless.
#
# Revision 1.7 1998/01/14 18:03:25 jim # Revision 1.7 1998/01/14 18:03:25 jim
# Added Unless tag as replacement for else tag. # Added Unless tag as replacement for else tag.
# #
......
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