[jToolkit-cvs] jToolkit/web __init__.py,1.4,1.5
Brought to you by:
davidfraser,
friedelwolff
|
From: <dav...@us...> - 2003-10-14 08:25:59
|
Update of /cvsroot/jtoolkit/jToolkit/web
In directory sc8-pr-cvs1:/tmp/cvs-serv18595
Modified Files:
__init__.py
Log Message:
factored out getserver which does the import of the instance etc. and creates a server
also added error checking code into the import
Index: __init__.py
===================================================================
RCS file: /cvsroot/jtoolkit/jToolkit/web/__init__.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** __init__.py 29 Sep 2003 07:47:11 -0000 1.4
--- __init__.py 14 Oct 2003 08:25:55 -0000 1.5
***************
*** 19,22 ****
--- 19,24 ----
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ import sys
+
# list of modules in this package
__all__ = ["safeapache", "server", "session"]
***************
*** 55,66 ****
pass
! # handler is in here so that we can say PythonHandler jToolkit.web
! # (modpython automatically looks for handler in that module)
! def handler(req):
! """the standard handler which locates the instance, creates the server if neccessary, and hands off to it"""
! logtime('handler start: ' + req.uri)
! apache_options = req.get_options()
! modulename = apache_options['jToolkit.module']
! instancename = apache_options['jToolkit.instance']
fullinstancename = modulename + "." + instancename
if fullinstancename in servers:
--- 57,62 ----
pass
! def getserver(modulename, instancename):
! """returns a server based on a given instance in a given module"""
fullinstancename = modulename + "." + instancename
if fullinstancename in servers:
***************
*** 68,78 ****
else:
# this is equivalent to: from modulename import instancename
! module = __import__(modulename, globals(), locals(), [instancename])
# get the actual instance
! instance = getattr(module, instancename)
# construct a server of the appropriate class using the instance
server = instance.serverclass(instance)
server.name = fullinstancename
servers[fullinstancename] = server
pathwords = filter(None, req.uri.split('/')) # split into bits, strip out empty strings
logtime('calling server.handle: ' + req.uri)
--- 64,95 ----
else:
# this is equivalent to: from modulename import instancename
! try:
! module = __import__(modulename, globals(), locals(), [instancename])
! except ImportError, importmessage:
! errormessage = "Error importing module %r: %s\nPython path is %r" \
! % (modulename, importmessage, sys.path)
! raise ImportError(errormessage)
# get the actual instance
! try:
! instance = getattr(module, instancename)
! except AttributeError:
! errormessage = "module %r has no attribute %r\nmodule is %r, attributes are %r\nPython path is %r" \
! % (modulename, instancename, module, dir(module), sys.path)
! raise AttributeError(errormessage)
# construct a server of the appropriate class using the instance
server = instance.serverclass(instance)
server.name = fullinstancename
servers[fullinstancename] = server
+ return server
+
+ # handler is in here so that we can say PythonHandler jToolkit.web
+ # (modpython automatically looks for handler in that module)
+ def handler(req):
+ """the standard handler which locates the instance, creates the server if neccessary, and hands off to it"""
+ logtime('handler start: ' + req.uri)
+ apache_options = req.get_options()
+ modulename = apache_options['jToolkit.module']
+ instancename = apache_options['jToolkit.instance']
+ server = getserver(modulename, instancename)
pathwords = filter(None, req.uri.split('/')) # split into bits, strip out empty strings
logtime('calling server.handle: ' + req.uri)
|