[web2py] Re: {{code}} compile in view

2012-08-30 Thread lucas
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

[web2py] Re: {{code}} compile in view

2012-08-29 Thread Anthony
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

[web2py] Re: {{code}} compile in view

2012-08-29 Thread lucas
ok, i see the source code for restricted but its use eludes me a bit. how do i grab its executed processed output? --

[web2py] Re: {{code}} compile in view

2012-08-29 Thread Anthony
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

[web2py] Re: {{code}} compile in view

2012-08-29 Thread lucas
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

[web2py] Re: {{code}} compile in view

2012-08-29 Thread Anthony
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

Re: [web2py] Re: {{code}} compile in view

2012-08-29 Thread Bruno Rocha
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

[web2py] Re: {{code}} compile in view

2012-08-29 Thread lucas
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. --

[web2py] Re: {{code}} compile in view

2012-08-29 Thread Anthony
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

[web2py] Re: {{code}} compile in view

2012-08-29 Thread lucas
what using restricted or snapshot? would that be best and is it visible to us normal web2py users? --