| License |
Perl Artistic License (c) 2008 Fred Morris, Seattle WA USA |
| Author |
Fred Morris/Fred Morris Consulting http://www.inwa.net/~m3047/data-services.html |
| Version |
version 1.1, 23-Feb-2008 |
This is a toolkit for quickly producing HTTP-based middleware.
Everything is intended to be fetched with HTTP: templates and data
services alike.
This means that hosting arrangements can be very flexible, and
responsibility for the required components can be distributed: a
designer can work up semi-functional mockups and those can be
immediately pulled in and utilized to actually produce output. Somebody
else can work on the data services.
There is nothing fancy about it. It's self-contained, and if you
need an HTML/XML parser or templating language with more features then
you can extend this or go to the trouble of picking (and learning) a
tool with more features.
("TMTOWTDI" is the abbreviation for the Perl aphorism "There's more than one way to do it".)
The two examples here are both going to assemble new web pages from the same three templates:
The two examples are:
There is a slight difference in the resulting output. In the latter example anything between the %%inner%% and %%inner2%% tags is discarded. (This was done intentionally, to demonstrate that they are different techniques.)
The other nice thing to be able to do is to render data from a data source. We assume you're going to use REST/XML data sources:
Here is an example of that:
There is a limited (and hopefully easily understandable) form of
asynchronous fetching. There is a logical point in request processing
referred to as "The Gate": fetches which happen before The Gate can be done asynchronously, while fetches which happen after The Gate are always performed synchronously. Processing flow waits at The Gate until all asynchronous template and data fetches have completed.
This mode is turned off by default, but can be enabled on a per-handler basis.
As demonstrated by nested.cgi, SnakeStation supports insertion of sub-handler content into an outer template. There two insertion modes and three insertion locations which can be combined in different ways:
SPLITTER) must match exactly.You are encouraged to look at the source, of course!
handlers.pyGeneric - The base handler class from which all others are intended to be derived.Nester and Inner - Base classes from which nested handlers are intended to be derived.TemplatedHTMLFinder - Base class from which classes which render from data sources are intended to be derived.components.pyRequest - More or less a do-nothing subclass of the cgi.FieldStorage class, which encapsulates request information.Response - Encapsulates a CGI response.ErrorResponse - A default error response.InnerResponse - A response class for use by output which is going to be rendered by replacement into a different response.dataclient.pyXMLResponse - Encapsulates the response from a service request where the data comes in in XML format.RESTRequest - Encapsulates a service request which is sent in REST format.utils.pyTagged - An extension of the built-in Python str class which helps with taking a bite out of an XML/HTML document.It unpacks as a directory structure which mimics the demonstration site. Alternately you can move the cgi-bin/snakestation/ directory to your Python distribution directory.
.pyc filesYou don't need mod_python. However Python scripts do run faster when they can be compiled into .pyc
files. This means that immediately after installation, or if you make
any updates, your web server needs write access to the directories so
that the .pyc files can be regenerated in its context.
Shebang lines aren't even required in all cases. However there are shebang lines in these source files, and they refer to /usr/bin/python. You may need to change them or create a symlink to your actual Python interpreter.
More detailed revision information is included in the source files.
Asynchronous template and data requests. Subhandler injection now
supports regular expressions, and before/after insertion as well as
replacement.
Initial release.