defnull / multipart

Multipart parser for Python 3
Other
120 stars 33 forks source link

differenciate between form_data and files based on filename headder #19

Closed theelous3 closed 5 years ago

theelous3 commented 5 years ago
>>> from io import BytesIO
>>> from multipart import MultipartParser
>>> 
>>> m = '--8banana133744910kmmr13a56!102!2405\r\nContent-Disposition: form-data; name="file_1";\r\n\r\nCompooper\r\n--8banana133744910kmmr13a56!102!2405--\r\n'
>>> 
>>> boundary = '8banana133744910kmmr13a56!102!2405'.encode()
>>> 
>>> parser = MultipartParser(BytesIO(m.encode()), boundary)
>>> 
>>> parser.parts()[0]
<multipart.MultipartPart object at 0xb716d4ec>
>>> parser.parts()[0].form_data
True
>>> parser.parts()[0].file
False

>>> m = '--8banana133744910kmmr13a56!102!2405\r\nContent-Disposition: form-data; name="file_1"; filename="test_file1.txt"; Content-Type: application/octet-stream\r\n\r\nCompooper\r\n--8banana133744910kmmr13a56!102!2405--\r\n'
>>> 
>>> boundary = '8banana133744910kmmr13a56!102!2405'.encode()
>>> 
>>> parser = MultipartParser(BytesIO(m.encode()), boundary)
>>> 
>>> parser.parts()[0]
<multipart.MultipartPart object at 0xb723678c>
>>> parser.parts()[0].file
True
>>> parser.parts()[0].form_data
False
>>> 
theelous3 commented 5 years ago

Note that this is breaking tests. (Things expect to use the bytesio object at .file, but .file is now just a bool.)

I foresee a fair bit of work going on in this lib over the next short while, and keeping tests up to date will likely be fruitless work in the mean time.

theelous3 commented 5 years ago

Actually, who cares. Realising my problem wasn't that the type of the data wasn't being catagorised, but only that everything was catagorised under file. Easier to just chuck that whole thing.