quetz-mod_python-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sterling Hughes <sterl...@bumblebury.com>
Subject Re: Python Server Pages
Date Fri, 04 Apr 2003 22:38:15 GMT
On Fri, 2003-04-04 at 14:45, Gregory (Grisha) Trubetskoy wrote:
> I am delighted to announce that in a little private exchange Sterling
> Hughes has agreed to work on integrating the code from mod_psp into
> mod_python. (Just google for mod_psp for details).
> 
> I guess the point of this e-mail is to bring the matter to everyone's
> attention and to give people an opportunity to pitch in with
> ideas/opinions/etc.


Hi,

I figured I'd take this opportunity to say hello, and discuss some of my
plans for mod_python + psp.

First a bit about mod_psp
(http://www.edwardbear.org/mod_psp-0.3.tar.gz).  mod_psp was created to
create a PHP-esque environment for python code.  It sports a syntax for
embedding python code with in HTML, an apache module that registers MIME
types, and a little toolkit for common tasks (like accessing GET, POST
and cookie variables):

<?psp
import time
?>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>Hello World</h1>
It is now <i><?=time.strftime("%Y-%m-%d, %H:%M)?></i>
</body>
</html>


It supports code blocks and indentation via two methods, either using
whitespace to denote html blocks:

<?psp if foo: ?>
	FOO is here
	<?psp if bar: ?>
		BAR is here
	Some More FOO
Whitespace block is over, printed regardless

Or by denoting things with { and } like in traditional languages:

<?psp if foo: { ?>
	FOO is here
	<?psp if bar: ?>
		BAR is here
	Some More Foo
<?psp } ?>
Block of FOO is over, printed regardless

These two indentations can be mixed, and matched.  PSP supports
modifying request and response parameters, however it also provides
reasonable defaults.  So for example, the content-type of an application
starts with text/html.  Headers are automatically sent when the
application first produces output, etc.

The core idea behind PSP is to make developing web applications with
Python as simple as humanly possible.  My first (and only) web
application with PSP can be found at:
http://www.edwardbear.org/guestbook.psp.txt (it ends in .txt because IE
ignores MIME headers)..

PSP is internally written completely in C.  It consists of a parser,
which rewrites PSP files into python files (plain html into
response.write("html code"), it uses flex), code that executes the
python file, and support scaffolding that give access to the apache api.
mod_psp registers two MIME types, application/x-httpd-python and
application/x-httpd-psp, it allows you to natively run normal python
files (no rewriting), and PSP files. 

One of the cooler things it does (don't know if mod_python does this),
is internally cache the compiled python objects.  Therefore, you only
need to compile python scripts once per apache process (it stat()s the
files each time to check for changes).

I took a little time today to look at mod_python's source code, and it
seems the mod_psp could live very happily inside of mod_python without
being too invasive.  What I think would be an ideal thing is if the
following happened:

1) mod_python gains two new MIME handlers, application/x-httpd-python
and application/x-httpd-psp.  These MIME handlers behave similairly to
how they did in mod_psp.

2) The Python Server Pages functionality gets exported in a traditional
mod_python module, and therefore you could do something like:

from mod_python import psp

def handler(req):
	code = psp.parse(filename)

You can also use the psp.include() function to parse and execute psp
code from within mod_python handlers and application/x-httpd-python
python scripts.  mod_psp already has this functionality.

Anyhow, this is how I envision the two merging.  I'm sorry to have
written such a long mail, I just prefer to be verbose. ;-)  I'm really
excited about getting the two to work together, and am interested to
hear other people's opinions as to how this should be integrated.

-Sterling







Mime
View raw message