An idea - request for comments

Nigel Head nhead at houbits.com
Wed Aug 4 04:03:25 EDT 1999


Ian Clarke wrote:

> I am presently working on a CGI based system in Python, and the
> experience gave me an idea for a simple Python program, I would
> appreciate any comments (such as "don't bother, it's been done" or
> "sure, I have loads of spare time, I will do it and release it under the
> GPL").

I'm not going to say either of those! I have done it, although I'm not
terribly happy with the results so far and it's on the back burner for
the moment .... I need to figure out if it's still useful in a Zope
world - which means I have to learn and understand Zope!

> It is to create a Python web server which automatically parses embedded
> Python in HTML (there is a Perl extension that does this too).  So, for
> example, the following HTML code:

I embed the python fragments in HTML comment blocks for the sake of
my HTML editor tools which would otherwise feel very sad ...

I've also set it up (at least in one version) so that the python can
generate
http headers at the start as well .... or they can be embedded in the
templates.

> Internally, operation of the system would be simple.  The HTML page with
> embedded python would first be converted to a python file (by having a
> print statement output the HTML between the embedded python), this could
> then be compiled for efficiency as when normal files are executed.  The
> web server would then parse these files when requested (using an
> appropriately neat method to allow access to CGI variables and Cookies
> and the like from within the embedded HTML).  This would lead to a speed
> improvement in that the Python interpreter need not be launched every
> time.  The efficiency could be further improved by caching the compiled
> python files in memory.

Yup! All there (minus "appropriately neat": more "rather nasty" for now I'm
afraid)

> Cool facilities could also be implemented which sit ontop of the base
> CGI and Cookie layers to emulate a "per-user" memory.  This would allow
> a dictionary to be stored only to be retrieved the next time this user
> accesses the site (this would be achieved using cookies and storing
> information locally with a cookie-style self destruct).  Similarly, a
> "per-session" memory could be implemented, making it much easier to
> transfer information (such as a username and password) from one page to
> the next.

Hhmm! Didn't tackle this sort of thing yet !

Also I haven't yet dealt with putting the python into rexec for execution-
but this is only needed if a web master wants to give their clients access
to
these facilities as opposed to doing things themselves.

Things I'm not happy with:

* indenting of the python bits versus the HTML bits doesn't mesh
   very well

* the base server that I use is a threaded version of SimpleHTTP and I seem
   to have occasional problems with the thing hanging ... don't know why
   and haven't time to look into it just now

* I haven't figured how many security holes this might open ...

* there aren't any database "adapters" yet -- I just use background
    threads with an in memory database shelved to flat files when
    written to. Locking between threads is there though to allow
    this to be done safely ... Gadfly would not be a difficult step!

* basically it isn't anywhere near finished

* there are no good examples in the package yet

Having said that I have a couple of small sites where the thing is running
happily
with low load levels. Runs on NT/95 and BSD OS3 as of today. Used to run
on an very old RedHat linux but hasn't been tested there in a while!

I'll upload the thing to my starship account when I get home tonight just
in case anyone is interested!! I'll get back tomorrow with a URL.

Nigel.

nhead at houbits.com, nhead at esoc.esa.de





More information about the Python-list mailing list