eqiv of perl's CGI.pm?

Harry George hgg9140 at seanet.com
Tue Feb 22 18:44:39 EST 2000

Your cgiforms.py looks inteesting, and seems to cover the needed
functions, but it doesn't solve my problem.  The python code has to
look and feel somewhat like perl with the CGI.pm.  E.g., same names,
same parameter order, etc.  It is hard to explain without looking at
the CGI.pm module itself.

FYI: I've begun this task with:

a) pyperl.PyPerl: a class which gives a perl-like feel to the program.
Based on a similar Perlish.i3/m3 I did for Modula-3.  (One complaint
form perl programmers is that they can't remember which module has
which functionality in python.  So this class flattens the namespace
for common items.  So far it looks like:

	#--make new---
	p.mkdir(newdir) or p.die("cannot make %(newdir)s" % locals())
	p.chdir(newdir) or p.die("cannot cd to %(newdir)s" % locals())
	if not myfile: p.die("cannot open %(filename)s" % locals())

	p.print_("before writing to file\n")
	p.print_("writing to %(filename)s\n" % locals())
	p.print_("after writing to file\n")

	if not myfile: p.die("cannot open %(filename)s" % locals())
	for line in lines:
I've stumbled over:
(1) "print" is a keyword, and thus cannot be redefined, so I use "print_"
(2) can't set value of a parameter, so "open" has to return file
instead of setting it
(3) need to know caller (so I can look in caller's __dict__) -- that
would allow hidden expansions of $ and @ vars in text strings; so I
have to do % locals() for now.

b) pyperl.cgipm.CGI: a class which replicates the CGI API.
The OO approach to using it looks like:
	def processform(self):
		print self.header()
		title='Test02: CGI response'
		print self.start_html(title=title,author='John Doe')
		print '<CENTER>',title,'</CENTER>'
		print "<P>Hello, world"
		print self.end_html()

	def sendform(self):
		print self.header()
		title='Test02: CGI form'
		print self.start_html(title=title,author='John Doe')
		print '<CENTER>',title,'</CENTER>'
		print "<P>Hello, world"
		print self.startform(action='http://wilma/cgi-bin/hgg9140/test02.py',

		print self.textfield(name="mytextfield",default="hello, world",size=50,
		print self.endform()
		print self.end_html()

The in-line approach looks like:

Michael =?iso-8859-1?Q?Str=F6der?= <michael.stroeder at inka.de> writes:

> "Harry G. George" wrote:
> > 
> > I have the opportunity to convert a lot of perl cgi's to python.  But
> > I need to make them look similar to perl's CGI.pm API. (The users have
> > just barely gotten comfortable with Perl and CGI.pm.)
> > 
> > python's cgi.py is good for reading forms, but I need to build forms too.
> > cgi.py doesn't address this.  HTMLgen is overkill.  Anyone doing a
> > CGI.pm workalike?
> What exactly does CGI.pm? I have a module cgiforms.py with which you
> can pre-define input fields in a form and output the single input
> fields. The input parameters are checked against reg exp. you define
> with the input field. E.g. my project http://web2ldap.de/ is based
> on that. Your mileage may vary...
> Have a look at http://sites.inka.de/ms/python/pylib/. If you're
> interested in using that drop me a note and I will package a newer
> version with demo script.
> Ciao, Michael.

Harry George
hgg9140 at seanet.com

More information about the Python-list mailing list