|
|
Log in / Subscribe / Register

Python finally offloads some batteries

Python finally offloads some batteries

Posted Mar 17, 2022 23:06 UTC (Thu) by cjwatson (subscriber, #7322)
In reply to: Python finally offloads some batteries by mb
Parent article: Python finally offloads some batteries

I don't know about the rest of cgi, but cgi.FieldStorage is so broken as to be a snare and a delusion, so I'm glad they're removing it. I got involved with maintaining the multipart package when I found that FieldStorage was unusably broken for my purposes and that its design was enough of a ball of wax that it couldn't realistically be fixed without breaking something else.


to post comments

Python finally offloads some batteries

Posted Mar 18, 2022 7:03 UTC (Fri) by mb (subscriber, #50428) [Link] (1 responses)

>cgi.FieldStorage is so broken as to be a snare and a delusion, so I'm glad they're removing it.

It works just fine for me.
What's broken with it?

I'm not against removing unused or rarely used modules.
But removing those widely used modules, like cgi, is going to cause major waste of developer time in the order of hundreds of thousands of hours. That's not Ok and it will hurt Python's reputation. Again.

Python finally offloads some batteries

Posted Mar 18, 2022 18:48 UTC (Fri) by cjwatson (subscriber, #7322) [Link]

https://bugs.python.org/issue27777 was an absolute blocker in my application causing extremely confusing failures (and that only due to quite pedantic tests - we might easily have missed it until it hit production), and caused me weeks of work trying to work around it before I eventually concluded that cgi.FieldStorage was engaged in playing core-wars with other bits of itself and there was no realistic prospect of it ever being fixed, so switched to something different instead. See https://github.com/zopefoundation/zope.publisher/issues/39.

Python finally offloads some batteries

Posted Mar 18, 2022 18:35 UTC (Fri) by edgewood (subscriber, #1123) [Link] (2 responses)

Did you find an alternative? I have a few scripts that are only called occasionally, and aren't performance sensitive, so are fine as CGI scripts, which saves me deployment hassle.

But I do need to parse URL and form parameters, and use FieldStorage for that. I was planning to just copy cgi.py when it went EOL, but if there's a better replacement I'll use it.

Python finally offloads some batteries

Posted Mar 18, 2022 18:49 UTC (Fri) by cjwatson (subscriber, #7322) [Link] (1 responses)

The PEP itself has several suggestions (https://peps.python.org/pep-0594/#cgi).

Python finally offloads some batteries

Posted Mar 27, 2022 13:53 UTC (Sun) by edgewood (subscriber, #1123) [Link]

I'm so sorry that I missed that. I had skimmed the PEP, and had seen that section, but my eyes got pulled to the code sample at the bottom of the section.

I just had a chance to convert a script that used cgi.FieldStorage to use urllib.parse.parse_qs instead, and it only took me about a half an hour. It helped that I had a helper method to smooth over some weirdness caused by the interaction of FieldStorage and the structure of my existing HTML, and a lot of the accesses of the FieldStorage values already went through that method. I just changed it to access the parse_qs dictionary instead, and changed a handful of sites that directly accessed FieldStorage values directly to call the helper, and it all worked.

My previous plan was to vendor cgi.py, so thank you for responding to my question and pointing me to how I could use supported stdlib code!


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds