I note that Werkzeug doesn’t use FieldStorage
(or any other part of cgi
, really). Django doesn’t use FieldStorage
either, but do use cgi.parse_header
and cgi.valid_boundary
.
Both of these functions should really be provided by the email
package. There is an implementation of parse_header()
in email.message.Message()
, actually, so this functionality is duplicated across two different libraries in the standard lib:
>>> from cgi import parse_header
>>> from email.message import Message
>>> parse_header(h)
('application/json', {'charset': 'utf8'})
>>> m = Message()
>>> m['content-type'] = h
>>> m.get_params()
[('application/json', ''), ('charset', 'utf8')]
>>> m.get_param('charset')
'utf8'
cgi.parse_multipart()
can likewise be handled by email.message
; it’s all the same MIME RFC.
Or someone creates a canonical package that everyone uses, just like they rely on Python’s cgi
module. That’s not really an argument for or against removing cgi
from the standard library. Moving it to PyPI does have the advantage that the fix you carry in WebOb could be upstreamed faster, you don’t have to wait for everyone to upgrade their Python installation first.
Note that both Werkzeug and Django already wrote their own POST data handling.