[ 
http://issues.apache.org/jira/browse/MODPYTHON-38?page=comments#action_65491 ]
     
Graham Dumpleton commented on MODPYTHON-38:
-------------------------------------------

Adding more to this and why PSP should check for req.form and also set req.form
if it is the first to create the form object, one should look at the 
set_error_page()
mechanism in PSP pages. If setting an error page, and it gets triggered, an
additional instance of the PSP object is created, it will yet again create a 
unique
instance of the form object if a reference to it exists in the page. Again, POST
form parameters will not be preserved.

Related to the form object, one also needs to be careful with the session object
which is created by PSP run() method. If PSP pages were being created explicitly
from a basic content handler or publisher, and the parent was creating a session
object and the PSP code also tried to reference a session object, the code would
deadlock on itself. Even if the parent didn't create a session, if the main PSP 
page
and an error page both tried to access a session object, it would again deadlock
on itself.

Code should perhaps be something like:

        # does this code use session?
        session = None
        if "session" in code.co_names:
            if not hasattr(req,"session"):
                session = Session.Session(req)
                req.session = session

        # does this code use form?
        if "form" in code.co_names:
            if not hasattr(req,"form"):
                 req.form = util.FieldStorage(req, keep_blank_values=1)

        # create psp interface object
        psp = PSPInterface(req, self.filename, req.form)

        try:
            global_scope = globals().copy()
            global_scope.update({"req":req.form, "session":req.session,
                                 "form":form, "psp":psp})
            global_scope.update(self.vars) # passed in __init__()
            global_scope.update(vars)      # passed in run()
            try:
                exec code in global_scope
                req.flush()

                # the mere instantiation of a session changes it
                # (access time), so it *always* has to be saved
                if session is not None:
                    session.save()
            except:
                et, ev, etb = sys.exc_info()
                if psp.error_page:
                    # run error page
                    psp.error_page.run({"exception": (et, ev, etb)})
                else:
                    raise et, ev, etb
        finally:
            if session is not None:
                    session.unlock()

> Passing req.form into psp.PSP().
> --------------------------------
>
>          Key: MODPYTHON-38
>          URL: http://issues.apache.org/jira/browse/MODPYTHON-38
>      Project: mod_python
>         Type: Improvement
>     Versions: 3.1.4
>     Reporter: Graham Dumpleton
>     Priority: Minor

>
> When calling psp.PSP() explicitly to render PSP pages, it will internally 
> setup
> req.form if it determines that the form is accessed by the PSP page.
> Problem is that if you are wanting to trigger psp.PSP() from a publisher 
> function
> any form parameters have already been processed and req.form created. For a
> POST request this is problematic as in doing this it will have consumed all 
> the
> content of the request.
> This means that when the form is processed a second time by psp.PSP(), it will
> find no request content. Thus, the PSP page will only be able to make use of
> GET form parameters and not POST form parameters.
> It would be an improvement if psp.PSP() allowed a instance of 
> util.FieldStorage
> which has previously been created to be passed in through the "form" parameter
> of the constructor. Ie.,
>     template = psp.PSP(req,filename=path,vars=settings,form=req.form)
>     template.run()

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to