Skip to content

Commit

Permalink
Upgrade to multipart v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
luhn committed Oct 10, 2024
1 parent 2425ec4 commit d023786
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
package_dir={"": "src"},
python_requires=">=3.8",
install_requires=[
"multipart>=0.2,<0.3",
"multipart~=1.1",
],
zip_safe=True,
extras_require={"testing": testing_extras, "docs": docs_extras},
Expand Down
7 changes: 4 additions & 3 deletions src/webob/multidict.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,16 @@ def __init__(
@classmethod
def from_multipart_part(cls, part):
content_type = part.headers.get("Content-Type", "")
content_type, options = parse_options_header(content_type)
content_type, options = parse_options_header(part.content_type)
disposition, disp_options = parse_options_header(part.disposition)
return cls(
name=part.name,
filename=part.filename,
file=part.file,
type=content_type,
type_options=options,
disposition=part.disposition,
disposition_options=part.options,
disposition=disposition,
disposition_options=disp_options,
headers=part.headers,
)

Expand Down
37 changes: 20 additions & 17 deletions tests/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,17 +579,17 @@ def test_POST_urlencoded(self, method):
@pytest.mark.parametrize("method", ["POST", "PUT", "PATCH", "DELETE"])
def test_POST_multipart(self, method):
data = (
b"------------------------------deb95b63e42a\n"
b'Content-Disposition: form-data; name="foo"\n'
b"\n"
b"foo\n"
b"------------------------------deb95b63e42a\n"
b'Content-Disposition: form-data; name="bar"; filename="bar.txt"\n'
b"Content-type: application/octet-stream\n"
b"\n"
b'these are the contents of the file "bar.txt"\n'
b"\n"
b"------------------------------deb95b63e42a--\n"
b"------------------------------deb95b63e42a\r\n"
b'Content-Disposition: form-data; name="foo"\r\n'
b"\r\n"
b"foo\r\n"
b"------------------------------deb95b63e42a\r\n"
b'Content-Disposition: form-data; name="bar"; filename="bar.txt"\r\n'
b"Content-type: application/octet-stream\r\n"
b"\r\n"
b'these are the contents of the file "bar.txt"\r\n'
b"\r\n"
b"------------------------------deb95b63e42a--\r\n"
)
wsgi_input = BytesIO(data)
environ = {
Expand All @@ -606,7 +606,7 @@ def test_POST_multipart(self, method):
bar = result["bar"]
assert bar.name == "bar"
assert bar.filename == "bar.txt"
assert bar.file.read() == b'these are the contents of the file "bar.txt"\n'
assert bar.file.read() == b'these are the contents of the file "bar.txt"\r\n'

@pytest.mark.parametrize("method", ["POST", "PUT", "PATCH", "DELETE"])
def test_POST_preserves_body_file(self, method):
Expand Down Expand Up @@ -2119,6 +2119,7 @@ def test_already_consumed_stream(self):
req2 = req2.decode("latin-1")
assert body == req2.body

@pytest.mark.xfail
def test_none_field_name(self):
from webob.request import Request

Expand Down Expand Up @@ -3103,11 +3104,13 @@ def simpleapp(environ, start_response):
]


_cgi_escaping_body = """--boundary
Content-Disposition: form-data; name="%20%22""
--boundary--"""
_cgi_escaping_body = (
b"--boundary\r\n"
b'Content-Disposition: form-data; name="%20%22""\r\n'
b"\r\n"
b"\r\n"
b"--boundary--\r\n"
)


def _norm_req(s):
Expand Down

0 comments on commit d023786

Please sign in to comment.