diff --git a/CHANGES.rst b/CHANGES.rst index 7f55366..34de237 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,8 @@ Changes 8.2 (unreleased) ---------------- +- Remove documentation that appears to promote unsupported direct guards usage. + - Move package metadata from setup.py to pyproject.toml. - Drop support for Python 3.9. diff --git a/docs/usage/policy.rst b/docs/usage/policy.rst index cd50c9c..6fda45c 100644 --- a/docs/usage/policy.rst +++ b/docs/usage/policy.rst @@ -167,71 +167,3 @@ unsafe operations, such as opening files: Traceback (most recent call last): ... NameError: name 'open' is not defined - -Guards -...... - -Here's an example of a write guard that never lets restricted code -modify (assign, delete an attribute or item) except dictionaries and -lists: - -.. code-block:: pycon - - >>> from RestrictedPython.Guards import full_write_guard - >>> _write_ = full_write_guard - >>> _getattr_ = getattr - - >>> class BikeShed(object): - ... colour = 'green' - ... - >>> shed = BikeShed() - -Normally accessing attributes works as expected, because we're using -the standard ``getattr`` function for the ``_getattr_`` guard: - -.. code-block:: pycon - - >>> src = ''' - ... print(shed.colour) - ... result = printed - ... ''' - >>> code = compile_restricted(src, '', 'exec') - >>> exec(code) - - >>> result - 'green\n' - -However, changing an attribute doesn't work: - -.. code-block:: pycon - - >>> src = ''' - ... shed.colour = 'red' - ... ''' - >>> code = compile_restricted(src, '', 'exec') - >>> exec(code) - Traceback (most recent call last): - ... - TypeError: attribute-less object (assign or del) - -As said, this particular write guard (``full_write_guard``) will allow -restricted code to modify lists and dictionaries: - -.. code-block:: pycon - - >>> fibonacci = [1, 1, 2, 3, 4] - >>> transl = dict(one=1, two=2, tres=3) - >>> src = ''' - ... # correct mistake in list - ... fibonacci[-1] = 5 - ... # one item doesn't belong - ... del transl['tres'] - ... ''' - >>> code = compile_restricted(src, '', 'exec') - >>> exec(code) - - >>> fibonacci - [1, 1, 2, 3, 5] - - >>> sorted(transl.keys()) - ['one', 'two']