1
2
3
4
5
6
7
8
9
10
11
12
13
14 ''' The Let tag was contributed to Zope by and is copyright, 1999
15 Phillip J. Eby. Permission has been granted to release the Let tag
16 under the Zope Public License.
17
18
19 Let name=value...
20
21 The 'let' tag is used to bind variables to values within a block.
22
23 The text enclosed in the let tag is rendered using information
24 from the given variables or expressions.
25
26 For example::
27
28 <!--#let foofunc="foo()" my_bar=bar-->
29 foo() = <!--#var foofunc-->,
30 bar = <!--#var my_bar-->
31 <!--#/let-->
32
33 Notice that both 'name' and 'expr' style attributes may be used to
34 specify data. 'name' style attributes (e.g. my_bar=bar) will be
35 rendered as they are for var/with/in/etc. Quoted attributes will
36 be treated as Python expressions.
37
38 Variables are processed in sequence, so later assignments can
39 reference and/or overwrite the results of previous assignments,
40 as desired.
41 '''
42
43 from DT_Util import render_blocks, Eval, ParseError
44 from DT_Util import str
45 import re
46
47
49 blockContinuations=()
50 name='let'
51
53 tname, args, section = blocks[0]
54 self.__name__ = args
55 self.section = section.blocks
56 self.args = args = parse_let_params(args)
57
58 for i in range(len(args)):
59 name,expr = args[i]
60 if expr[:1]=='"' and expr[-1:]=='"' and len(expr) > 1:
61
62 expr=expr[1:-1]
63 try: args[i] = name, Eval(expr).eval
64 except SyntaxError, v:
65 m,(huh,l,c,src) = v
66 raise ParseError, (
67 '<strong>Expression (Python) Syntax error</strong>:'
68 '\n<pre>\n%s\n</pre>\n' % v[0],
69 'let')
78
79 __call__ = render
80
81
82 -def parse_let_params(text,
83 result=None,
84 tag='let',
85 parmre=re.compile('([\000- ]*([^\000- ="]+)=([^\000- ="]+))'),
86 qparmre=re.compile('([\000- ]*([^\000- ="]+)="([^"]*)")'),
87 **parms):
111