[mod_python] how to define publisher when page not found

Maksim Kasimov maksim.kasimov at gmail.com
Tue Jan 16 05:07:42 EST 2007


On 1/15/07, Graham Dumpleton <grahamd at dscpl.com.au> wrote:
>
> Maksim Kasimov wrote ..
> > hi,
> >
> > in apache conf file i use:
> >
> >     <Directory "/mypath/mydir">
> >         SetHandler python-program
> >         PythonHandler mod_python.publisher
> >     </Directory>
> >
> >
> > there is file:
> >
> > in file  /mypath/mydir/index.py there some functions:
> >
> > def index(req):
> >
> >     return "index"
> >
> >
> > def free(req):
> >
> >     return 'free'
> >
> >
> > def not_found(req):
> >
> >     # some computation
> >     return 'page not found'
> >
> >
> >
> > and every thing is just fine and works as expected:
> >
> >        for http://myhostname.org/mydir/free i can see "free"
> >        for http://myhostname.org/mydir/ i can see "index"
> >
> >
> > my question is: How to get output of "not_found" function for any other
> > uri,
> > such as "http://myhostname.org/mydir/hello" ?
> >
> > many thanks for any advice.
>
> Use the Apache ErrorDocument directive, specifying the URL to the
> not_found
> function as the argument.
>
> Graham
>

it is very inconveniently because:
    1) in the directory "mydir" there can be a lot of *.py scripts (not only
index.py), and i need to specify some default handler for each of module in
the directory.
    2) it makes superfluous redirections
So my question is still opened.

To provide this, temporary, i've changed resolve_object function in
publisher.py from mod_python in that way:

        try:
            #obj = getattr(obj, obj_str)
            obj = getattr(obj, obj_str, getattr(obj, '_default'))
        except AttributeError:
            raise apache.SERVER_RETURN, apache.HTTP_NOT_FOUND

than, i will define _default function in my /mypath/mydir/index.py or any
other modules in mydir.

i think it is very wrong to change standart libraries, but i did not found
the way, how to redifine this behavior in my index.py file.

is it possible to define some function in my module, to make it return
default attribute for getattr function?
or may be, if i dare, to expect such changes as above in future releases of
mod_python?

thanks for any help.

-- 
Maksim Kasimov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20070116/167ade24/attachment.html


More information about the Mod_python mailing list