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

Function _get_module_code

Lib/zipimport.py:798–830  ·  view source on GitHub ↗
(self, fullname)

Source from the content-addressed store, hash-verified

796# Get the code object associated with the module specified by
797# 'fullname'.
798def _get_module_code(self, fullname):
799 path = _get_module_path(self, fullname)
800 import_error = None
801 for suffix, isbytecode, ispackage in _zip_searchorder:
802 fullpath = path + suffix
803 _bootstrap._verbose_message('trying {}{}{}', self.archive, path_sep, fullpath, verbosity=2)
804 try:
805 toc_entry = self._get_files()[fullpath]
806 except KeyError:
807 pass
808 else:
809 modpath = toc_entry[0]
810 data = _get_data(self.archive, toc_entry)
811 code = None
812 if isbytecode:
813 try:
814 code = _unmarshal_code(self, modpath, fullpath, fullname, data)
815 except ImportError as exc:
816 import_error = exc
817 else:
818 code = _compile_source(modpath, data, fullname)
819 if code is None:
820 # bad magic number or non-matching mtime
821 # in byte code, try next
822 continue
823 modpath = toc_entry[0]
824 return code, ispackage, modpath
825 else:
826 if import_error:
827 msg = f"module load failed: {import_error}"
828 raise ZipImportError(msg, name=fullname) from import_error
829 else:
830 raise ZipImportError(f"can't find module {fullname!r}", name=fullname)

Callers 2

get_codeMethod · 0.85
get_filenameMethod · 0.85

Calls 6

_get_module_pathFunction · 0.85
_get_dataFunction · 0.85
_unmarshal_codeFunction · 0.85
_compile_sourceFunction · 0.85
ZipImportErrorClass · 0.85
_get_filesMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…