8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
10 # FOR A PARTICULAR PURPOSE. |
10 # FOR A PARTICULAR PURPOSE. |
11 # |
11 # |
12 |
12 |
13 __docformat__ = 'restructuredtext' |
13 """PyAMS_utils.tales module |
|
14 |
|
15 This module provides a custom TALES extension engine, which allows you to define custom |
|
16 TALES expressions which can be used from Chameleon or Zope templates. |
|
17 """ |
14 |
18 |
15 import re |
19 import re |
16 |
20 |
17 from chameleon.astutil import Symbol |
21 from chameleon.astutil import Symbol |
18 from chameleon.codegen import template |
22 from chameleon.codegen import template |
19 from chameleon.tales import StringExpr |
23 from chameleon.tales import StringExpr |
20 from zope.contentprovider.tales import addTALNamespaceData |
24 from zope.contentprovider.tales import addTALNamespaceData |
21 |
25 |
22 from pyams_utils.interfaces.tales import ITALESExtension |
26 from pyams_utils.interfaces.tales import ITALESExtension |
23 |
27 |
|
28 __docformat__ = 'restructuredtext' |
24 |
29 |
25 class ContextExprMixin(object): |
30 |
|
31 class ContextExprMixin: |
26 """Mixin-class for expression compilers""" |
32 """Mixin-class for expression compilers""" |
27 |
33 |
28 transform = None |
34 transform = None |
29 |
35 |
30 def __call__(self, target, engine): |
36 def __call__(self, target, engine): |
34 target=target, |
40 target=target, |
35 transform=self.transform) |
41 transform=self.transform) |
36 return assignment + transform |
42 return assignment + transform |
37 |
43 |
38 |
44 |
39 FUNCTION_EXPRESSION = re.compile('(.+)\((.+)\)', re.MULTILINE | re.DOTALL) |
45 FUNCTION_EXPRESSION = re.compile(r'(.+)\((.+)\)', re.MULTILINE | re.DOTALL) |
40 ARGUMENTS_EXPRESSION = re.compile('[^(,)]+') |
46 ARGUMENTS_EXPRESSION = re.compile(r'[^(,)]+') |
41 |
47 |
42 |
48 |
43 def render_extension(econtext, name): |
49 def render_extension(econtext, name): |
44 """TALES extension renderer |
50 """TALES extension renderer |
45 |
51 |