Mailing List Archive

Python CGI Scripts
I'm just getting into python really, and being a perler for a couple of years
I've gotten it to do just about everything I've ever needed for SA'ing. As I
thumb through 'Programming Python' it looks like just about everything that can
be done with perl can be done with python.

But... have a lot of people adopted python as their new cgi language? This is
what I do primarily lately and I found only one program in the book called
'cgimail.py'. As I read through the code I notice that the h1 tags, the form,
the header infomation, etc etc are all being 'print'ed manually. Is there no
nifty CGI.pm equivelent in python?

Comments?

/***************************************************************\
* Stephen ("xinu") Klassen -- Unix Systems Administrator *
* Website: http://stephen.webadmins.com/ UIN: 19224641 (wk) *
\***************************************************************/
Python CGI Scripts [ In reply to ]
Well, there is the cgi.py module, which is basically form parsing, etc. For
HTML formatting, you can use HTMLgen, which I think is what you probably
have in mind. See the contributed modules section of www.python.org

I'd suggest considering using a template class as well; IMHO, mixing HTML
and a scripting language is a bad idea, from a code maint / readability
standpoint (whether it's HTML in CGI, like this, or something like ASP/PHP).

More generally, yes, a lot of people use Python for CGI. Between cgi,
htmlgen, htmllib, urllib and httplib, there's pretty much everything you
need.


Cheers,



> I'm just getting into python really, and being a perler for a couple of
years
> I've gotten it to do just about everything I've ever needed for SA'ing. As
I
> thumb through 'Programming Python' it looks like just about everything
that can
> be done with perl can be done with python.
>
> But... have a lot of people adopted python as their new cgi language? This
is
> what I do primarily lately and I found only one program in the book called
> 'cgimail.py'. As I read through the code I notice that the h1 tags, the
form,
> the header infomation, etc etc are all being 'print'ed manually. Is there
no
> nifty CGI.pm equivelent in python?
Python CGI Scripts [ In reply to ]
Stephen> But... have a lot of people adopted python as their new cgi
Stephen> language?

Just one data point from one person (who never wrote a single Perl CGI
script, so it's my old cgi language as well):

~% ls ~httpd/cgi-bin/* | xargs file | egrep -i python | wc -l
51

and I tend to use ZServer (see http://www.zope.org/) much more these days
instead of CGI.

Skip Montanaro | http://www.mojam.com/
skip@mojam.com | http://www.musi-cal.com/~skip/
847-971-7098
Python CGI Scripts [ In reply to ]
Stephen wrote:
>
> But... have a lot of people adopted python as their new cgi language? This is
> what I do primarily lately and I found only one program in the book called
> 'cgimail.py'. As I read through the code I notice that the h1 tags, the form,
> the header infomation, etc etc are all being 'print'ed manually. Is there no
> nifty CGI.pm equivelent in python?
>
> Comments?
>

Yep, have a look at Zope, a python based opensource cgi solution:

http://www.zope.org/

Cheers,

Rudi Angela
Python CGI Scripts [ In reply to ]
On Mon, 16 Aug 1999, Rudi Angela wrote:

>Yep, have a look at Zope, a python based opensource cgi solution:

From my POV, Zope has two major problems.

#1: It expects to run as a server. This is not a good
thing, from the POV of most IPPs and ISPs.

#2: The documentation is somewhat lacking.
<< This one is easy to fix. >>

I suspect that the same would be true for various other
people as well.

A Python equivelent to the Perl CGI.pm module would be a
very usefull thing to have/do.

xan

jonathon
Python CGI Scripts [ In reply to ]
Jonathon> A Python equivelent to the Perl CGI.pm module would be a
Jonathon> very usefull thing to have/do.

What does Python's existing cgi.py module not do that you would like it to?

Skip Montanaro | http://www.mojam.com/
skip@mojam.com | http://www.musi-cal.com/~skip/
847-971-7098
Python CGI Scripts [ In reply to ]
On Mon, 16 Aug 1999 20:24:42 +0000 (UTC), Jonathon wrote:
>On Mon, 16 Aug 1999, Rudi Angela wrote:

>>Yep, have a look at Zope, a python based opensource cgi solution:

> From my POV, Zope has two major problems.

Only two :)?

> #1: It expects to run as a server. This is not a good
> thing, from the POV of most IPPs and ISPs.

I'm confused -- since its earliest release it's run under Apache. What
could you mean "run as a server"? Were you expecting it to be a client?

> #2: The documentation is somewhat lacking.
> << This one is easy to fix. >>

You nailed that one right on. It's not easy, but it sure is important.

> I suspect that the same would be true for various other
> people as well.

I'm sorry, what? What are you saying would be true for people?

> A Python equivelent to the Perl CGI.pm module would be a
> very usefull thing to have/do.

I'm pretty sure it's already there, even for people who don't use Bobo.
People have been using Python for CGI scripting for a while.

> xan
> jonathon

--
-William "Billy" Tanksley
Python CGI Scripts [ In reply to ]
> From my POV, Zope has two major problems.
>
> #1: It expects to run as a server. This is not a good
> thing, from the POV of most IPPs and ISPs.

Zope usually runs as a server (a.k.a. long running process)
because it is more responsive that way. It can also run in a
conventional CGI manner (one new process forked per hit)
if you have low traffic and/or don't mind paying the price.

For many low-traffic tasks, I don't use an LRP. My code
uses the publisher (maps urls to methods & paramenters),
document templates, and the persistent object store (POS).
The latter is basically a pickling mechanism. You write
Python class methods which are invoked as http requests.

Also: Although Zope is usually run as a server, this
does not mean it expects to be _the_ server. Your ISP
can use their favorite web server (e.g. Apache) to
communicate with a Zope process.

This begs the question: Will your ISP allow you to own
a long-running process on one of their machines? Many
won't. but some ISP's explicitly provide web hosting
services to Zope users.

Best regards,

Jeff Bauer
Rubicon, Inc.
Python CGI Scripts [ In reply to ]
>>>>> "WT" == William Tanksley <wtanksle@dolphin.openprojects.net> writes:

WT> I'm pretty sure it's already there, even for people who don't
WT> use Bobo. People have been using Python for CGI scripting for
WT> a while.

Take a look at Mailman <www.list.org>. It is in large part a huge
Python CGI `script'!

-Barry