From a8ad096d065ed2cf3bc329886e5da970ba634286 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Mon, 12 Feb 2018 13:39:31 +0545 Subject: [PATCH] importer: always refuse builtins and __builtin__. --- mitogen/core.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mitogen/core.py b/mitogen/core.py index 93adaf35..d0c69ec4 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -457,6 +457,13 @@ class Importer(object): del self.tls.running def _load_module_hacks(self, fullname): + if fullname in ('builtins', '__builtin__'): + # Python 2.x will generate needless imports for 'builtins', while + # Python 3.x will generate needless imports for '__builtin__'. The + # correct one is already present in sys.modules, the other is + # always a negative round-trip. + raise ImportError('Refused') + f = sys._getframe(2) requestee = f.f_globals['__name__']