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

Method get_source

Lib/zipimport.py:170–192  ·  view source on GitHub ↗

get_source(fullname) -> source string. Return the source code for the specified module. Raise ZipImportError if the module couldn't be found, return None if the archive does contain the module, but has no source for it.

(self, fullname)

Source from the content-addressed store, hash-verified

168
169
170 def get_source(self, fullname):
171 """get_source(fullname) -> source string.
172
173 Return the source code for the specified module. Raise ZipImportError
174 if the module couldn't be found, return None if the archive does
175 contain the module, but has no source for it.
176 """
177 mi = _get_module_info(self, fullname)
178 if mi is None:
179 raise ZipImportError(f"can't find module {fullname!r}", name=fullname)
180
181 path = _get_module_path(self, fullname)
182 if mi:
183 fullpath = _bootstrap_external._path_join(path, '__init__.py')
184 else:
185 fullpath = f'{path}.py'
186
187 try:
188 toc_entry = self._get_files()[fullpath]
189 except KeyError:
190 # we have the module, but no source
191 return None
192 return _get_data(self.archive, toc_entry).decode()
193
194
195 # Return a bool signifying whether the module is a package or not.

Callers 2

runMethod · 0.45
_readmoduleFunction · 0.45

Calls 6

_get_filesMethod · 0.95
_get_module_infoFunction · 0.85
ZipImportErrorClass · 0.85
_get_module_pathFunction · 0.85
_get_dataFunction · 0.85
decodeMethod · 0.45

Tested by

no test coverage detected