diff --git a/README.rst b/README.rst index 0cd5a39..261d650 100644 --- a/README.rst +++ b/README.rst @@ -47,7 +47,7 @@ This example directly executed in Python could harm your system. .. code-block:: pycon >>> from RestrictedPython import compile_restricted - >>> from RestrictedPython import safe_builtins + >>> from RestrictedPython import safe_globals >>> >>> source_code = """ ... import os @@ -55,6 +55,6 @@ This example directly executed in Python could harm your system. ... os.listdir('/') ... """ >>> byte_code = compile_restricted(source_code, '', 'exec') - >>> exec(byte_code, {'__builtins__': safe_builtins}, {}) + >>> exec(byte_code, safe_globals, {}) Traceback (most recent call last): ImportError: __import__ not found diff --git a/docs/upgrade_dependencies/index.rst b/docs/upgrade_dependencies/index.rst index d411a14..62f02e8 100644 --- a/docs/upgrade_dependencies/index.rst +++ b/docs/upgrade_dependencies/index.rst @@ -28,6 +28,7 @@ RestrictedPython did move some of the imports to the base namespace, so you shou * predefined built-ins: + * ``from RestrictedPython import safe_globals`` * ``from RestrictedPython import safe_builtins`` * ``from RestrictedPython import limited_builtins`` * ``from RestrictedPython import utility_builtins`` diff --git a/docs/usage/api.rst b/docs/usage/api.rst index dc80ed7..32707c9 100644 --- a/docs/usage/api.rst +++ b/docs/usage/api.rst @@ -130,6 +130,7 @@ RestrictedPython has tree major scopes: 2. restricted builtins + * ``safe_globals`` * ``safe_builtins`` * ``limited_builtins`` * ``utility_builtins`` diff --git a/docs/usage/basic_usage.rst b/docs/usage/basic_usage.rst index 07d7de8..61c1393 100644 --- a/docs/usage/basic_usage.rst +++ b/docs/usage/basic_usage.rst @@ -86,12 +86,15 @@ So you normally end up using: filename='', mode='exec' ) - exec(byte_code, safe_builtins, None) + exec(byte_code, {'__builtins__': safe_builtins}, None) except SyntaxError as e: pass One common advanced usage would be to define an own restricted builtin dictionary. +There is a shortcut for ``{'__builtins__': safe_builtins}`` named +``safe_globals`` which can be imported from ``RestrictedPython``. + Necessary setup ---------------