1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """
18 =====================
19 Text Filter Classes
20 =====================
21
22 Filters for text templates.
23 """
24 __author__ = u"Andr\xe9 Malo"
25 __docformat__ = "restructuredtext en"
26
27 import re as _re
28
29 from tdi import filters as _filters
30
31
33 """ Extract template encoding and pass it properly to the builder """
34
35
36
37
38 _PI_MATCH = _re.compile(r'''
39 \[\? \s*
40 [eE][nN][cC][oO][dD][iI][nN][gG] (?:\s+|\s*=\s*) (?P<enc>[^=\s?]+)
41 \s* \?\]$
42 ''', _re.X).match
43
45 """
46 Extract encoding from PI instruction
47
48 Here's a sample for the expected format::
49
50 [? encoding latin-1 ?]
51
52 The event is passed to the builder nevertheless.
53
54 :See: `BuildingListenerInterface`
55 """
56 match = self._PI_MATCH(data)
57 if match:
58 self.builder.handle_encoding(match.group('enc'))
59 self.builder.handle_pi(data)
60