On Tue, 2003-07-29 at 04:36, paul.boddie@... wrote:
> I know that this is "done and dusted" already, but I also think that this is
> a great idea. You may have seen a patch I submitted which attempts to allow
> Webware contexts to have "virtual resources" in much the same way that
> mod_python doesn't care what the requested resource is called as long as the
> extension is the one mapped to the specified mod_python handler. My patch
> does an inelegant workaround with respect to caching, and it also has to
> suppress the insistence that real files exist for every requested resource -
> something which certainly is useful in many situations (eg. checking
> modified times against active servlets), but is obstructive or unnecessary
> in other situations (eg. "virtual resources").
This actually doesn't handle virtual resources. Unlike mod_python,
URLParser adds the extension itself, so it has to have a filesystem to
search. The assumption of a file is carried on into ServletFactory, at
least into the caching that is performed.
If you want to use virtual resources you'd have to put a sub-parser in
the path somewhere (probably in an __init__.py file), like:
def __init__(self, rootObj):
self.rootObj = rootObj
def parse(self, trans, requestPath):
# URLParser needs a helper function here...
splitted = requestPath[1:].split('/', 1)
first = splitted
rest = '/' + splitted[1:]
rest = ''
# now we get to do interesting things...
# More access controls are probably called for
dest = getattr(self.rootObj, first)
return SubParser(dest).parse(self, trans, rest)
Hmm... that's assuming you are traversing a bunch of threadsafe
servlet-like objects, which is an unlikely scenario. The factory only
comes in indirectly, by changing that last line -- in a more likely case
you'd probably be wrapping the final object in a servlet class. Which
is what a factory does...
I don't know, it's not all thought out yet.