[mod_python] transhandler setup?

IR labs labs at ixopusada.com
Tue Aug 30 15:44:15 EDT 2005


Sorry for a late reply.

I feel really silly for my problem, *really* silly. (almost too silly 
to let you all know ...)
After trying all different things in the httpd.conf and not seeing any 
noticeable result, I started thinking it could be having to do with 
apache not reading it after I issued "sudo apachectl restart". And then 
I realized that, after I upgraded to apache 2, to make mod_python work 
decently, I forgot to also change the path to /usr/local/apache2/bin in 
my .profile. DUH... So every time I tried to made a change to apache2's 
httpd.conf and "restarted" I restarted apache 1, ... well, zero points 
for dirk and no desert for a week. :-(

So I got everything working in the end.

But thanks for this solution to have everything (also the stuff we 
don't want to handle) handled by the handler in main.py.
My only remaining question now, would be what you recommend?
1. Don't use the transhandle phase, and have *all* requests handled by 
the main PythonHandler, including the ones it shouldn't handle ( 
apache.DECLINE)
or.
2. Use the TransHandler phase to discern between real physical present 
files (requests for .html, .css, .js etc. files) and virtual pages that 
should be handled by main.py

Thanks,
dirk

On 26-aug-05, at 04:19, Graham Dumpleton wrote:

> If your content handler doesn't want to handle a request, have it 
> return
> apache.DECLINED and Apache will then serve up any static file that may
> have been identified by the URL.
>
>   def handler(req):
>     extension = os.path.splitext(req.filename)[1]
>     if extension == ".html":
>       if not os.path.exists(req.filename):
>         ...
>       else:
>         return apache.DECLINED
>     else:
>       return apache.DECLINED
>
> That is at least one way of doing it, although this will disable
> processing in some cases by other Apache modules such as PHP. You can
> get around that by explicitly disabling use of mod_python for that
> extension:
>
>   <Directory /document/root>
>   SetHandler mod_python
>   PythonHandler main
>   <Files *.php>
>   SetHandler None
>   </Files>
>   </Directory>
>
> Rather than using subtraction, you could instead be additive:
>
>   <Directory /document/root>
>   AddHandler mod_python .html
>   PythonHandler main
>   </Directory>
>
> Thus, if you are only interested in intercepting .html files, only
> have mod_python triggered for them.
>
> In respect of transhandler(), all I can really comment on there is
> that if setting PythonTransHandler, you do not need to use either
> AddHandler or SetHandler. These latter directives only need to be
> used if setting PythonHandler, ie., the content handler. As the
> documentation points out, PythonTransHandler can only be used at
> top level scope, ie., not with a Directory, Location or Files
> directive or in a .htaccess file.
>
> Graham
>
> On 26/08/2005, at 11:57 AM, IR labs wrote:
>
>> Sorry, I haven't been clear. I don't want so much to handle all 
>> requests under a directory. I like to handle all requests in general, 
>> and than first analyze the url. ((If the it is a certain file (.gif, 
>> .jpg, .css, .js) or a certain directory, apache should handle it 
>> further, i.e. just serve that file. If it is just a path or a .html, 
>> I want a python script to check wether the directory or file indeed 
>> exist or not. If the index.html or other .html file doesn't exist the 
>> main.py should take it over.))
>> So I wan't this analysis be done during the transHandler phase. But 
>> how do I make apache run my translate.py first? where do I put my 
>> config lines?
>> PythonPath "sys.path + ['/some/path']"
>> PythonTransHandler translate
>>
>> thx
>> dirk
>

-----------------------------
Dirk van Oosterbosch
dirk at ixopusada.com
-----------------------------




More information about the Mod_python mailing list