Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ An unproblematic code example
Python allows you to execute a large set of commands.
This would not harm any system.

.. code-block:: pycon

>>> from RestrictedPython import compile_restricted
>>> from RestrictedPython import safe_builtins
>>>
Expand All @@ -42,15 +44,17 @@ Problematic code example

This example directly executed in Python could harm your system.

>>> from RestrictedPython import compile_restricted
>>> from RestrictedPython import safe_builtins
>>>
>>> source_code = """
... import os
...
... os.listdir('/')
... """
>>> byte_code = compile_restricted(source_code, '<inline>', 'exec')
>>> exec(byte_code, {'__builtins__': safe_builtins}, {})
Traceback (most recent call last):
ImportError: __import__ not found
.. code-block:: pycon

>>> from RestrictedPython import compile_restricted
>>> from RestrictedPython import safe_builtins
>>>
>>> source_code = """
... import os
...
... os.listdir('/')
... """
>>> byte_code = compile_restricted(source_code, '<inline>', 'exec')
>>> exec(byte_code, {'__builtins__': safe_builtins}, {})
Traceback (most recent call last):
ImportError: __import__ not found
6 changes: 0 additions & 6 deletions docs/CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Changes

- Fix regression in ``RestrictionCapableEval`` which broke when using list comprehensions.


4.0b1 (2017-09-15)
------------------

Expand All @@ -39,7 +38,6 @@ Changes
- Remove ``__len__`` method in ``.Guards._write_wrapper`` because it is no
longer reachable by code using the wrapper.


4.0a3 (2017-06-20)
------------------

Expand All @@ -48,8 +46,6 @@ Changes

- Update configurations to give better feedback and helpful reports.



4.0a2 (2017-05-26)
------------------

Expand All @@ -59,7 +55,6 @@ Changes
- Drop support for long-deprecated ``sets`` module.
[tseaver]


4.0a1 (2017-05-05)
------------------

Expand All @@ -73,7 +68,6 @@ Changes
- The ``compile_restricted*`` functions now return a
``namedtuple CompileResult`` instead of a simple ``tuple``.


3.6.0 (2010-07-09)
------------------

Expand Down
2 changes: 0 additions & 2 deletions docs/RestrictedPython3/index.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
RestrictedPython 3.6.x and before
=================================


Technical foundation of RestrictedPython
........................................

Expand All @@ -14,7 +13,6 @@ RestrictedPython based on the

With Python 2.6 the compiler module with all its sub modules has been declared deprecated with no direct upgrade Path or recommendations for a replacement.


Version Support of RestrictedPython 3.6.x
.........................................

Expand Down
12 changes: 5 additions & 7 deletions docs/api/index.rst
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
API of RestrictedPython 4.0
===========================

.. code:: Python
.. code-block:: python

compile_restricted(source, filename, mode [, flags [, dont_inherit]])

.. code:: Python
.. code-block:: python

compile_restricted_exec(source, filename, mode [, flags [, dont_inherit [, policy]]])

.. code:: Python
.. code-block:: python

compile_restricted_eval(source, filename, mode [, flags [, dont_inherit [, policy]]])


.. code:: Python
.. code-block:: python

compile_restricted_single(source, filename, mode [, flags [, dont_inherit [, policy]]])


.. code:: Python
.. code-block:: python

compile_restricted_function(source, filename, mode [, flags [, dont_inherit [, policy]]])
6 changes: 0 additions & 6 deletions docs/basics/index.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
Grundlagen von RestrictedPython und der Sicherheitskonzepte von Zope2
=====================================================================


Motivation für RestrictedPython
-------------------------------

Expand Down Expand Up @@ -36,14 +35,9 @@ Die zentrale Frage ist:

Vertraue ich der Software, bzw. den Entwicklern der Software und führe diese aus.




Python ist eine Turing-vollständige Prgrammiersprache.
Somit haben Entwickler grundsätzlich erstmal keine Limitierungen beim programmieren.



und können somit potentiell die Applikation und den Server selber schaden.

RestrictedPython und AccessControl zielen auf diese Besonderheit und versuchen einen reduzierten Subset der Programmiersprache Python zur verfügung zu stellen.
Expand Down
2 changes: 0 additions & 2 deletions docs/contributing/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ Contributing

Contributing to RestrictedPython 4+



Todos
-----

Expand Down
4 changes: 2 additions & 2 deletions docs/idea.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Python itself offers three methods that provide such a workflow:
Therefore RestrictedPython offers a replacement for the python builtin function ``compile()`` (Python 2: https://docs.python.org/2/library/functions.html#compile / Python 3 https://docs.python.org/3/library/functions.html#compile).
This method is defined as following:

.. code:: Python
.. code-block:: python

compile(source, filename, mode [, flags [, dont_inherit]])

Expand All @@ -42,7 +42,7 @@ There are three valid string values for ``mode``:

For RestrictedPython this ``compile()`` method is replaced by:

.. code:: Python
.. code-block:: python

compile_restricted(source, filename, mode [, flags [, dont_inherit]])

Expand Down
4 changes: 2 additions & 2 deletions docs/install/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ RestrictedPython is usually not used stand alone, if you use it in context of yo

For a standalone usage:

.. code:: bash
.. code-block:: console

pip install RestrictedPython
$ pip install RestrictedPython
1 change: 0 additions & 1 deletion docs/roadmap/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Full code coverage tests.

stephan-hof did propose a solution, should be discussed and if approved implemented.


RestrictedPython 4.1+
---------------------

Expand Down
11 changes: 1 addition & 10 deletions docs/upgrade/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ The ``compiler`` module predates several major improvements of the Python develo
While ``compiler`` still uses the old `CamelCase`_ Syntax (``visitNode(self, node, walker)``) the ``ast.AST`` did now use the Python common ``visit_Node(self, node)`` syntax.
Also the names of classes have been changed, where ``compiler`` uses ``Walker`` and ``Mutator`` the corresponding elements in ``ast.AST`` are ``NodeVisitor`` and ``NodeTransformator``.


``ast`` module (Abstract Syntax Trees)
--------------------------------------

Expand All @@ -48,7 +47,6 @@ The ``ast`` module consists of four areas:

* ``PyCF_ONLY_AST``


``NodeVisitor`` & ``NodeTransformer``
.....................................

Expand All @@ -58,15 +56,8 @@ In contrast, a ``NodeTransformer`` (which inherits from a ``NodeVisitor``) is al
Modifying the AST
-----------------








Technical Backgrounds - Links to External Documentation
---------------------------------------------------------
.......................................................
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why a level-change of the headings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it looked like "Technical Backgrounds" is a subsection of "Modifying the AST"


* Concept of Immutable Types and Python Example (https://en.wikipedia.org/wiki/Immutable_object#Python)
* Python 3 Standard Library Documentation on AST module ``ast`` (https://docs.python.org/3/library/ast.html)
Expand Down
1 change: 0 additions & 1 deletion docs/usage/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ RestrictedPython has tree major scopes:
... compiled_function.__defaults__ or ())
>>> result = new_function(*[], **{})


2. restricted builtins

* ``safe_builtins``
Expand Down
19 changes: 11 additions & 8 deletions docs/usage/basic_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ With RestrictedPython that workflow should be as straight forward as possible:
pass
"""

byte_code = compile_restricted(source_code,
filename='<inline code>',
mode='exec')
byte_code = compile_restricted(
source_code,
filename='<inline code>',
mode='exec'
)
exec(byte_code)
do_something()

Expand All @@ -51,7 +53,7 @@ restrict the access to the available library modules and methods.

Providing defined dictionaries for ``exec()`` should be used in context of RestrictedPython.

.. code:: Python
.. code-block:: python

byte_code = <code>
exec(byte_code, { ... }, { ... })
Expand Down Expand Up @@ -79,10 +81,11 @@ So you normally end up using:
"""

try:
byte_code = compile_restricted(source_code,
filename='<inline code>',
mode='exec')

byte_code = compile_restricted(
source_code,
filename='<inline code>',
mode='exec'
)
exec(byte_code, safe_builtins, None)
except SyntaxError as e:
pass
Expand Down
32 changes: 18 additions & 14 deletions docs/usage/framework_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ A policy is basically a special ``NodeTransformer`` that could be instantiated w
class OwnRestrictingNodeTransformer(RestrictingNodeTransformer):
pass

policy_instance = OwnRestrictingNodeTransformer(errors=[],
warnings=[],
used_names=[])
policy_instance = OwnRestrictingNodeTransformer(
errors=[],
warnings=[],
used_names=[]
)

All ``compile_restricted*`` methods do have a optional parameter ``policy``, where a specific policy could be provided.
All ``compile_restricted*`` methods do have an optional parameter ``policy``, where a specific policy could be provided.

.. testcode:: own_policy

Expand All @@ -58,11 +60,12 @@ All ``compile_restricted*`` methods do have a optional parameter ``policy``, whe

policy = OwnRestrictingNodeTransformer

byte_code = compile_restricted(source_code,
filename='<inline code>',
mode='exec',
policy=policy # Policy Class
)
byte_code = compile_restricted(
source_code,
filename='<inline code>',
mode='exec',
policy=policy # Policy Class
)
exec(byte_code, globals(), None)

One special case "unrestricted RestrictedPython" (defined to unblock ports of Zope Packages to Python 3) is to actually use RestrictedPython in an unrestricted mode, by providing a Null-Policy (aka ``None``).
Expand All @@ -77,9 +80,10 @@ That special case would be written as:
pass
"""

byte_code = compile_restricted(source_code,
filename='<inline code>',
mode='exec',
policy=None # Null-Policy -> unrestricted
)
byte_code = compile_restricted(
source_code,
filename='<inline code>',
mode='exec',
policy=None # Null-Policy -> unrestricted
)
exec(byte_code, globals(), None)
1 change: 0 additions & 1 deletion docs/usage/policy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Policies & builtins
Should be described in detail.
Especially the difference between builtins and a policy which is a NodeTransformer.


RestrictedPython provides a way to define Policies, by redefining restricted versions of ``print``, ``getattr``, ``setattr``, ``import``, etc..
As shortcuts it offers three stripped down versions of Pythons ``__builtins__``:

Expand Down
Loading