[Zope-dev] RestrictedPython - inserting variables before doing exec(code)
Russ Ferriday
russf at topia.com
Wed Nov 3 16:07:06 EDT 2010
Apologies for the noise.
Brain in gear....
--r.
Begin forwarded message:
> From: Russ Ferriday <russf at topia.com>
> Date: November 3, 2010 12:47:33 PM PDT
> To: zope-dev <zope-dev at zope.org>
> Subject: RestrictedPython - inserting variables before doing exec(code)
>
> Good day!
>
> Refs:
> http://pypi.python.org/pypi/RestrictedPython
>
> I want to pass existing bound variables into the environment of some restricted code before running it.
>
> This is similar to when globals are passed to compile_restricted_function.
>
> The idea...
>
> x = 42
> y = 'foo'
> src="""print x*2; print y; return printed"""
> code=compile_restricted(src, '<string>', 'exec')
> code.global['x'] = x # <- just dreaming, here.
> code.global['y'] = y # <- just dreaming, here.
> ans = exec(code) in restricted_globals
> print ans # prints "84\n'foo'\n"
>
> It's clear that passing in arbitrary objects is not feasible. But what if I'm prepared to constrain input to built-in numeric and string types, possibly in or with nested dicts?
>
> In many cases the input will be large integer or float arrays, and I want to avoid any nasty
> kludge such as printing those inputs into the top lines of the src ;). The src in the demo is a constant,
> but in the application, it's provided by users via a list of pre-defined and user-created 'macros'.
>
> If I'm missing something obvious, flames welcome!
>
> --r.
>
> Russ Ferriday --
> CEO Topia Systems Ltd.
> russf at topia.com -- +1 (805) 910 7877 -- www.topia.com
>
>
>
>
>
>
>
>
Russ Ferriday -- Systems Architect & Entrepreneur
CEO Topia Systems Ltd.
russf at topia.com -- +1 (805) 910 7877 -- www.topia.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zope-dev/attachments/20101103/1792c291/attachment-0001.html
More information about the Zope-Dev
mailing list