[mod_python] Strange request.parsed_uri

Graham Dumpleton grahamd at dscpl.com.au
Wed Jan 26 16:03:26 EST 2005


On 27/01/2005, at 1:07 AM, Igor Stroh wrote:

> myHandler.py:
> ===============================================================
> from mod_python import apache
> def handler(REQUEST):
>    REQUEST.conditions = "text/plain"
>    REQUEST.send_http_header()
>    REQUEST.write("Parsed URI: %s\n" % str(REQUEST.parsed_uri))
>    return apache.OK
> ===============================================================

Can't help you on the parsed_uri stuff right this minute, but just
a suggestion about the handler and what possibly can be seen as
"best practice".

Instead of using "REQUEST", always use "req".

The reason for this is that if you ever decided to switch your code
to using mod_python.publisher, the "req" name is a bit magic and
must always be used as the parameter name for the request object.

This is because in mod_python.publisher, any form parameters will
be matched against the method parameter names. In doing this, the
req object is still available to be passed in, but will be passed in
only through a parameter called "req".

Thus, maintaining this convention might save you some confusion
later.

This is mainly from memory, although I had a quick check at the
code as well. Someone please correct me if I am wrong, especially
after that last stuff up I made. :-)

Graham




More information about the Mod_python mailing list