[Zope-Checkins] CVS: Zope/lib/python/RestrictedPython - Guards.py:1.5.4.1
Ken Manheimer
klm@zope.com
Tue, 16 Oct 2001 11:22:32 -0400
Update of /cvs-repository/Zope/lib/python/RestrictedPython
In directory cvs.zope.org:/tmp/cvs-serv24340
Modified Files:
Tag: Zope-2_4-branch
Guards.py
Log Message:
_full_read_guard(), _full_write_guard(): Use default arguments rather
than nested scopes to convey the value of safetype (and Wrapper, in
_full_write_guard()) to the nested guard function.
This is necessary to avoid occasional, apparent stack confusion in
_full_write_guard() when we use just nested scopes, where 'safetype'
gets the value of 'Wrapper'. I don't know why this happens, or even
how to reliably repeat it with a simple case. However, once the
conditions *are* set set, it's easy to repeat, and this change
prevents it from happening.
=== Zope/lib/python/RestrictedPython/Guards.py 1.5 => 1.5.4.1 ===
# safetype variable is used by guard()
safetype = {type(()): 1, type([]): 1, type({}): 1, type(''): 1}.has_key
- def guard(ob, write=None):
+ def guard(ob, write=None, safetype=safetype):
# Don't bother wrapping simple types, or objects that claim to
# handle their own read security.
if safetype(type(ob)) or getattr(ob, '_guarded_reads', 0):
@@ -165,7 +165,7 @@
# safetype and Wrapper variables are used by guard()
safetype = {type([]): 1, type({}): 1}.has_key
Wrapper = _write_wrapper()
- def guard(ob):
+ def guard(ob, safetype=safetype, Wrapper=Wrapper):
# 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'):