A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://pypi.python.org/pypi/RestrictedPython below:

RestrictedPython · PyPI

RestrictedPython is a tool that helps to define a subset of the Python language which allows to provide a program input into a trusted environment. RestrictedPython is not a sandbox system or a secured environment, but it helps to define a trusted environment and execute untrusted code inside of it.

Example

To give a basic understanding what RestrictedPython does here two examples:

An unproblematic code example

Python allows you to execute a large set of commands. This would not harm any system.

>>> from RestrictedPython import compile_restricted
>>> from RestrictedPython import safe_globals
>>>
>>> source_code = """
... def example():
...     return 'Hello World!'
... """
>>>
>>> loc = {}
>>> byte_code = compile_restricted(source_code, '<inline>', 'exec')
>>> exec(byte_code, safe_globals, loc)
>>>
>>> loc['example']()
'Hello World!'
Problematic code example

This example directly executed in Python could harm your system.

>>> from RestrictedPython import compile_restricted
>>> from RestrictedPython import safe_globals
>>>
>>> source_code = """
... import os
...
... os.listdir('/')
... """
>>> byte_code = compile_restricted(source_code, '<inline>', 'exec')
>>> exec(byte_code, safe_globals, {})
Traceback (most recent call last):
ImportError: __import__ not found
Contributing to RestrictedPython

If you want to help maintain RestrictedPython and contribute, please refer to the documentation Contributing page.

Changes 8.0 (2025-01-23) Backwards incompatible changes Features 7.4 (2024-10-09) 7.3 (2024-09-30) 7.2 (2024-08-02) 7.1 (2024-03-14) 7.0 (2023-11-17) Backwards incompatible changes Features Fixes 6.0 (2022-11-03) Backwards incompatible changes Features 5.2 (2021-11-19) 5.1 (2020-10-07) Features Documentation Fixes 5.0 (2019-09-03) Breaking changes Features 4.0 (2019-05-10)

Changes since 3.6.0:

Breaking changes Features Bug fixes 3.6.0 (2010-07-09) 3.6.0a1 (2010-06-05) 3.5.2 (2010-04-30) 3.5.1 (2009-03-17) 3.5.0 (2009-02-09) 3.4.3 (2008-10-26) 3.4.2 (2007-07-28) 3.4.1 (2007-06-23) 3.4.0 (2007-06-04) 3.2.0 (2006-01-05) 3.1.0 (2005-10-03) 3.0.0 (2004-11-07)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4