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)
| 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. |
no test coverage detected