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

Source Code for Module tdi.markup.text.filters

 1  # -*- coding: ascii -*- 
 2  u""" 
 3  :Copyright: 
 4   
 5   Copyright 2013 
 6   Andr\xe9 Malo or his licensors, as applicable 
 7   
 8  :License: 
 9   
10   Licensed under the Apache License, Version 2.0 (the "License"); 
11   you may not use this file except in compliance with the License. 
12   You may obtain a copy of the License at 
13   
14       http://www.apache.org/licenses/LICENSE-2.0 
15   
16   Unless required by applicable law or agreed to in writing, software 
17   distributed under the License is distributed on an "AS IS" BASIS, 
18   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
19   See the License for the specific language governing permissions and 
20   limitations under the License. 
21   
22  ===================== 
23   Text Filter Classes 
24  ===================== 
25   
26  Filters for text templates. 
27  """ 
28  __author__ = u"Andr\xe9 Malo" 
29  __docformat__ = "restructuredtext en" 
30   
31  import re as _re 
32   
33  from tdi import filters as _filters 
34   
35   
36 -class EncodingDetectFilter(_filters.BaseEventFilter):
37 """ Extract template encoding and pass it properly to the builder """ 38 39 #: Regex matcher to match encoding declarations 40 #: 41 #: :Type: ``callable`` 42 _PI_MATCH = _re.compile(r''' 43 \[\? \s* 44 [eE][nN][cC][oO][dD][iI][nN][gG] (?:\s+|\s*=\s*) (?P<enc>[^=\s?]+) 45 \s* \?\]$ 46 ''', _re.X).match 47
48 - def handle_pi(self, data):
49 """ 50 Extract encoding from PI instruction 51 52 Here's a sample for the expected format:: 53 54 [? encoding latin-1 ?] 55 56 The event is passed to the builder nevertheless. 57 58 :See: `BuildingListenerInterface` 59 """ 60 match = self._PI_MATCH(data) 61 if match: 62 self.builder.handle_encoding(match.group('enc')) 63 self.builder.handle_pi(data)
64