Running CGI from within CGI

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Thu Feb 14 10:33:38 EST 2008


rodmc a écrit :
(top-post corrected - rod, please learn to quote, thanks !-)

> On Feb 14, 3:26 pm, Bruno Desthuilliers <bruno.
> 42.desthuilli... at wtf.websiteburo.oops.com> wrote:
>> rodmc a écrit :
(snip)
>>> However I would like to execute a script instead so calling for
>>> example myscript.py - thus populating the existing forms with data.
>>> This does not seem to work when I modify the above method. Is there
>>> another way to do it? Thanks in advance.
 >
>> The QuickAndDirtyWay(tm) would be to use execfile IIRC. But since you
>> *don't* want to do it that way, the best thing to do would be to factor
>> out common code into functions in a distinct module (or in as many
>> modules as needed), then rewrite your cgi scripts so they import the
>> relevant modules and call the appropriate functions.

 > Thanks for the details, is execfile full of security issues or
 > something?

I don't think it has any peculiar problem wrt/ security, but it's plain 
butt-ugly, and certainly a nightmare when it comes to readability and 
maintainability.

FWIW, I never ever used execfile myself. My scripts (I mean, the .py 
intended to be use as 'entry points', either on command line, CGI or 
whatnot) have very few code at the top-level, almost only imports, 
functions / classes / symbols definitions, and the canonical guard for 
the effective entry point, ie:

# somescript.py
<imports here>
<globals and constants here>
<classes and/or functions here>

if __name__ == '__main__':
   # been called as script, not imported as module, so let's proceed
   <handle sys.args and whatnot>
   <call relevant functions>
   <output something>



HTH

(snip about templates, not relevant here)



More information about the Python-list mailing list