[Q] Bug in cgi.FieldStorage?

Discussion in 'Python' started by Ames Andreas (MPA/DF), Aug 20, 2004.

  1. Hi,

    I'm currently using Zope 2.7.2-0 which in turn uses cgi.FieldStorage
    from Python 2.3.4.

    FieldStorage can either build a 'list' or a 'file' to represent a
    request. Unfortunately it overwrites __len__ such that it throws an
    exception when the request wasn't of type 'multipart', i.e. when it
    doesn't 'return' a list but a file. I'd consider this a bug because
    if you have an instance fs of FieldStorage you can't safely write

    if fs:
    ...

    because of the unfortunate __len__ implementation (it raises a
    TypeError exception in some cases). I might be willing to accept that
    this isn't python's bug but mine if someone argues smartly enough.

    What's is the right thing to do in this case (and in the general
    case)?

    1) The idiom 'if fs:' is borked. I'm not supposed to use it, I should
    have known and I'm dumb. Instead I'm supposed to use 'if fs is not
    None:' or something. (This seems to be smart enough an argument
    for me :)

    2) cgi.FieldStorage should have a more appropriate __len__
    implementation. If so, how?

    3) cgi.FieldStorage should overwrite __nonzero__ to always return 1.
    I'm leaning towards this one. Am I right?


    tia,

    andreas
     
    Ames Andreas (MPA/DF), Aug 20, 2004
    #1
    1. Advertising

  2. Ames Andreas (MPA/DF)

    Tim Roberts Guest

    "Ames Andreas (MPA/DF)" <> wrote:
    >
    >I'm currently using Zope 2.7.2-0 which in turn uses cgi.FieldStorage
    >from Python 2.3.4.
    >
    >FieldStorage can either build a 'list' or a 'file' to represent a
    >request. Unfortunately it overwrites __len__ such that it throws an
    >exception when the request wasn't of type 'multipart', i.e. when it
    >doesn't 'return' a list but a file. I'd consider this a bug because
    >if you have an instance fs of FieldStorage you can't safely write
    >
    >if fs:
    > ...


    What question do you intuitively expect that statement to be asking?

    I've been using cgi.FieldStorage() for quite a while, and I can't say that
    I have ever wanted to write a statement like that.
    --
    - Tim Roberts,
    Providenza & Boekelheide, Inc.
     
    Tim Roberts, Aug 22, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Al Stoltz
    Replies:
    1
    Views:
    1,099
    Andrew Clover
    Jan 23, 2004
  2. Fred Murray

    Odd cgi.FieldStorage behavior

    Fred Murray, Mar 2, 2004, in forum: Python
    Replies:
    1
    Views:
    329
    Tim Roberts
    Mar 4, 2004
  3. python user

    libapreq2 and cgi.FieldStorage

    python user, Jul 9, 2004, in forum: Python
    Replies:
    0
    Views:
    374
    python user
    Jul 9, 2004
  4. Austyn Bontrager

    cgi.FieldStorage and REDIRECT_REQUEST_METHOD

    Austyn Bontrager, Jul 28, 2004, in forum: Python
    Replies:
    1
    Views:
    521
    Lee Harr
    Jul 28, 2004
  5. Ames Andreas (MPA/DF)
    Replies:
    0
    Views:
    328
    Ames Andreas (MPA/DF)
    Aug 5, 2004
Loading...

Share This Page