diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index eafcb87a..6ad2ce87 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,21 @@ # imports from Libraries\Shared from typing import Optional +try: + # 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)) +except Exception as e: + Log.Exception("Failed to bypass RestrictedPython: {}".format(e)) + # local imports from default_prefs import default_prefs from constants import contributes_to, version