# PEP 594: Removing dead batteries from the standard library

**URL:** <https://discuss.python.org/t/pep-594-removing-dead-batteries-from-the-standard-library/1704>\
**Category:** PEPs\
**Created:** [May 22, 2019, 10:58am UTC](https://discuss.python.org/t/pep-594-removing-dead-batteries-from-the-standard-library/1704 "2019-05-22T10:58:29Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![mjpieters](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/mjpieters/32/710_2.png) [@mjpieters](https://discuss.python.org/u/mjpieters)\
**Post date:** [May 23, 2019, 10:39am UTC](https://discuss.python.org/t/pep-594-removing-dead-batteries-from-the-standard-library/1704/14 "2019-05-23T10:39:13Z")

</div>

> [@xistence](#):
>
> `cgi.FieldStorage` is used to parse POST data, and backs all file storage inside WebOb.
> 
> As I understand it there are other frameworks that use it as well, such as Bottle.

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`.

> [@xistence](#):
>
> `cgi.parse_header` is also used by Django and WebOb.
> 
> `cgi.parse_multipart` is used by Twisted.

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:

```python
>>> 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.

> [@xistence](#):
>
> If this PEP goes through and `cgi.FieldStorage` are not moved then anyone that is parsing `multipart` POST bodies will have to write their own, or copy an older version and hope they can get patches from other projects that have done the same.

_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](https://github.com/pallets/werkzeug/blob/master/src/werkzeug/formparser.py) and [Django](https://github.com/django/Django/tree/master/django/http) already wrote their own POST data handling.

---

_[View the full topic](https://discuss.python.org/t/pep-594-removing-dead-batteries-from-the-standard-library/1704)._
