1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """
18 =====================
19 Soup Input Decoders
20 =====================
21
22 Soup Input Decoders.
23 """
24 __author__ = u"Andr\xe9 Malo"
25 __docformat__ = "restructuredtext en"
26
27 from tdi import _htmldecode as _htmldecode
28 from tdi import interfaces as _interfaces
29
30
32 """
33 Decoder for (X)HTML input
34
35 :IVariables:
36 `encoding` : ``str``
37 Character encoding
38 """
39 __implements__ = [_interfaces.DecoderInterface]
40
42 """
43 Initialization
44
45 :Parameters:
46 `encoding` : ``str``
47 Encoding
48 """
49 self.encoding = encoding
50
52 """ :See: `DecoderInterface` """
53 return name.lower()
54
55 - def decode(self, value, errors='strict'):
58
60 """ :See: `DecoderInterface` """
61 if value.startswith('"') or value.startswith("'"):
62 value = value[1:-1]
63 return _htmldecode.decode(value, self.encoding, errors=errors)
64
65
67 """
68 Decoder for XML input
69
70 :IVariables:
71 `encoding` : ``str``
72 Character encoding
73 """
74 __implements__ = [_interfaces.DecoderInterface]
75
77 """
78 Initialization
79
80 :Parameters:
81 `encoding` : ``str``
82 Character encoding
83 """
84 self.encoding = encoding
85
87 """ :See: `DecoderInterface` """
88 return name
89
90 - def decode(self, value, errors='strict'):
93
95 """ :See: `DecoderInterface` """
96 if value.startswith('"') or value.startswith("'"):
97 value = value[1:-1]
98 return _htmldecode.decode(value, self.encoding, errors=errors)
99
100
101 from tdi import c
102 c = c.load('impl')
103 if c is not None:
104 HTMLDecoder, XMLDecoder = c.HTMLDecoder, c.XMLDecoder
105 del c
106