Yesterday I announced a patch on the Zope list that adds a <dtml-break> tag which allows you to break out of a <dtml-in> iteration like so: <dtml-in sequence> <dtml-if condition> <dtml-break> </dtml-if> <dtml-var sequence-item> </dtml-in> I'm just wondering what you folks on the zope-dev list and at DC think about adding something like this to the Zope core before my patch gets lost in the collector. Thanks, --jfarr "Perl is worse than Python because people wanted it worse." Larry Wall, 14 Oct 1998
----- Original Message ----- From: Jonothan Farr <jfarr@real.com>
Yesterday I announced a patch on the Zope list that adds a <dtml-break> tag which allows you to break out of a <dtml-in> iteration like so:
<dtml-in sequence> <dtml-if condition> <dtml-break> </dtml-if> <dtml-var sequence-item> </dtml-in>
I'm just wondering what you folks on the zope-dev list and at DC think about adding something like this to the Zope core before my patch gets lost in the collector.
I like it well enough, although with the proposed changes at http://www.zope.org/Members/4am/DTMLWiki/NamedDTMLInLoop I would prefer it to be a method of the iterator rather than a tag, so that you would write: <dtml-in sequence> <dtml-if condition><dtml-call sequence-break></dtml-if> <dtml-var sequence-item> </dtml-in> ...or in the case of nested loops: <dtml-in seq1 var=loop1> <dtml-in seq2 var=loop2> <dtml-if condition><dtml-call loop1/sequence-break></dtml-if> <dtml-var loop1/sequence-item>, <dtml-var loop2/sequence-item> </dtml-in> </dtml-in> Cheers, Evan @ digicool & 4-am
I like it well enough, although with the proposed changes at http://www.zope.org/Members/4am/DTMLWiki/NamedDTMLInLoop I would prefer it to be a method of the iterator rather than a tag, so that you would write:
OK, thanks. I wasn't aware of these proposed changes. I suppose it makes more sense then to just leave it as a downloadable patch for people that would like the functionality right away (and wouldn't mind updating their dtml code later). --jfarr
----- Original Message ----- From: Jonothan Farr <jfarr@real.com>
OK, thanks. I wasn't aware of these proposed changes. I suppose it makes more sense then to just leave it as a downloadable patch for people that would like the functionality right away (and wouldn't mind updating their dtml code later).
Actually, it shouldn't be too hard to make the patch behave this way from the start, so no code would need to be changed. Couldn't call it "break" without more work than it's worth, tho, since that's a reserved word in Python. Just add: def stop(self): raise BreakException, self to the sequence_variables class in DT_InSV.py, and change each "except BreakError: foo" clause into: except BreakError, bobj: if bobj == self.vars: foo else: raise and <dtml-call sequence-stop> should work. I think. Cheers, Evan @ digicool & 4-am
Actually, it doesn't look hard to name it sequence-break. Just name the function '_break'. Add a line to sequence_variables.__getitem__: if key=='sequence-break': return self._break() Although I think it needs to be: except BreakError, bobj: if bobj is self.vars: foo ...in order for it to know if the break is being called from the correct instance of in. --jfarr "Perl is worse than Python because people wanted it worse." Larry Wall, 14 Oct 1998
----- Original Message ----- From: Jonothan Farr <jfarr@real.com>
Actually, it doesn't look hard to name it sequence-break. Just name the function '_break'. Add a line to sequence_variables.__getitem__:
if key=='sequence-break': return self._break()
Or even inline it as "if key=='sequence-break': raise BreakError, self". Nifty.
except BreakError, bobj: if bobj is self.vars: foo
Looks good! Cheers, Evan @ digicool & 4-am
participants (2)
-
Evan Simpson -
Jonothan Farr