Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
begin documenting usage and and upgarde of dependencies, also comment…
…ing source code in compile
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
Usage of RestrictedPython | ||
========================= | ||
|
||
Basics | ||
------ | ||
|
||
RestrictedPython do have tree major scopes: | ||
|
||
* compile_restricted methods | ||
|
||
* compile_restricted | ||
* compile_restricted_exec | ||
* compile_restricted_eval | ||
* compile_restricted_single | ||
* compile_restricted_function | ||
|
||
* restricted builtins | ||
|
||
* safe_builtins | ||
* limited_builtins | ||
* utility_builtins | ||
|
||
* Helper Moduls | ||
|
||
* PrintCollector | ||
|
||
heading | ||
------- | ||
|
||
The general workflow to execute Python code that is loaded within a Python program is: | ||
|
||
.. code:: Python | ||
source_code = """ | ||
def do_something(): | ||
pass | ||
""" | ||
byte_code = compile(source_code, filename='<inline code>', mode='exec') | ||
exec(byte_code) | ||
do_something() | ||
With RestrictedPython that workflow should be as straight forward as possible: | ||
|
||
.. code:: Python | ||
from RestrictedPython import compile_restricted as compile | ||
source_code = """ | ||
def do_something(): | ||
pass | ||
""" | ||
byte_code = compile(source_code, filename='<inline code>', mode='exec') | ||
exec(byte_code) | ||
do_something() | ||
With that simple addition ``from RestrictedPython import compile_restricted as compile`` it uses a predefined policy that checks and modify the source code and checks against restricted subset of the Python language. | ||
Execution of the compiled source code is still against the full avaliable set of library modules and methods. |