MCPcopy Index your code
hub / github.com/python/cpython / normalize_encoding

Function normalize_encoding

Lib/encodings/__init__.py:45–66  ·  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

43 pass
44
45def normalize_encoding(encoding):
46
47 """ Normalize an encoding name.
48
49 Normalization works as follows: all non-alphanumeric
50 characters except the dot used for Python package names are
51 collapsed and replaced with a single underscore, e.g. ' -;#'
52 becomes '_'. Leading and trailing underscores are removed.
53
54 Note that encoding names should be ASCII only.
55
56 """
57 if isinstance(encoding, bytes):
58 encoding = str(encoding, "ascii")
59
60 if not encoding.isascii():
61 import warnings
62 warnings.warn(
63 "Support for non-ascii encoding names will be removed in 3.17",
64 DeprecationWarning, stacklevel=2)
65
66 return _normalize_encoding(encoding)
67
68def search_function(encoding):
69

Callers 1

search_functionFunction · 0.85

Calls 3

strFunction · 0.85
isasciiMethod · 0.80
warnMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…