Skip to content

Commit

Permalink
issue #310: fix negative imports on Python 3.x.
Browse files Browse the repository at this point in the history
On 3.x, Importer() can still have its methods called even if
load_module() raises ImportError.

Closes #310.
  • Loading branch information
dw committed Jul 19, 2018
1 parent 1ad4dff commit 7350a4c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mitogen/core.py
Expand Up @@ -815,10 +815,21 @@ def load_module(self, fullname):

def get_filename(self, fullname):
if fullname in self._cache:
path = self._cache[fullname][2]
if path is None:
# If find_loader() returns self but a subsequent master RPC
# reveals the module can't be loaded, and so load_module()
# throws ImportError, on Python 3.x it is still possible for
# the loader to be called to fetch metadata.
raise ImportError('master cannot serve %r' % (fullname,))
return u'master:' + self._cache[fullname][2]

def get_source(self, fullname):
if fullname in self._cache:
compressed = self._cache[fullname][3]
if compressed is None:
raise ImportError('master cannot serve %r' % (fullname,))

source = zlib.decompress(self._cache[fullname][3])
if PY3:
return to_text(source)
Expand Down

0 comments on commit 7350a4c

Please sign in to comment.