MCPcopy Index your code
hub / github.com/RustPython/RustPython / normalize_encoding

Function normalize_encoding

Lib/encodings/__init__.py:43–69  ·  view source on GitHub ↗

Normalize an encoding name. Normalization works as follows: all non-alphanumeric characters except the dot used for Python package names are collapsed and replaced with a single underscore, e.g. ' -;#' becomes '_'. Leading and trailing underscores are removed.

(encoding)

Source from the content-addressed store, hash-verified

41 pass
42
43def normalize_encoding(encoding):
44
45 """ Normalize an encoding name.
46
47 Normalization works as follows: all non-alphanumeric
48 characters except the dot used for Python package names are
49 collapsed and replaced with a single underscore, e.g. ' -;#'
50 becomes '_'. Leading and trailing underscores are removed.
51
52 Note that encoding names should be ASCII only.
53
54 """
55 if isinstance(encoding, bytes):
56 encoding = str(encoding, "ascii")
57
58 chars = []
59 punct = False
60 for c in encoding:
61 if c.isalnum() or c == '.':
62 if punct and chars:
63 chars.append('_')
64 if c.isascii():
65 chars.append(c)
66 punct = False
67 else:
68 punct = True
69 return ''.join(chars)
70
71def search_function(encoding):
72

Callers 1

search_functionFunction · 0.85

Calls 6

isinstanceFunction · 0.85
strFunction · 0.85
isalnumMethod · 0.45
appendMethod · 0.45
isasciiMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected