[mod_python] Subclassing Session

Thomas J. Schirripa tommys at eden.rutgers.edu
Tue Jul 18 11:39:02 EDT 2006

Before stating my problem, let me say that I am running apache version 2.0.52, mod_python 3.2.8, python 2.3, all on Redhat Enterprise Linux WS release 4.

I am making some basic web utilities that require that I create sessions. Essentially, I want to use session ids created by mod_python to create a session folder where I can temporarily dump files  and manipulate stuff so I can generate some output for the client. Since I would be using this feature a lot, I thought it would be a good idea to make a subclass of BaseSession that added this functionality of making a folder with the session name. I made a file located somewhere else on my machine called SessDirectory.py, and it defines the class SessionDirectory. The file looks like this:

from Session import BaseSession
import os

class SessionDirectory(BaseSession):
	def __init__(self, req, path=None, sid=None, secret=None, lock=1, timeout=0):
		BaseSession.__init__(self, req, sid, secret, lock, timeout)
		if path == None:
			self.absPath = os.path.join(os.getcwd(), sid)
			self.absPath = os.path.join(path, sid)
		os.mkdir(self.absPath, mode=0755)

It can take an absolute path to create the session directory, or it can take no path, in which case it creates the session directory in the current directory. When I try to instantiate the SessionDirectory object, the following exception is raised:

AttributeError: 'SessionDirectory' object has no attribute 'do_load'

I did some fishing around and looked at the source code of the session module. Apparently, BaseSession has a method called "load()" that makes a call to "do_load()". BaseSession does not define "do_load()", HOWEVER, it seems that the built in sublcasses of BaseSession (ie- FileSession, DbmSession, etc) all define a "do_load()" method.

My background is really in Java, and to me, it seems like BaseSession is an abstract class, but it has no signature for "do_load()" and I believe the exception would have been NotImplemented or something like that if there was a required implementation missing. 

Also, why does BaseSession inherit from "dict" and not "UserDict". I wanted to see if "dict" had a "do_load()" method, but if it did, then the instantiation of SessionDirectory should have called the "do_load()" from dict. 

Can anyone tell me what's going on?


More information about the Mod_python mailing list