Skip to content

Commit

Permalink
Merge pull request #46 from zopefoundation/fix-full-write-guard
Browse files Browse the repository at this point in the history
Fix the Python-3 variant which was not equivalent to the Python-2 one.
  • Loading branch information
loechel committed Mar 27, 2017
2 parents a3e9051 + 1593aca commit b627d8c
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/RestrictedPython/Guards.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,14 @@ def __init__(self, ob):

def _full_write_guard():
# Nested scope abuse!
# safetype and Wrapper variables are used by guard()
safetype = ({dict: True, list: True}.has_key if IS_PY2 else
{dict: True, list: True}.keys)
# safetypes and Wrapper variables are used by guard()
safetypes = {dict, list}
Wrapper = _write_wrapper()

def guard(ob):
# Don't bother wrapping simple types, or objects that claim to
# handle their own write security.
if safetype(type(ob)) or hasattr(ob, '_guarded_writes'):
if type(ob) in safetypes or hasattr(ob, '_guarded_writes'):
return ob
# Hand the object to the Wrapper instance, then return the instance.
return Wrapper(ob)
Expand Down

0 comments on commit b627d8c

Please sign in to comment.