From: Winston W. <st...@ob...> - 2004-12-28 06:38:07
|
Hello Ian- I like your idea of having one servlet that dispatches requests to a=20 bunch of other objects that are not servlets. I'm having a little=20 problem though, with getting the request to go to that servlet and not=20= to the other objects. That's a little hard to read, let me explain it=20= with this diagram: /MyContext/ Main.py (This is my servlet which loads all the files = below it like=20 One.py, Two.py, etc.) One.py (This object is NOT a servlet, it just has an = html() method=20 that returns my HTML text.) Two.py (This is another object with just an html() = method) The idea is that a request to http://myserver/MyContext/One.py should=20 be received by Main.py, and it will: =95 Cut off the extraURLPath, which will be "/One.py" =95 Main loads the MyContext.One.One object and calls it's = .html()=20 method. =95 Main writes that text to the response object and returns. The problem is, how do I get Webware to load and call the Main object=20 as opposed to the One.py object? -winston > But you could build what you are looking for ontop of Webware. Maybe=20= > like: > > class Main(Page): > > def awake(self, trans): > Page.awake(self, trans) > path =3D self.request().extraURLPath() > self.object =3D traverse_path(root, path) > > def writeHTML(self): > self.write(self.object(trans)) > > import base > root =3D base.root_object > def traverse_path(object, path): > if not path: > return object > assert path.startswith('/') > first =3D path.split('/')[1] > rest =3D path.split('/', 2) > if len(rest) =3D=3D 3: > rest =3D '/' + rest[2] > else: > rest =3D '' > return traverse_path(get_part(object, first), rest) > > def get_part(object, attr): > # Maybe use getattr or something else > return object[attr] > > --=20 > Ian Bicking / ia...@co... / http://blog.ianbicking.org > _________________________________________ winston wolff - (646) 827-2242 - http://www.stratolab.com - learning by=20= creating |