File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3434_cache = {}
3535_unknown = '--unknown--'
3636_import_tail = ['*' ]
37- _norm_encoding_map = (' . '
38- '0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ '
39- ' abcdefghijklmnopqrstuvwxyz '
40- ' '
41- ' '
42- ' ' )
4337_aliases = aliases .aliases
4438
4539class CodecRegistryError (LookupError , SystemError ):
@@ -58,14 +52,17 @@ def normalize_encoding(encoding):
5852 non-ASCII characters, these must be Latin-1 compatible.
5953
6054 """
61- # Make sure we have an 8-bit string, because .translate() works
62- # differently for Unicode strings.
63- if isinstance (encoding , str ):
64- # Note that .encode('latin-1') does *not* use the codec
65- # registry, so this call doesn't recurse. (See unicodeobject.c
66- # PyUnicode_AsEncodedString() for details)
67- encoding = encoding .encode ('latin-1' )
68- return '_' .join (encoding .translate (_norm_encoding_map ).split ())
55+ chars = []
56+ punct = False
57+ for c in encoding :
58+ if c .isalnum () or c == '.' :
59+ if punct and chars :
60+ chars .append ('_' )
61+ chars .append (c )
62+ punct = False
63+ else :
64+ punct = True
65+ return '' .join (chars )
6966
7067def search_function (encoding ):
7168
You can’t perform that action at this time.
0 commit comments