[mod_python] Re: Mod_python.publisher behavior - sending .py file tobrowser not processing it in pyton

Graham Dumpleton grahamd at dscpl.com.au
Thu May 4 06:56:17 EDT 2006


On 04/05/2006, at 8:17 PM, Daniel Nogradi wrote:

>> > Just getting started with modpython. And i am not sure if I  
>> understand
>> > the
>> > documentation, specifically section 6.1.2 Publishing algorithm  
>> so I hope
>> > someone can set me straight.
>> >
>> > My setup is on a laptop
>> > Apache/2.0.54 (Win32) mod_python/3.2.8 Python/2.4.1 Server
>> >
>> >
>> > Using mod_python.publisher with the following setup in my  
>> http.conf file;
>> > <Directory "C:\Program Files\Apache Group\Apache2\htdocs\app/">
>> >     SetHandler mod_python
>> >     AddHandler mod_python .py
>> >     AddHandler mod_python .pyw
>> >     AddHandler mod_python .pyc
>> >     PythonHandler mod_python.publisher
>> >     PythonDebug On
>> > </Directory>
>>
>> Running out the door, so can't explain in detail. But you should not
>> be setting both SetHandler and AddHandler. Just use SetHandler and
>> see what happens.
>>
>
> As Graham pointed out SetHandler and AddHandler should not be used at
> the same time. "SetHandler mod_python" causes all files to be served
> by mod_python and when you refer to them in your browser you don't
> need to specify any extension such as .py and "AddHandler mod_python
> .py" causes all files ending in .py to be served by mod_python but in
> this case when referring to a file in your browser you should add the
> .py extension. So if you have
>
> <Directory '/your_document_root/whatever'>
>    SetHandler mod_python
>    PythonHandler mod_python.publisher
> </Directory>
>
> and you have a file /whatever/foo.py with a function bar( ) then in
> your browser you would type http://yourserver/whatever/foo/bar,

When using SetHandler you should still be able to use:

   http://yourserver/whatever/foo.py/bar

Your mileage may vary though depending on how some of the
other bits of Apache configuration are set. See some of previous
rants for possibly useful about this.

   http://www.modpython.org/pipermail/mod_python/2005-August/018828.html
   http://www.modpython.org/pipermail/mod_python/2005-August/018829.html
   http://www.modpython.org/pipermail/mod_python/2006-March/020501.html

> whereas with
>
> <Directory '/your_document_root/whatever'>
>    AddHandler mod_python .py
>    PythonHandler mod_python.publisher
> </Directory>
>
> you would need http://yourserver/whatever/foo.py/bar

As long as you have content negotiation directives set correctly, you
don't have to use .py extension when AddHandler is used. See my linked
rants above for details.

> So it's really up to you which behaviour you like, you want *all*
> files to be served by mod_python or only those that have a specific
> extension and then you set either AddHandler or SetHandler. But not
> both :) And in any case, you certainly don't want your .pyc files to
> be served at all, so you should probably remove "AddHandler mod_python
> .pyc".

If using AddHandler and Apache has write permission to directory, it is
actually a good idea to have:

   <Files *.pyc>
   deny from all
   </Files>

This will prevent the pyc files being accessible.

Using AddHandler for pyc extension will probably actually cause it to
execute the file as publisher, just like if py extension was used.  
This is
because mod_python.publisher will quite happily drop the pyc extension
and use basename to match to .py file.

Besides the fact that AddHandler allows you to mix other file types in
the same directory, the main difference between SetHandler and  
AddHandler
as far as mod_python.publisher goes is that when SetHandler is used a
request against the directory is passed through direct to  
mod_python.publisher
and it resolves request to index.py.

When AddHandler is used, a request against the directory results in  
mod_dir
trying to match for a file listed in DirectoryIndex directive. In  
order for
mod_python.publisher to be triggered, you would need to list index.py
in the DirectoryIndex directive.

Other than that, with the correct Apache directives defined related  
to content
negotiation, both ways should allow for optional use of extension.

Graham



More information about the Mod_python mailing list