ok, i am stuck. i have studied run_controller_in and restricted and i
tried some test code attempts and i am stuck. so here is some sample code:
xx2 = """
def lucas53():
harry = (4+16)/2
rtn = dict(harry=harry)
return rtn
"""
and under a web2py controller function:
env = {}
exec xx2 in e
It executes the code in the environment passed to it. If the code adds
objects to the environment, you can grab them from the environment after
execution. Look at the run_models_in, run_controller_in, and run_view_in
functions in compileapp.py to see how it is used.
Anthony
On Wednesday, Augus
ok, i see the source code for restricted but its use eludes me a bit. how
do i grab its executed processed output?
--
Got it. In that case, you can still use exec -- you probably want to wrap
it in a try/except. Here's what web2py does to execute all model,
controller, and view code (using the restricted() function in
restricted.py):
try:
if type(code) == types.CodeType:
ccode = code
yes, you're right, i should be more clear sorry. consider two text fields
in a table. one is called view and the other controller. the view has the
similar syntax we are used to, it is just stored in the table and row. and
the controller, i want to be able to allow myself to enter any type o
On Wednesday, August 29, 2012 12:14:24 PM UTC-4, lucas wrote:
>
> ok, that is fine for simple code execution, but what of the more complex?
> how does web2py execute all of that complex code we can embed within a
> view? that is what i want to reproduce in my scheme.
>
exec code in environment
You can use template render
from gluon.template import render
html = "{{=name}} {{for x in range(10)}} Hello {{pass}}"
print render(content=html, context=dict(name="Bruno"))
On Wed, Aug 29, 2012 at 1:14 PM, lucas wrote:
> ok, that is fine for simple code execution, but what of the more comp
ok, that is fine for simple code execution, but what of the more complex?
how does web2py execute all of that complex code we can embed within a
view? that is what i want to reproduce in my scheme.
--
You could use the Python exec command to execute the code, but if any of
the code comes from users, this is a very bad idea, as any malicious code
(or even a mere mistake) could do a lot of damage.
Anthony
On Tuesday, August 28, 2012 11:36:54 PM UTC-4, lucas wrote:
>
> hello one and all,
>
> i
what using restricted or snapshot? would that be best and is it visible to
us normal web2py users?
--
10 matches
Mail list logo