1
2 r"""
3 :Copyright:
4
5 Copyright 2006 - 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 Tool Utilities
24 ================
25
26 Tool Utilities.
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 import encodings as _encodings
35
36
38 """ Make encoding normalizer """
39 isinstance_, unicode_, str_ = isinstance, unicode, str
40 normalize = _encodings.normalize_encoding
41 aliases = _encodings.aliases.aliases.get
42 get_alias = lambda x: aliases(x, x)
43
44 def norm_enc(encoding):
45 """ Return normalized unaliased encoding name """
46
47
48 if not isinstance_(encoding, unicode_):
49 encoding = str_(encoding).decode('latin-1')
50 return get_alias(normalize(encoding.lower()))
51
52 return norm_enc
53
54 norm_enc = _make_norm_enc()
55