473,804 Members | 3,018 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[Q] Bug in cgi.FieldStorag e?

Hi,

I'm currently using Zope 2.7.2-0 which in turn uses cgi.FieldStorag e
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.FieldStorag e should have a more appropriate __len__
implementation. If so, how?

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

andreas

Jul 18 '05 #1
1 1951
"Ames Andreas (MPA/DF)" <An**********@t enovis.com> wrote:

I'm currently using Zope 2.7.2-0 which in turn uses cgi.FieldStorag e
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.FieldStorag e() for quite a while, and I can't say that
I have ever wanted to write a statement like that.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1251
by: Fred Murray | last post by:
Hi all, When uploading a file ("input type=file"), FieldStorage usually behaves correctly, but every once in a while (every couple days?), it will suddenly start causing internal server errors. A look at the apache (v. 2.0.44 on Linux) error log shows "premature end of script headers" with no error messages from Python. After reloading the browser about 10 times in a row, it will suddenly start working again. Recently, when a series...
1
1639
by: Ames Andreas (MPA/DF) | last post by:
Hi, sorry for following-up to myself. Some remarks: 1) Please excuse the bogus original message. I wrote it a minute before I knocked off work and I promise to never do so again :-) 2) What I really wanted to know was: FieldStorage writes what it reads from the stream that is given to its constructor's fp (or sys.stdin by default) to a temporary file only _in some cases_. My
0
1702
by: Neil Benn | last post by:
Hello, I'm writing a simple cgi script and want to be able to access the filename in a FieldStorage file instance. I have successfully manmaged to access the file as a 'file-like object' by using the simple code of : objInFile = objForm.file I can easily read through this data and get all the information out
4
2122
by: Derek Basch | last post by:
Given this FieldStorage object: FieldStorage(None, None, ) I am trying to cgi.urlencode the FieldStorage object to POST to another cgi script. The documentation for urlencode, http://docs.python.org/lib/module-urllib.html , says that urlencode takes a mapping object or a list of double tuples. I see that I could use cgi.parse_qs and cgi.parse_qsl to create these object types. Should I just use that or should I continue using...
2
2628
by: praba kar | last post by:
Dear All, I have doubt in python cgi script. I describe that doubt with below code import cgi form = cgi.FieldStorage() passwd = form.value print passwd But Now I want to assign some value to form field value form = 'surese'
3
2214
by: Chris Curvey | last post by:
I can't be the first person to want to do this, but I also can't seem to find a solution. (Perhaps my Google skills are poor today.) How can I emulate cgi.FieldStorage() for my unit tests so that I don't have to put a web server in the way? what I'd like to do is something like fs = cgi.FieldStorage() fs = "bar" functionToBeTested(fs)
0
1902
by: John Salerno | last post by:
I'm trying to use a for loop with a FieldStorage object and I get the following error. Can you not treat it like a dictionary, or am I writing the for loop incorrectly? for item in form: print item # or print item.value
7
1588
by: John Salerno | last post by:
If I want to get all the values that are entered into an HTML form and write them to a file, is there some way to handle them all at the same time, or must FieldStorage be indexed by each specific field name?
4
4885
by: arorap | last post by:
I've mod_php installed with Apache 2.2. In one of my folders, I'm using the cgihandler as the PythonHandler as my target host runs python only as CGI. Here cgi.FieldStorage() doesn't seem to work. I can see the form data in sys.stdin but cgi.FieldStorage() returns an empty dictionary. Here's the code for the test script I am posting to - -- #!/usr/bin/python
0
10562
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10070
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9132
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4282
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2978
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.