[Patches] [ python-Patches-1159139 ] cgi.py invalid REQUEST_METHOD set
SourceForge.net
noreply at sourceforge.net
Mon Apr 2 15:54:56 CEST 2007
Patches item #1159139, was opened at 2005-03-08 11:04
Message generated for change (Settings changed) made by joesalmeri
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1159139&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Library (Lib)
Group: Python 2.4
>Status: Open
Resolution: Rejected
Priority: 5
Private: No
Submitted By: Joe (joesalmeri)
Assigned to: Martin v. Löwis (loewis)
Summary: cgi.py invalid REQUEST_METHOD set
Initial Comment:
Python Version 2.4
OS Windows XP SP 2 + WindowsUpdates
Patch for lastest CVS Tree
When the environment does not have a correctly set
REQUEST_METHOD cgi.py prompts
for key=value pairs by reading from sys.stdin. After the
values are read from sys.stdin they are never stored in
the FieldStorage.list attribute like they are
when the FieldStorage.read_urlencoded or
FieldStorage.read_multi methods are called.
This causes a problem when FieldStorage.keys() is
called because although the values were read from
sys.stdin they were never stored in FieldStorage.list.
Although you could argue that REQUEST_METHOD
should have been set correctly in the first place, it still
seems like if cgi.py is going to handle that situation by
actually reading the values from sys.stdin it should
store them too.
This fix stores the values read.
----------------------------------------------------------------------
Comment By: Joe (joesalmeri)
Date: 2007-04-02 09:54
Message:
Logged In: YES
user_id=1235002
Originator: YES
It been a long time since I submitted this patch but I meant that
REQUEST_METHOD is not set although I believe it also happens when it is set
incorrectly.
Regarding your question with the prompting I thought I explained that in
the original post but here are more details:
When the REQUEST_METHOD is not set the __init__ method for the
FieldStorage class ends up setting the self.fp to sys.stdin.
When the read_single method is called it calls self.read_lines(). Since
self.fp is equal to sys.stdin at that point and since there is not input
pending on stdin it ends up prompting for input until it reaches EOF.
The bug was that although it prompted for input by reading from sys.stdin,
the values that it read were never stored in FieldStorage like they are
when the values are read from the normal sources.
Since someone went to the trouble of coding cgi.py to read the values from
stdin when the REQUEST_METHOD was invalid it seems to make sense to store
them.
As jimjjewett point out this addresses the issue of allowing a cgi script
to be called from the command line which is useful for debugging of if no
web server is running.
Since it is counter-intuitive to read the values or not store them the
other option would be not to set self.fp = sys.stdin and instead through an
error that REQUEST_METHOD was not set properly however, it seems more
benefitial to read from sys.stdin and then store the values read in
FieldStorage.
Does that make more sense now?
Thanks.
----------------------------------------------------------------------
Comment By: SourceForge Robot (sf-robot)
Date: 2007-03-20 22:20
Message:
Logged In: YES
user_id=1312539
Originator: NO
This Tracker item was closed automatically by the system. It was
previously set to a Pending status, and the original submitter
did not respond within 14 days (the time period specified by
the administrator of this Tracker).
----------------------------------------------------------------------
Comment By: Martin v. Löwis (loewis)
Date: 2007-03-06 08:23
Message:
Logged In: YES
user_id=21627
Originator: NO
I must be completely missing the point of this patch.
Where in the code does it currently prompt for key=value pairs if
REQUEST_METHOD is not correctly set?
By "not correctly set", do you mean "not set" or "set incorrectly"? If the
latter, to what value?
You seem to be modifying the read_single function. This is meant to read a
single body of the CGI request (as sent by the HTTP client), not the
key-value-pairs.
I've tried to come up with a demo application of this new functionality,
but failed: I couldn't make this new code do anything useful. What Python
script should I use, how should I invoke it, what environment variables
should I give, and what standard input?
Tentatively rejecting the patch.
----------------------------------------------------------------------
Comment By: Jim Jewett (jimjjewett)
Date: 2005-03-14 17:54
Message:
Logged In: YES
user_id=764593
+1 on supporting use without a REQUEST_METHOD, if only
to match Perl on "what happens if my .cgi was called straight
from the command line"?
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1159139&group_id=5470
More information about the Patches
mailing list