A function declared to be available inside the RepyV2 namespace via one of namespace.py's *_WRAPPER_INFO wrapper dicts may list Dict() as (one of) its args processor(s). A call from within the sandbox into such function causes the argument(s) to be _copyed. Now certain dictionary contents cause problems during copying, particularly those that use types as values.
For instance, virtualnamespace.evaluate takes a dict or SafeDict argument. Supplying a dict with a problematic value like so,
v = createvirtualnamespace("", "")
v.evaluate({"abc": str}) # Ouch
breaks as namespace._copy raises Exception (with class 'namespace.NamespaceInternalError'): _copy failed on {'abc': <type 'str'>} with message _copy failed on <type 'str'> with message _copy is not implemented for objects of type <function safe_type at 0x10d0021b8>. The issue is that str is a type, or more accurately a safe.safe_type, and there is no handling for that in _copy.
Funnily enough, the problem is avoided by providing a SafeDict with the same contents, because the SafeDict makes a different clause in _copy match. The difference is that SafeDicts are instances / types.InstanceTypes.
v = createvirtualnamespace("", "")
v.evaluate(SafeDict({"abc": str})) # Success!
The superficial fix for this corner case of a corner case of a bit of funtionality I've never seen anyone use is to add safe.safe_type to the list of types that namespace._copy checks the type of its argument, obj, against. Whether or not dicts should be treated all that differently from SafeDicts as they traverse the namespace boundary is a different question though.
Historical note: I found this problem via the original virtualnamespace context safety unit test, although that test was not supposed the above problem: https://github.com/SeattleTestbed/repy_v2/blob/4db9ecd48a4577d646e4c38cf1af634dd8600810/testsV2/ut_repyv2api_virtualnamespacecontextsafety.py .
A function declared to be available inside the RepyV2 namespace via one of
namespace.py's*_WRAPPER_INFOwrapper dicts may listDict()as (one of) its args processor(s). A call from within the sandbox into such function causes the argument(s) to be_copyed. Now certain dictionary contents cause problems during copying, particularly those that usetypes as values.For instance,
virtualnamespace.evaluatetakes adictorSafeDictargument. Supplying adictwith a problematic value like so,breaks as
namespace._copyraisesException (with class 'namespace.NamespaceInternalError'): _copy failed on {'abc': <type 'str'>} with message _copy failed on <type 'str'> with message _copy is not implemented for objects of type <function safe_type at 0x10d0021b8>. The issue is thatstris atype, or more accurately asafe.safe_type, and there is no handling for that in_copy.Funnily enough, the problem is avoided by providing a
SafeDictwith the same contents, because theSafeDictmakes a different clause in_copymatch. The difference is thatSafeDicts areinstances /types.InstanceTypes.The superficial fix for this corner case of a corner case of a bit of funtionality I've never seen anyone use is to add
safe.safe_typeto the list of types thatnamespace._copychecks the type of its argument,obj, against. Whether or notdicts should be treated all that differently fromSafeDicts as they traverse the namespace boundary is a different question though.Historical note: I found this problem via the original virtualnamespace context safety unit test, although that test was not supposed the above problem: https://github.com/SeattleTestbed/repy_v2/blob/4db9ecd48a4577d646e4c38cf1af634dd8600810/testsV2/ut_repyv2api_virtualnamespacecontextsafety.py .