CGI questions

Ian Bicking ianb at colorstudy.com
Tue Jun 4 04:47:55 EDT 2002


On Tue, 2002-06-04 at 12:41, Michael Hall wrote:
> 
> I've been using PHP for a couple of years now, but have begun to look at
> Python as a CGI language. So far so good, I really like writing straight
> OO code and keeping all the HTML spaghetti out of the way in templates.
> Anyway, a couple of questions:
> 
> 1.
> Does Python have the same or a similar problem that PHP had until recently 
> with regard to automatic global registration of GET, POST and COOKIE
> variables within a script's namespace? My guess is that it doesn't, but
> I'd like to know for sure.
> In other words, is all user input in the form of query string or POST
> variables 'filtered' through cgi.Fieldstorage? Is user input ever directly
> available to the script? 
> Let's say I have a variable 'loggedon' in my script. If a user passes
> 'loggedon=yes' in a query string to my script, will it have any effect or
> would it have to be accessed via something like this first:
> 
> form = cgi.Fieldstorage
> loggedon = form["loggedon"].value

No, there's no problem with this -- you will always explicitly say where
you want to get the value from, nothing's ever put in the global
namespace for you.

> 2.
> I'm trying to use the md5 module to create a session id string. It
> produces some output, but it is pretty weird stuff, not the 32 character
> alphanumeric string I'd expect from PHP. Most of it is definitely not
> [a-zA-Z0-9], and it is around 10 characters long. How can I get a PHP
> style md5 result?

Use .hexdigest()

> 3.
> What is the decimal bit on the end of time.time()'s output? Hundredths of
> a second?

Fractions of a second, of course.  The actual precision is
system-dependent (i.e., it's probably not as precise as it looks)

> 4.
> Is the following Python the (best) equivalent to the PHP?
> 
> PHP				Python
> ereg("bit","bigbits")		re.compile("bit").search("bigbits",1)

I'm not sure what the ,1 is in the Python version.  You should just do
re.compile("bit").search("bigbits"), or perhaps 
re.search("bit", "bigbits") (you save your compiled regex to speed later
searches, but if you don't save the compiled regex compiling won't make
a difference).

--
Ian Bicking           Colorstudy Web Design
ianb at colorstudy.com   http://www.colorstudy.com
4869 N Talman Ave, Chicago, IL 60625 / (773) 275-7241






More information about the Python-list mailing list