Gregory (Grisha) Trubetskoy
grisha at apache.org
Mon Nov 11 15:04:58 EST 2002
I looked at the mod_dir.c code, it looks like if you use SetHandler, DirectoryIndex has no effect, but if you use AddHandler, DirectoryIndex does apply, but the problem is that req.path_info in this case ends up bing None (or NULL) as opposed to a blank string, thus the "Unsubscriptable Object" error. To get around this, try this patch: --- publishre.py.old Mon Nov 11 14:51:44 2002 +++ publisher.py Mon Nov 11 14:50:13 2002 @@ -83,10 +83,12 @@ if req.method not in ["GET", "POST"]: raise apache.SERVER_RETURN, apache.HTTP_METHOD_NOT_ALLOWED - func_path = req.path_info[1:] # skip first / - func_path = func_path.replace("/", ".") - if func_path[-1:] == ".": - func_path = func_path[:-1] + func_path = "" + if req.path_info: + func_path = req.path_info[1:] # skip first / + func_path = func_path.replace("/", ".") + if func_path[-1:] == ".": + func_path = func_path[:-1] # default to 'index' if no path_info was given if not func_path: An imperfection with using AddHandler is that you end up with the ".py" in your URL's. To be able to use the best of both worlds, i.e. SetHandler and a default module, the Publisher needs to provide its own default (since DirectoryIndex has no effect). Here is another patch for this. Most likely these will be in the release version (perhaps slightly modified). This will tell the publisher to default to "index.py" is no file is specified. --- publishre.py.old Mon Nov 11 14:51:44 2002 +++ publisher.py Mon Nov 11 14:50:13 2002 @@ -126,6 +128,9 @@ ## import the script path, module_name = os.path.split(req.filename) + if not module_name: + module_name = "index" # get rid of the suffix # explanation: Suffixes that will get stripped off Grisha On Mon, 11 Nov 2002, Michael C. Neel wrote: > This is an untested guess, but I think apache needs to see "index.py" in > the document root before it will send the client a redirect to > spam.com/index.py - try doing a touch index.py in the doc root and see > what happens... > > Mike > > > -----Original Message----- > > From: Arcady Genkin [mailto:agenkin-lst-mod_python at thpoon.com] > > Sent: Sunday, November 10, 2002 5:11 PM > > To: mod_python at modpython.org > > Subject: Re: [mod_python] Default function for Publisher in 3.0 > > > > > > Arcady Genkin <agenkin-lst-mod_python at thpoon.com> writes: > > > > > this does not seem to work with "DirectoryIndex index.py". > > > > An update: I had a problem with configuration (using AddHandler > > directive instead of the SetHandler, as recommended in the docs). > > However, still can't use index.py implicitely. Now the backtrace > > looks this way: > > > > ,---- > > | Mod_python error: "PythonHandler mod_python.publisher" > > | > > | Traceback (most recent call last): > > | > > | File > > "/usr/local/lib/python2.2/site-packages/mod_python/apache.py", > > | line 335, in HandlerDispatch > > | result = object(req) > > | > > | File > > "/usr/local/lib/python2.2/site-packages/mod_python/publisher.py", > > | line 145, in handler > > | module = apache.import_module(module_name, > > req.get_config(), [path]) > > | > > | File > > "/usr/local/lib/python2.2/site-packages/mod_python/apache.py", > > | line 499, in import_module > > | f, p, d = imp.find_module(parts[i], path) > > | > > | ImportError: No module named > > `---- > > > > The httpd.conf contains the following configuration: > > > > ,---- > > | <Directory "/var/www/data"> > > | PythonDebug On > > | SetHandler python-program > > | PythonHandler mod_python.publisher > > | DirectoryIndex index.py > > | </Directory> > > `---- > > > > Something tells me that I am still doing something wrong. I tried > > setting DIrectoryIndex to "index" instead of "index.py", but this > > still did not work. Any ideas? > > > > Many thanks, > > -- > > Arcady Genkin : CDF Systems Administrator > > http://www.cdf.toronto.edu/~agenkin/contact.html > > > > guilt is the cause of more disauders > > than history's most obscene marorders (E.E. Cummings) > > _______________________________________________ > > Mod_python mailing list > > Mod_python at modpython.org > > http://www.modpython.org/mailman/listinfo/mod_python > > > > _______________________________________________ > Mod_python mailing list > Mod_python at modpython.org > http://www.modpython.org/mailman/listinfo/mod_python >
|