Graham Dumpleton
grahamd at dscpl.com.au
Sat Apr 2 20:25:47 EST 2005
Vampire doesn't use the "imp" module for doing imports and as such the imported modules do not appear in sys.modules. What exactly are you trying to do? Am a bit concerned about the way you might be doing things as it may cause problems with automatic module reloading. If you can give an english description of what you want to do, may be able to suggest a more appropriate way of doing it. That said, you can probably say: module = vampire.ModuleCache().moduleInfo(FileHandler.__module__).module On 03/04/2005, at 11:10 AM, Keerati Inochanon wrote: > Hi, > > I'm getting this exception: > Mod_python error: "PythonHandler vampire" > > Traceback (most recent call last): > > File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line > 299, in HandlerDispatch > result = object(req) > > File "/usr/lib/python2.3/site-packages/vampire/lookup.py", line 641, > in _handler > result = _execute(req,objects[-1]) > > File "/usr/lib/python2.3/site-packages/vampire/lookup.py", line 445, > in _execute > return object(**args) > > File "/home/www/testing/upload.py", line 56, in handler > FileHandler.processUpload(filename, destination) > > File "/home/www/testing/modules/FileHandler.py", line 149, in > processUpload > def getFileHandler(filename, > module=sys.modules[FileHandler.__module__]): > > KeyError: '_vampire_c5f8def7c7c8bbf5b9d75d365a5bbe67_37' > -- > > I'm not sure this it is related to vampire or not, but it seems to > happen when I do module loading through vampire. I tried to run the > same code with python import, and the code was running fine. > > Here is my code snippet: > > FileHandler.py: > ------------------------------ > import os > import sys > import vampire > > config = vampire.loadConfig(__req__, ".vampire") > directory = config.get("Modules", "common") > SessionManagement = vampire.importModule("SessionManagement", > directory) > Settings = vampire.importModule("Settings", directory, __req__) > > class FileHandler: > ... > ... > ... > > class XYZFileHandler: > ... > ... > ... > > def processUpload(filename, directory): > "Process the user-uploaded files" > > def getFileHandler(filename, > module=sys.modules[FileHandler.__module__]): > "Return the file handler class according to the file extension" > > subclass = "%sFileHandler" % > os.path.splitext(filename)[1].upper()[1:] > return hasattr(module, subclass) and getattr(module, subclass) or > FileHandler > > getFileHandler(filename)(filename, directory) > ------------------------------------------------ > upload.py: > from mod_python import apache, util > from mod_python.Session import Session > import vampire > import os > > config = vampire.loadConfig(__req__, ".vampire") > directory = config.get("Modules", "common") > SessionManagement = vampire.importModule("SessionManagement", > directory) > Settings = vampire.importModule("Settings", directory) > FileHandler = vampire.importModule("FileHandler", directory, __req__) > Utility = vampire.importModule("Utility", directory, __req__) > > def handler(req, **kwargs): > ... > ... > FileHandler.processUpload(filename, destination) > ... > ... > > --------------------------------------------------- > What am I doing wrong? Please let me know if you need more > information. Thank you very much in advance. > > Best regards, > Keerati Inochanon > _______________________________________________ > Mod_python mailing list > Mod_python at modpython.org > http://mailman.modpython.org/mailman/listinfo/mod_python
|