Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mitogen: Clarify blacklisted import error message #1013

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions mitogen/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ def is_blacklisted_import(importer, fullname):
any packages have been whitelisted and `fullname` is not part of one.

NB:
- The default whitelist is `['']` which matches any module name.
- If a package is on both lists, then it is treated as blacklisted.
- If any package is whitelisted, then all non-whitelisted packages are
treated as blacklisted.
Expand Down Expand Up @@ -1416,9 +1417,9 @@ def find_module(self, fullname, path=None):
del _tls.running

blacklisted_msg = (
'%r is present in the Mitogen importer blacklist, therefore this '
'context will not attempt to request it from the master, as the '
'request will always be refused.'
"%r is blacklisted (on the Mitogen importer blacklist (%r) or not "
"on the whitelist (%r)). This context won't try to request it from "
"the master, it would be refused."
)
pkg_resources_msg = (
'pkg_resources is prohibited from importing __main__, as it causes '
Expand All @@ -1433,7 +1434,10 @@ def find_module(self, fullname, path=None):

def _refuse_imports(self, fullname):
if is_blacklisted_import(self, fullname):
raise ModuleNotFoundError(self.blacklisted_msg % (fullname,))
raise ModuleNotFoundError(
self.blacklisted_msg
% (fullname, self.blacklist, self.whitelist),
)

f = sys._getframe(2)
requestee = f.f_globals['__name__']
Expand Down
18 changes: 0 additions & 18 deletions tests/responder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,3 @@ def test_stats(self):
self.assertEqual(2+os_fork, self.router.responder.good_load_module_count)
self.assertLess(10000, self.router.responder.good_load_module_size)
self.assertGreater(40000, self.router.responder.good_load_module_size)


class BlacklistTest(testlib.TestCase):
@unittest.skip('implement me')
def test_whitelist_no_blacklist(self):
assert 0

@unittest.skip('implement me')
def test_whitelist_has_blacklist(self):
assert 0

@unittest.skip('implement me')
def test_blacklist_no_whitelist(self):
assert 0

@unittest.skip('implement me')
def test_blacklist_has_whitelist(self):
assert 0