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

Function search_function

Lib/encodings/__init__.py:71–153  ·  view source on GitHub ↗
(encoding)

Source from the content-addressed store, hash-verified

69 return ''.join(chars)
70
71def search_function(encoding):
72
73 # Cache lookup
74 entry = _cache.get(encoding, _unknown)
75 if entry is not _unknown:
76 return entry
77
78 # Import the module:
79 #
80 # First try to find an alias for the normalized encoding
81 # name and lookup the module using the aliased name, then try to
82 # lookup the module using the standard import scheme, i.e. first
83 # try in the encodings package, then at top-level.
84 #
85 norm_encoding = normalize_encoding(encoding)
86 aliased_encoding = _aliases.get(norm_encoding) or \
87 _aliases.get(norm_encoding.replace('.', '_'))
88 if aliased_encoding is not None:
89 modnames = [aliased_encoding,
90 norm_encoding]
91 else:
92 modnames = [norm_encoding]
93 for modname in modnames:
94 if not modname or '.' in modname:
95 continue
96 try:
97 # Import is absolute to prevent the possibly malicious import of a
98 # module with side-effects that is not in the 'encodings' package.
99 mod = __import__('encodings.' + modname, fromlist=_import_tail,
100 level=0)
101 except ImportError:
102 # ImportError may occur because 'encodings.(modname)' does not exist,
103 # or because it imports a name that does not exist (see mbcs and oem)
104 pass
105 else:
106 break
107 else:
108 mod = None
109
110 try:
111 getregentry = mod.getregentry
112 except AttributeError:
113 # Not a codec module
114 mod = None
115
116 if mod is None:
117 # Cache misses
118 _cache[encoding] = None
119 return None
120
121 # Now ask the module for the registry entry
122 entry = getregentry()
123 if not isinstance(entry, codecs.CodecInfo):
124 if not 4 <= len(entry) <= 7:
125 raise CodecRegistryError('module "%s" (%s) failed to register'
126 % (mod.__name__, mod.__file__))
127 if not callable(entry[0]) or not callable(entry[1]) or \
128 (entry[2] is not None and not callable(entry[2])) or \

Callers

nothing calls this directly

Calls 10

normalize_encodingFunction · 0.85
isinstanceFunction · 0.85
lenFunction · 0.85
CodecRegistryErrorClass · 0.85
callableFunction · 0.85
getregentryFunction · 0.70
__import__Function · 0.50
getMethod · 0.45
replaceMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected