Sean Reifschneider
jafo at tummy.com
Mon Jun 9 23:59:27 EST 2003
I've been trying to build a web application system using mod_python, and I've been running into some weirdness. Some of it is just sporadic behavior, some of it seems to be pretty consistent. Before I get started, my main development system is running Red Hat 9 with Python 2.2.2 and I've been trying mod_python 3.0.1 (shipped with RH9) and 3.0.3. Basically, I'm building up a package that contains my system. In it I have a module which contains my handler: AddHandler python-program .html PythonHandler jotweb.jotweb_mod_python::handler Basically, my handler is using SimpleTAL to parse some HTML, which will result in my code getting called, which will import things from the jotweb package: fileName = path + '.py' fp = open(fileName, 'r') module = imp.load_source(path, fileName, fp) So, basically, I am trying to load a module from a specific file. The first problem I'm seeing is that imports are just weird. For example, if I have code which does "import jotweb.input.Request", unless my __init__.py in jotweb/input includes: import Request I will get an error to the effect that the module object contains no element "Request". Of course, from a regular Python program, I can do "import jotweb.input.Request" just fine either way. Basically, because of the above, my entire code-base has to be imported when you do an "import jotweb". Further, I'm running into weird issues with headers_out. If from my jotweb_mod_python.handler code I do: req.headers_out.add('key', 'value') it will properly add the specified header. And if this code is executed from the module that is imported as above, it seems to work. If, however, in this imported module I do: import jotweb jotweb.auth.Sessions.processLogin() where "processLogin()" gets a handle to the request object and does req.headers_out.add(), the headers aren't showing up in my browser. HOWEVER, if I telnet to port 80 and issue a GET request to exactly the same URL that I issued in the GET request, the headers are *NOT* getting return as far as I can tell (no cookie is getting set, doing "View Documenat Information" shows not those headers, but if I set headers in my main mod_python handler, it WILL show it. I've verified that the call to headers_out.add() is happening by adding a syslog before it, it's definitely calling that code. It seems like at some point something is making it so that headers_out.add() doesn't work any more. Would pulling the form data out of the request cause that? Any thoughts on why the imports seem to work quite differently on a name-space basis from how they happen from the interpreter: AttributeError: 'module' object has no attribute 'input' Is there something about being in mod_python that makes it a "toy" interpreter in some ways, that mean I'm constantly going to be bumping into weird things? Thoughts? Thanks, Sean -- I like to be different, so I built a lowercase a-frame house. -- Sean Reifschneider, 2000 Sean Reifschneider, Inimitably Superfluous <jafo at tummy.com> tummy.com, ltd. - Linux Consulting since 1995. Qmail, Python, SysAdmin
|