Skip to content

Commit 3ecbd6d

Browse files
authored
Remove documentation that appears to promote unsupported direct guards usage (#314)
1 parent aa2282a commit 3ecbd6d

2 files changed

Lines changed: 2 additions & 68 deletions

File tree

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Changes
44
8.2 (unreleased)
55
----------------
66

7+
- Remove documentation that appears to promote unsupported direct guards usage.
8+
79
- Move package metadata from setup.py to pyproject.toml.
810

911
- Drop support for Python 3.9.

docs/usage/policy.rst

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -167,71 +167,3 @@ unsafe operations, such as opening files:
167167
Traceback (most recent call last):
168168
...
169169
NameError: name 'open' is not defined
170-
171-
Guards
172-
......
173-
174-
Here's an example of a write guard that never lets restricted code
175-
modify (assign, delete an attribute or item) except dictionaries and
176-
lists:
177-
178-
.. code-block:: pycon
179-
180-
>>> from RestrictedPython.Guards import full_write_guard
181-
>>> _write_ = full_write_guard
182-
>>> _getattr_ = getattr
183-
184-
>>> class BikeShed(object):
185-
... colour = 'green'
186-
...
187-
>>> shed = BikeShed()
188-
189-
Normally accessing attributes works as expected, because we're using
190-
the standard ``getattr`` function for the ``_getattr_`` guard:
191-
192-
.. code-block:: pycon
193-
194-
>>> src = '''
195-
... print(shed.colour)
196-
... result = printed
197-
... '''
198-
>>> code = compile_restricted(src, '<string>', 'exec')
199-
>>> exec(code)
200-
201-
>>> result
202-
'green\n'
203-
204-
However, changing an attribute doesn't work:
205-
206-
.. code-block:: pycon
207-
208-
>>> src = '''
209-
... shed.colour = 'red'
210-
... '''
211-
>>> code = compile_restricted(src, '<string>', 'exec')
212-
>>> exec(code)
213-
Traceback (most recent call last):
214-
...
215-
TypeError: attribute-less object (assign or del)
216-
217-
As said, this particular write guard (``full_write_guard``) will allow
218-
restricted code to modify lists and dictionaries:
219-
220-
.. code-block:: pycon
221-
222-
>>> fibonacci = [1, 1, 2, 3, 4]
223-
>>> transl = dict(one=1, two=2, tres=3)
224-
>>> src = '''
225-
... # correct mistake in list
226-
... fibonacci[-1] = 5
227-
... # one item doesn't belong
228-
... del transl['tres']
229-
... '''
230-
>>> code = compile_restricted(src, '<string>', 'exec')
231-
>>> exec(code)
232-
233-
>>> fibonacci
234-
[1, 1, 2, 3, 5]
235-
236-
>>> sorted(transl.keys())
237-
['one', 'two']

0 commit comments

Comments
 (0)