cgi.py -- anybody using it?
John J Lee
jjl at pobox.com
Sat Apr 5 14:48:31 CEST 2003
On 5 Apr 2003, Ian Bicking wrote:
> On Fri, 2003-04-04 at 17:58, John J Lee wrote:
> > I just tried testing some HTML form upload code using cgi.py, and
> > discovered that it wants lower-case HTTP headers :-/
> Have you actually seen this behavior, or are you getting this from
> reading the code?
No, I've seen it, but by using cgi.FieldStorage directly in unit tests
rather than actually sending HTTP requests.
> I don't even think the code handles headers -- the
> CGI process turns headers into environmental variables, and case isn't
> preserved in that process.
Ah. That'll be it. That sort of thing did pass through my mind, but for
some reason I didn't follow it up.
> In some places you may read code that uses the mimetools module to parse
> headers. It has a dictionary interface, but keys are case-insensitive,
> so if it uses m["content-type"] it's still work with Content-Type or
Well, though I had forgotten about mimetools, presumably that isn't the
issue, assuming it's the CGI process' responsibility to lower-case
everything as you tell me. Might be an easy way to fix my unit test,
> And yes, the cgi module is in very active use, not just for cgi
> programs, but in many systems that handle the web (since it has
> functions for query string parsing and many other things).
Oh. There should be a pointer to the cgi docs from the urllib docs, then.
I once wrote a urldecode function to match urllib.urlencode -- hadn't
noticed cgi.parse_qsl. I'll file a bug about *that*.
More information about the Python-list