Graham Dumpleton
grahamd at dscpl.com.au
Fri Jan 21 05:59:30 EST 2005
On 21/01/2005, at 9:10 PM, Graham Dumpleton wrote: >>> Maybe it shouldn't use an actual req object, but a new object which >>> incorporates some of what req provides, dropping stuff that may be >>> more specific to a particular request. >>> >> Thats my point :-) > > Possibly not complete, but the things from req it would/could have are: > > hlist > interpreter > server > get_options() > get_config() > document_root() > > This means there is nothing which could be used to write data back to > the remote > client. > > Figured I could call it __info__ and not __req__ when populated into > the > namespace of the module when loading. > > ... > > Anyway, having explored this a but, am certainly going to implement > such a > mechanism in Vampire. Okay, all implemented. Took about 2 dozen lines, but I had some extra complexity to deal with related to lookup and caching of configuration files in Vampire. :-) An example content handler I have now starts as: import vampire import types from mod_python import apache if __info__.get_config().get("PythonDebug","0") == "1": apache.log_error("loading",apache.APLOG_NOERRNO|apache.APLOG_ERR) config = vampire.loadConfig(__info__,".vampire") modules = config.get("Modules","common") module = vampire.importModule("python-utils",modules) def handler(req): ... The cut down req object is setup in __info__ just during module import. Here I happen to look for PythonDebug setting from get_config(), but the get_options() is there along with what I listed above. Also did find it necessary to have "filename" and "uri", but this was to support my configuration file search mechanism also illustrated above. It needs to know the physical directory corresponding to the URL so it can search back up the directory hierarchy looking for the named config file. Search stops at the PythonHandler root directory if no config file found. Hard to explain, but using "uri" and "filename" in the context I do here would be fine because of the link back to a physical file in the file system. Now in terms of what I was talking previously about sub imports. The line before the handler function is doing a module sub import. Ie., use the vampire.importModule() method instead of "import". I could have supplied the __info__ variable as additional third argument to the import function and it would have passed access to the cut down req object to the sub import as well. I do have good reasons for all this weirdness, but take too long to explain here. I need to write up some better documentation for Vampire about all its tricky features. :-) BTW, was probably going to be releasing a new version of Vampire this weekend. This will now incorporate this. I just have to decide whether "__info__" is an okay name, or whether another name is more appropriate. Is this looking better? Probably just confusing you. :-) Graham
|