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

Source Code for Module tdi.markup.text.filters

 1  # -*- coding: ascii -*- 
 2  r""" 
 3  :Copyright: 
 4   
 5   Copyright 2013 - 2015 
 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  if __doc__: 
29      # pylint: disable = redefined-builtin 
30      __doc__ = __doc__.encode('ascii').decode('unicode_escape') 
31  __author__ = r"Andr\xe9 Malo".encode('ascii').decode('unicode_escape') 
32  __docformat__ = "restructuredtext en" 
33   
34  import re as _re 
35   
36  from ... import filters as _filters 
37   
38   
39 -class EncodingDetectFilter(_filters.BaseEventFilter):
40 """ Extract template encoding and pass it properly to the builder """ 41 42 #: Regex matcher to match encoding declarations 43 #: 44 #: :Type: ``callable`` 45 _PI_MATCH = _re.compile(r''' 46 \[\? \s* 47 [eE][nN][cC][oO][dD][iI][nN][gG] (?:\s+|\s*=\s*) (?P<enc>[^=\s?]+) 48 \s* \?\]$ 49 ''', _re.X).match 50
51 - def handle_pi(self, data):
52 """ 53 Extract encoding from PI instruction 54 55 Here's a sample for the expected format:: 56 57 [? encoding latin-1 ?] 58 59 The event is passed to the builder nevertheless. 60 61 :See: `BuildingListenerInterface` 62 """ 63 match = self._PI_MATCH(data) 64 if match: 65 self.builder.handle_encoding(match.group('enc')) 66 self.builder.handle_pi(data)
67