diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index eafcb87a..2a79f703 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # standard imports +import inspect import re # plex debugging @@ -24,6 +25,18 @@ # imports from Libraries\Shared from typing import Optional +# get the original Python builtins module +python_builtins = inspect.getmodule(object) + +# get the Sandbox instance +sandbox = inspect.stack()[1][0].f_locals["self"] + +# bypass RestrictedPython +getattr(sandbox, "_core").loader.compile = lambda src, name, _=False: python_builtins.compile(src, name, "exec") + +# restore Python builtins +sandbox.environment.update(python_builtins.vars(python_builtins)) + # local imports from default_prefs import default_prefs from constants import contributes_to, version