[mod_python] using mod python without calling the function

Graham Dumpleton graham.dumpleton at gmail.com
Tue Dec 23 17:27:27 EST 2008


2008/12/24 David Jackson <davidj411 at gmail.com>:
> is this the section of docs you wanted me to review?
> "If req.filename is empty, the module name defaults to 'index'.

I am not even sure that is technically correct, as req.filename
shouldn't be empty.

If SetHandler is used and req.filename references a directory, then it
would look for index.py file in that directory.

> Once module is imported, the remaining part of the URI up to the beginning
> of any query data (a.k.a. PATH INFO)
> is used to find an object within the module. The Publisher handler traverses
> the path, one element at a time from left
> to right, mapping the elements to Python object within the module. <-this
> sentence is lost on me

This is a rather fundamental aspect of mod_python.publisher. If you
don't understand it, you may perhaps want to use something else. This
is because if you don't understand this bit, you would likely not
understand all the security implications in how you name code you
stick in a publisher .py file. Result is that you could expose a lot
of your code to access when you didn't mean to.

What it in effect means is that the first name (between slashes) in
URL is mapped to global variable in .py file of same name. If there is
a second part to URL, that is then in turn mapped to sub attribute of
that global variable and so on for each part of the URL. All parts
have to be satisfactorily mapped else you will get not found.

> If no path info was given in the URL, the Publisher handler will use the
> default value of 'index'. If the last element
> is an object inside a module, and the one immediately preceding it is a
> directory (i.e. no module name is given), then
> the module name will also default to 'index'."

This is the bit you care about. Just add a function called 'index()'
to your .py file and it will be called when no function is explicitly
named in the URL.

See also perhaps:

  http://webpython.codepoint.net/mod_python_publisher_handler

> as for the versions of python that work with mod_python:
> os:winXP
> loading (win32 pre-compiled modules, not compiling apache.
> mod_python gives error during windows installation if it can not find
> registry entry for python 2.5.

But for which version of Python was the mod_python compiled for. It
has to match what you have installed.

Further, the Python and Apache installations should really be
installed as an Administrator and not an unprivileged user.

> i was unable to find a binary mod_python MSI installer that would work for
> python 2.6.

That is because there is no mod_python binary installer for Python 2.6
that I know of.

> if there is a binary ready to download, please advise on download location.

Compiling from source is only option unless someone else can supply
you prebuilt binary.

> regarding 2.5.2 versus 2.5, i rolled back to 2.5.0 when i saw this in the
> error.log
>
> [Tue Dec 23 11:51:00 2008] [error] python_init: Python version mismatch,
> expected '2.5', found '2.5.2'.
> b/c of this, i was not sure how well it would work , especially with my
> being new to mod_python.you answered that this error message means nothing.
> thanks!

If it was expect 2.5 but found 2.6, then it wouldn't work, but if only
patch level revision difference, should be okay on Windows.

Graham

>
> On Tue, Dec 23, 2008 at 3:19 PM, Graham Dumpleton
> <graham.dumpleton at gmail.com> wrote:
>>
>> 2008/12/24 David Jackson <davidj411 at gmail.com>:
>> > if using this config:
>> > <...snipped>
>> >   SetHandler mod_python
>> >  PythonHandler mod_python.publisher
>> >         PythonDebug On
>> > </Directory>
>> >
>> > do i always need to call the function in the URL?
>> >
>> > for example, testscript.py has a function called "writename".
>> > must i call testscript.py using
>> > http://localhost/pycgi/testscript.py/writename or could i add something
>> > to
>> > the contents of the file like you can when testing a script from command
>> > line like this:
>> >
>> > if __name__=="__main__":
>> >      writeback(names)
>> >
>> >
>> > basically, i am trying to avoid putting the function name into the URL.
>>
>> Look up how the 'index' function works in the documentation.
>>
>> > also, i noticed that the newest version of mod_python ONLY supports
>> > python
>> > 2.5.0. i had errors with 2.5.2
>>
>> What platform, what errors and is this compiling it from source code?
>>
>> There have not been any problem reports saying it doesn't work with
>> Python 2.5.2.
>>
>> If using precompiled binaries, for Python 2.5 you may see warnings
>> about a version mismatch at runtime in error logs, but that can be
>> ignored.
>>
>> > and would not install with python 2.6.
>>
>> Again, what platform, what errors and is this compilng from source code?
>>
>> There have not been any problem reports saying it doesn't work with Python
>> 2.6.
>>
>> Graham
>
>


More information about the Mod_python mailing list