Graham Dumpleton
grahamd at dscpl.com.au
Thu Feb 10 21:02:15 EST 2005
Graham Dumpleton wrote .. > Chris Jackson wrote .. > > If you rename my_script.py to index.py, you can just reference your > > handler like this: > > > > /scripts/my_handler > > Except that calling things "index.py" opens up another big can of worms > if using publisher. See: > > http://issues.apache.org/jira/browse/MODPYTHON-9 > http://issues.apache.org/jira/browse/MODPYTHON-10 > http://issues.apache.org/jira/browse/MODPYTHON-11 > > Although some disagree, mod_python.publisher is broken in a number of > ways and needs a good overhaul. > > Soon maybe I will hack together something to give same style of interface > as publisher on top of Vampire just to show how much better things could > be. Alas, probably no time to do so. :-) Found some time. :-) As an experiment, what I did was to take a copy of mod_python.publisher and simply replace the module loading section with calls to the module loader in Vampire. Result seems to fix all three of the issues listed above and also addresses: http://issues.apache.org/jira/browse/MODPYTHON-8 as well, since Vampire uses a two level locking scheme on the module cache. Use of the Vampire module loading and caching system will however introduce some unexpected differences to what you would get with standard mod_python module loader. The two main ones will be that module reloading cannot be turned off and the second is that data isn't persistent across module reloads unless you take special action. I will not bother going into the details of why these two things are as they are, unless someone actually bothers to play with this. Anyway, below is a patch against the publisher.py file from 3.1.3. You shouldn't just modify your installed "publisher.py" file. Simplest thing to do to experiment is to copy it into your document tree where your handlers are and call it "_publisher.py". Then change SetHandler/AddHandler to "_publisher". Make the changes below to that copy of the file. You will need to get a copy of Vampire. *** /usr/local/src/mod_python-3.1.3/lib/python/mod_python/publisher.py Fri Feb 11 12:42:24 2005 --- _publisher.py Fri Feb 11 12:59:25 2005 *************** *** 28,35 **** 5. Does not give special meaning to '.' and '..'. """ ! import apache ! import util import sys import os --- 28,35 ---- 5. Does not give special meaning to '.' and '..'. """ ! from mod_python import apache ! from mod_python import util import sys import os *************** *** 40,45 **** --- 40,47 ---- import new from types import * + import vampire + imp_suffixes = " ".join([x[0][1:] for x in imp.get_suffixes()]) def handler(req): *************** *** 85,90 **** --- 87,93 ---- suff_matcher = re.compile(exp) # python caches these, so its fast module_name = suff_matcher.sub("", module_name) + """ # import module (or reload if needed) # the [path] argument tells import_module not to allow modules whose # full path is not in [path] or below. *************** *** 110,116 **** except ImportError: # raise the original exception raise et, ev, etb ! # does it have an __auth__? realm, user, passwd = process_auth(req, module) --- 113,137 ---- except ImportError: # raise the original exception raise et, ev, etb ! """ ! ! # XXX ! ! try: ! #module = vampire.importModule(module_name,path,req=req) ! module = vampire.ModuleCache().importModule(module_name,path,req=req) ! except OSError: ! et, ev, etb = sys.exc_info() ! func_path = module_name ! module_name = "index" ! try: ! #module = vampire.importModule(module_name,path,req=req) ! module = vampire.ModuleCache().importModule(module_name,path,req=req) ! except OSError: ! raise et, ev, etb ! ! # XXX ! # does it have an __auth__? realm, user, passwd = process_auth(req, module)
|