FAQ
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

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?

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

4.
Is the following Python the (best) equivalent to the PHP?

PHP Python
ereg("bit","bigbits") re.compile("bit").search("bigbits",1)


TIA


--------------------------------
Michael Hall ninti at ninti.com
--------------------------------

Search Discussions

  • Ian Bicking at Jun 4, 2002 at 8:47 am

    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
  • John J. Lee at Jun 4, 2002 at 9:26 pm

    On Wed, 5 Jun 2002, Michael Hall wrote:

    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
    [...]

    Of course not -- Python itself knows nothing about CGI. I don't think the
    cgi module does any tricky implicit stuff along those lines, either.

    [...]
    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 the hexdigest method.
    3.
    What is the decimal bit on the end of time.time()'s output? Hundredths of
    a second?
    The seconds element of the time tuples that the standard Python library
    function uses is a decimal number, in seconds.
    4.
    Is the following Python the (best) equivalent to the PHP?

    PHP Python
    ereg("bit","bigbits") re.compile("bit").search("bigbits",1)
    No idea, but Python uses Perl-style regular expressions, which aren't
    exactly the same as 'extended' regexps.

    All this stuff is in the std. library docs.


    John

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJun 4, '02 at 8:47a
activeJun 4, '02 at 9:26p
posts3
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase