classification
Title: cgi.parse_multipart() requires undocumented CONTENT-LENGTH in Python 3.7
Type: behavior Stage: patch review
Components: Documentation, Library (Lib) Versions: Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Tercio Gaudencio Filho, docs@python, fdrake, orsenthil, quentel, rogerduran, xtreak, yan12125
Priority: normal Keywords: patch

Created on 2018-07-25 14:55 by yan12125, last changed 2019-07-12 18:55 by fdrake.

Pull Requests
URL Status Linked Edit
PR 8530 open python-dev, 2018-07-28 15:07
Messages (2)
msg322362 - (view) Author: Chih-Hsuan Yen (yan12125) * Date: 2018-07-25 14:55
In Python 3.7, cgi.parse_multipart() requires "CONTENT-LENGTH" in the second parameter `pdict`. This is not necesary in Python 3.6.

For example, the following code runs with 3.6:

$ python3.6
Python 3.6.6 (default, Jun 27 2018, 13:11:40) 
[GCC 8.1.1 20180531] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cgi, io
>>> data = b'--heyDavid\r\nContent-Disposition: form-data; name="cfield"\r\n\r\njust a string\r\n\r\n--heyDavid--\r\n'
>>> cgi.parse_multipart(io.BytesIO(data), {"boundary": b"heyDavid"})
{'cfield': [b'just a string\r\n']}

While not on 3.7:

$ python3.7
Python 3.7.0 (default, Jul 15 2018, 10:44:58) 
[GCC 8.1.1 20180531] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cgi, io
>>> data = b'--heyDavid\r\nContent-Disposition: form-data; name="cfield"\r\n\r\njust a string\r\n\r\n--heyDavid--\r\n'
>>> cgi.parse_multipart(io.BytesIO(data), {"boundary": b"heyDavid"})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.7/cgi.py", line 220, in parse_multipart
    headers['Content-Length'] = pdict['CONTENT-LENGTH']
KeyError: 'CONTENT-LENGTH'

I looked into the source code of CPython, and found CONTENT-LENGTH in nowhere but cgi.py and test_cgi.py. I guess it has the same meaning as the Content-Length header in HTTP or CONTENT_LENGTH environment variable in CGI? It would be great to document such a backward-incompatible behavior.

Environment: Arch Linux with Python 3.6.6 from [extra] repo and 3.7.0 from [staging] repo.

CC the author and the reviewer of issue29979, where relevant codes are introduced.
msg322541 - (view) Author: roger (rogerduran) * Date: 2018-07-28 10:55
working on this on europython
History
Date User Action Args
2019-07-12 18:55:03fdrakesetnosy: + fdrake
2018-08-30 18:58:24Tercio Gaudencio Filhosetnosy: + Tercio Gaudencio Filho
2018-07-28 15:07:11python-devsetkeywords: + patch
stage: patch review
pull_requests: + pull_request8047
2018-07-28 10:55:08rogerduransetnosy: + rogerduran
messages: + msg322541
2018-07-25 15:19:20xtreaksetnosy: + xtreak
2018-07-25 14:55:40yan12125create