1
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 Soup Input Decoders
24 =====================
25
26 Soup Input Decoders.
27 """
28 __author__ = u"Andr\xe9 Malo"
29 __docformat__ = "restructuredtext en"
30
31 from tdi import _htmldecode as _htmldecode
32 from tdi import interfaces as _interfaces
33
34
36 """
37 Decoder for (X)HTML input
38
39 :IVariables:
40 `encoding` : ``str``
41 Character encoding
42 """
43 __implements__ = [_interfaces.DecoderInterface]
44
46 """
47 Initialization
48
49 :Parameters:
50 `encoding` : ``str``
51 Encoding
52 """
53 self.encoding = encoding
54
56 """ :See: `DecoderInterface` """
57 return name.lower()
58
59 - def decode(self, value, errors='strict'):
62
64 """ :See: `DecoderInterface` """
65 if value.startswith('"') or value.startswith("'"):
66 value = value[1:-1]
67 return _htmldecode.decode(value, self.encoding, errors=errors)
68
69
71 """
72 Decoder for XML input
73
74 :IVariables:
75 `encoding` : ``str``
76 Character encoding
77 """
78 __implements__ = [_interfaces.DecoderInterface]
79
81 """
82 Initialization
83
84 :Parameters:
85 `encoding` : ``str``
86 Character encoding
87 """
88 self.encoding = encoding
89
91 """ :See: `DecoderInterface` """
92 return name
93
94 - def decode(self, value, errors='strict'):
97
99 """ :See: `DecoderInterface` """
100 if value.startswith('"') or value.startswith("'"):
101 value = value[1:-1]
102 return _htmldecode.decode(value, self.encoding, errors=errors)
103
104
105 from tdi import c
106 c = c.load('impl')
107 if c is not None:
108 HTMLDecoder, XMLDecoder = c.HTMLDecoder, c.XMLDecoder
109 del c
110