Package tdi :: Package markup :: Package text :: Module filters
[frames] | no frames]

Source Code for Module tdi.markup.text.filters

 1  # -*- coding: ascii -*- 
 2  # 
 3  # Copyright 2013 
 4  # Andr\xe9 Malo or his licensors, as applicable 
 5  # 
 6  # Licensed under the Apache License, Version 2.0 (the "License"); 
 7  # you may not use this file except in compliance with the License. 
 8  # You may obtain a copy of the License at 
 9  # 
10  #     http://www.apache.org/licenses/LICENSE-2.0 
11  # 
12  # Unless required by applicable law or agreed to in writing, software 
13  # distributed under the License is distributed on an "AS IS" BASIS, 
14  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
15  # See the License for the specific language governing permissions and 
16  # limitations under the License. 
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   
32 -class EncodingDetectFilter(_filters.BaseEventFilter):
33 """ Extract template encoding and pass it properly to the builder """ 34 35 #: Regex matcher to match encoding declarations 36 #: 37 #: :Type: ``callable`` 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
44 - def handle_pi(self, data):
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