On Mon, Apr 08, 2002 at 02:43:37PM -0400, Geoffrey Talvola wrote:
> > My first attempt failed because line 183 of ServletFactory is:
> > assert issubclass(theClass, Servlet)
> > Anyway, I'd like to argue for the removal of the assertion in
> > ServletFactory, since it is denying use of a very powerful,
> > and arguably
> > better technique than inheritance. In any case, assertions
> > can be optimized
> > away in .pyo files, so that the presence of the assertion
> > statement is of
> > questionable value...
> I think the assertion is there to help out the Webware user who forgets to
> have their servlet inherit from Servlet. I assume that mistake happens
> relatively frequently. I know I've done it once or twice. Without the
> assertion (which pinpoints the problem pretty clearly), presumably you would
> wind up with a traceback somewhere else in the guts of Appliction.py that
> would be less obvious to track down, especially for a casual user.
> Now you've identified a legitimate use for a servlet not derived from
> Servlet. So you want to remove the assertion, but that would hurt casual
> Webware users hwo might forget the base class. So maybe there should be an
> option "AllowServletsNotDerivedFromServlet" that defaults to 0, but you can
> just flip the switch and it skips the assertion? I would imagine this to be
> documented as "for experts".
If a servlet must always subclass Servlet, or at least we pretend to
require that for the default case, the exception should be changed from
AssertionError to something else. AssertionError mean "I" made an
error. Other exceptions mean "you" made an error.
But perhaps we need to rethink what are the requirements for servlets.
At minimum, awake/respond/sleep methods. This sounds like an interface.
Since Python doesn't have interfaces (yet), we've been using "must be a
subclass of Servlet" as a substitute.
The simplest way to avoid the issubclass test and yet not introduce an
esoteric option like AllowServletsNotDerivedFromServlet would be to
test explicitly for the required features:
if not hasattr(theClass, 'respond'): raise RuntimeError(...)
if not hasattr(theClass, 'respond') or \
type(theClass.respond) != types.MethodType:
requiredMethods = 'awake', 'respond', 'sleep'
for methMame in requiredMethods:
meth = getattr(theClass, methName)
if type(meth) != types.MethodType:
raise RuntimeError("not a method...")
raise RuntimeError("method doesn't exist...")
-Mike (Iron) Orr, iron@... (if mail problems: mso@...)
http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol