##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""The Let tag was contributed to Zope by and is copyright, 1999
Phillip J. Eby. Permission has been granted to release the Let tag
under the Zope Public License.
Let name=value...
The 'let' tag is used to bind variables to values within a block.
The text enclosed in the let tag is rendered using information
from the given variables or expressions.
For example::
\n%s\n\n' % v[0], 'let') def render(self, md): d = {} md._push(d) try: for name,expr in self.args: if isinstance(expr, StringType): d[name] = md[expr] else: d[name] = expr(md) return render_blocks(self.section, md) finally: md._pop(1) __call__ = render def parse_let_params(text, result=None, tag='let', parmre=re.compile('([\000- ]*([^\000- ="]+)=([^\000- ="]+))'), qparmre=re.compile('([\000- ]*([^\000- ="]+)="([^"]*)")'), **parms): result = result or [] mo = parmre.match(text) mo1 = qparmre.match(text) if mo is not None: name = mo.group(2) value = mo.group(3) l = len(mo.group(1)) elif mo1 is not None: name = mo1.group(2) value = '"%s"' % mo1.group(3) l = len(mo1.group(1)) else: if not text or not text.strip(): return result raise ParseError('invalid parameter: "%s"' % text, tag) result.append((name,value)) text = text[l:].strip() if text: return apply(parse_let_params, (text, result,tag), parms) else: return result