1
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 Soup Input Decoders
24 =====================
25
26 Soup Input Decoders.
27 """
28 if __doc__:
29
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 from ... import _htmldecode as _htmldecode
35 from ... import interfaces as _interfaces
36
37
39 """
40 Decoder for (X)HTML input
41
42 :IVariables:
43 `encoding` : ``str``
44 Character encoding
45 """
46 __implements__ = [_interfaces.DecoderInterface]
47
49 """
50 Initialization
51
52 :Parameters:
53 `encoding` : ``str``
54 Encoding
55 """
56 self.encoding = encoding
57
59 """ :See: `DecoderInterface` """
60 return name.lower()
61
62 - def decode(self, value, errors='strict'):
65
67 """ :See: `DecoderInterface` """
68 if value.startswith('"') or value.startswith("'"):
69 value = value[1:-1]
70 return _htmldecode.decode(value, self.encoding, errors=errors)
71
72
74 """
75 Decoder for XML input
76
77 :IVariables:
78 `encoding` : ``str``
79 Character encoding
80 """
81 __implements__ = [_interfaces.DecoderInterface]
82
84 """
85 Initialization
86
87 :Parameters:
88 `encoding` : ``str``
89 Character encoding
90 """
91 self.encoding = encoding
92
94 """ :See: `DecoderInterface` """
95 return name
96
97 - def decode(self, value, errors='strict'):
100
101 - def attribute(self, value, errors='strict'):
102 """ :See: `DecoderInterface` """
103 if value.startswith('"') or value.startswith("'"):
104 value = value[1:-1]
105 return _htmldecode.decode(value, self.encoding, errors=errors)
106
107
108 from ... import c
109 c = c.load('impl')
110 if c is not None:
111 HTMLDecoder, XMLDecoder = c.HTMLDecoder, c.XMLDecoder
112 del c
113