Graham Dumpleton wrote:
Graham Dumpleton wrote:
Unfortunately you can't do that as all Python request objects in that
chain are created fresh for the handler which is the target of the
internal redirect. When the internal redirect returned, the cached
would then be actually different to the original. It would still return
the same underlying Apache data, but any extra stuff added to the
request object from Python code wouldn't be accessible.

The cleanup routine gets called at the end of each request, so I don't think that's an issue that couldn't be resolved with the method I was describing. Perhaps I was being too simplistic in my example to fully explain what I was thinking, though.

But in any case, I think the problem could be solved much more simply by changing the following code:

    def set_req(self, req):
        prev_req = self.local.req
        self.local.req = req

        def free_req():
            self.local.req = prev_req
        req.register_cleanup(free_req)

That should take care of restoring the previous "cached" request object without explicitly creating a stack (i.e. relying on the Python call stack to bind local variables in the closure).

Nick

Reply via email to