Commit 5aaede96 authored by Arnaud Fontaine's avatar Arnaud Fontaine Committed by Jérome Perrin

py3: patches/Restricted: Port to Python3.

parent 63320b86
...@@ -279,7 +279,7 @@ def allow_full_write(t): ...@@ -279,7 +279,7 @@ def allow_full_write(t):
# Modify 'safetype' dict in full_write_guard function of RestrictedPython # Modify 'safetype' dict in full_write_guard function of RestrictedPython
# (closure) directly to allow write access (using __setattr__ and __delattr__) # (closure) directly to allow write access (using __setattr__ and __delattr__)
from RestrictedPython.Guards import full_write_guard from RestrictedPython.Guards import full_write_guard
safetype = full_write_guard.func_closure[1].cell_contents safetype = full_write_guard.__closure__[1].cell_contents
if isinstance(safetype, set): # 5.1 if isinstance(safetype, set): # 5.1
safetype.add(t) safetype.add(t)
else: # 3.6 else: # 3.6
...@@ -293,9 +293,15 @@ from RestrictedPython.Guards import full_write_guard ...@@ -293,9 +293,15 @@ from RestrictedPython.Guards import full_write_guard
ContainerAssertions[defaultdict] = _check_access_wrapper(defaultdict, _dict_white_list) ContainerAssertions[defaultdict] = _check_access_wrapper(defaultdict, _dict_white_list)
allow_full_write(defaultdict) allow_full_write(defaultdict)
# On Python2 only: In contrary to builtins such as dict/defaultdict, it is
# possible to set attributes on OrderedDict instances, so only allow
# setitem/delitem
ContainerAssertions[OrderedDict] = _check_access_wrapper(OrderedDict, _dict_white_list) ContainerAssertions[OrderedDict] = _check_access_wrapper(OrderedDict, _dict_white_list)
OrderedDict.__guarded_setitem__ = OrderedDict.__setitem__.__func__ if six.PY2:
OrderedDict.__guarded_delitem__ = OrderedDict.__delitem__.__func__ OrderedDict.__guarded_setitem__ = OrderedDict.__setitem__.__func__
OrderedDict.__guarded_delitem__ = OrderedDict.__delitem__.__func__
else:
allow_full_write(OrderedDict)
_counter_white_list = copy.copy(_dict_white_list) _counter_white_list = copy.copy(_dict_white_list)
_counter_white_list['most_common'] = 1 _counter_white_list['most_common'] = 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment