Has anyone thought about adding servlet-type files to Spyce? Assuming
a person want to access the Spyce environment (request, response,
session, redirect, etc.), (s)he has to use a .spy file. I'm not
counting Spyce modules because, while they have access to the
environment, they also must be called from a .spy file.
I'm proposing the addition of .spo (or whatever) file (spo for SPyce
Object) that can be called directly from a web url, similar to
servlets. The .spo file is an extension to regular Spyce modules that
contains a class.handle_request(request, reponse, modules, ...) method.
A snippet from a .spo-type file would be as follows:
def handle_request(request, response, ...):
print '<html><body>Hello World</body></html>'
Different from the servlet framework, though, is the location of the
.spo files. I would suggest we let .spo files live in the web
directories alongside the .spy files. The difference is really just
semantics. Sometimes people want to program from a method-based
approach (e.g. python cgi) and sometimes they want to program from an
html-based approach. I submit that the two can and should often exist
in the same project.
Why not use regular python CGI? Because python CGI doesn't have access
to the spyce environment. I want to be able to use the request and
response objects. For MVC apps (which I'm writing right now) I need to
use the redirect module to a .spy file at the end of the handle_request
method. Further, we cant' use the .py extension because most web
servers already map .py to non-spyce, python cgi.
Why not use Spyce modules as they are? Because Spyce modules aren't
callable directly from a URL (they must be called from a Spyce web
page). In addition, (from what I can see) they only have access to
loaded modules and can't load modules themselves. Finally, they
normally exist in a separate directory and not in the web directory.
If these drawbacks could be rectified, I'd support simply modifying
spyce modules to make them callable directly.
I realize a primary design goal of Spyce is "feature poor". However,
let me argue that servlet-type files are needed in Spyce. Any major
framework should support the MVC pattern of separating business logic
from viewing code. If Spyce is to see wide adoption, it should support
this best-practices method of writing web sites. *People are going to
expect it, especially if they are coming from Java or .NET or Webware
or Zope.* Simply embedding all logic into the html pages is a poor
way to design a large site. Some might argue that Spyce modules fill
this role, but Spyce modules still have to be embedded in .spy files,
and are, therefore, dependent upon a non-MVC model. They current
method of using MVC in Spyce is at best a clever hack.
I've been mucking around in the code and modified the spyce.py file a
bit to support it (specifically, the spyceFileCacheGenerate method). I
almost have it working, but it is a bit of a hack and shouldn't be
included in the main tree. I'm wondering if anyone else has done this
or, if Rimon would consider adding it himself. Or, perhaps I'm just
missing a feature somehow and will be quickly told so. :)
Conan C. Albrecht, Ph.D.
Brigham Young University