durusmail: quixote-users: _q_resolve vs direct call of method
_q_resolve vs direct call of method
2005-04-20
2005-04-20
2005-04-20
2005-04-20
2005-04-20
_q_resolve vs direct call of method (re-post)
2005-04-20
_q_resolve vs direct call of method
Jason Sibre
2005-04-20
Quoting R J Ladyman :

> Here's something that I think I must be misunderstanding.
....
>
> Then calling http://.../testconvert results in the set_content_type call only
> being called the FIRST time, thereafter the call will always the value of
> sreturn but NOT issue the 'print' command.
>
> If, however I use http://..../dotestconvert then set_content_type (and the
> preceeding print command) IS called.
>
> What am I missing here?
> --
>
> Robert Ladyman


_q_resolve should return the object that needs to be called.  Once returned, the
publisher will 'cache' the result that the call to _q_resolve returns, in the
appropriate namespace, and in future requests, _q_resolve won't be called.  If
you were running in CGI, it would be called for each request, because the
process dies after handling the request, but in an LRP environment (SCGI, FCGI,
mod_python, etc), it'll only be called once.  You probably want _q_lookup
instead.
_q_resolve is really intended for situations where, for example, you have a
module that you don't want to import until it's needed, because it takes a
while to import.  _q_resolve would import the module, and then return the
reference to the module.

You may want to look at the source in publish.py, and see how _q_resolve and
_q_lookup differ.  That should clear things up for you.

Note that even with _q_lookup, you generally want to return the reference that
should be called, not the result of that call..
i.e.:
  return dotestconvert
rather than
  return dotestconvert(get_request())

The publisher, seeing it got a callable back, will call it for you.

Jason

reply