Alan Kennedy
modpython at xhaus.com
Tue Jan 8 21:30:45 EST 2002
Rob, Bingo! That hit the nail square on the head, and drove it right home! Excellent! I obviously didn't read the documentation thoroughly enough. It states in section 5.1.3 about PythonTransHandler: "This routine gives allows for an opportunity to translate the URI into an actual *filename*" [my emphasis]. That's filename, NOT uri. I mixed it up, and tried to modify the request URI, which is a read-only attribute. Hence why I couldn't get it to work :*) Many thanks for clearing this up. This means that I can forge ahead and rewrite URLs to contain session IDs, without having to resort to "?sess=xyz" style query parameters. Thanks again. Alan. Robert Sherwood wrote: > Hi, > > Transhandler translates a request from a URL to a filename. Though you > can rewrite a URL, I found it was easier simply to use the URL that I > had, particularly since, In my case, I could count on the argument order > and such. > > This is an extremely simple example, but I wanted to set the file > request to main.py, which handled all the URL processing itself. The > important thing to remember is that the TransHandler figures out which > file you're requesting based on the URL you pass in. It can obviously do > any processing you need, but that is it's primary function. > > from mod_python import apache > import string > > def transhandler(req): > #We want to use main.py > req.filename = "main.py" > return apache.OK > > Again, I didn't use mod_python to process the URL, that is done by the > main Python Handler, as below (adapted slightly for your situation): > > def handler(req): > #remove trailing slash, if present > URI = req.uri > if URI[len(URI)-1] == '/': > URI = URI[:len(URI)-1] > > #disassemble the URI for processing > components = string.split(URI,'/')[1:] > > sessionID = components[0] > > command = components[1] > > what = components[2] > > # Do stuff here > > There's no error checking or anything, but I found it was easier to use > the request as it came in, rather than rewriting it and processing that. > However, I had to use the TransHandler to set the request filename to > the script that did the processing. > > Hope this helps. > > Rob
|