Skip to content

Commit 7afb8d9

Browse files
Remove deprecated content_transfer_encoding (#8303)
1 parent 5fd2946 commit 7afb8d9

File tree

3 files changed

+6
-27
lines changed

3 files changed

+6
-27
lines changed

CHANGES/8303.breaking.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Removed ``content_transfer_encoding`` parameter in :py:meth:`FormData.add_field()
2+
<aiohttp.FormData.add_field>` and passing bytes no longer creates a file
3+
field unless the ``filename`` parameter is used -- by :user:`Dreamsorcerer`.

aiohttp/formdata.py

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import io
2-
import warnings
32
from typing import Any, Iterable, List, Optional
43
from urllib.parse import urlencode
54

@@ -50,18 +49,9 @@ def add_field(
5049
*,
5150
content_type: Optional[str] = None,
5251
filename: Optional[str] = None,
53-
content_transfer_encoding: Optional[str] = None,
5452
) -> None:
55-
if isinstance(value, io.IOBase):
53+
if isinstance(value, (io.IOBase, bytes, bytearray, memoryview)):
5654
self._is_multipart = True
57-
elif isinstance(value, (bytes, bytearray, memoryview)):
58-
msg = (
59-
"In v4, passing bytes will no longer create a file field. "
60-
"Please explicitly use the filename parameter or pass a BytesIO object."
61-
)
62-
if filename is None and content_transfer_encoding is None:
63-
warnings.warn(msg, DeprecationWarning)
64-
filename = name
6555

6656
type_options: MultiDict[str] = MultiDict({"name": name})
6757
if filename is not None and not isinstance(filename, str):
@@ -82,18 +72,6 @@ def add_field(
8272
)
8373
headers[hdrs.CONTENT_TYPE] = content_type
8474
self._is_multipart = True
85-
if content_transfer_encoding is not None:
86-
if not isinstance(content_transfer_encoding, str):
87-
raise TypeError(
88-
"content_transfer_encoding must be an instance"
89-
" of str. Got: %s" % content_transfer_encoding
90-
)
91-
msg = (
92-
"content_transfer_encoding is deprecated. "
93-
"To maintain compatibility with v4 please pass a BytesPayload."
94-
)
95-
warnings.warn(msg, DeprecationWarning)
96-
self._is_multipart = True
9775

9876
self._fields.append((type_options, headers, value))
9977

tests/test_web_functional.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ def fname(here: Any):
4949

5050
def new_dummy_form():
5151
form = FormData()
52-
with pytest.warns(DeprecationWarning, match="BytesPayload"):
53-
form.add_field("name", b"123", content_transfer_encoding="base64")
52+
form.add_field("name", b"123")
5453
return form
5554

5655

@@ -505,8 +504,7 @@ async def handler(request):
505504
return web.Response()
506505

507506
form = FormData()
508-
with pytest.warns(DeprecationWarning, match="BytesPayload"):
509-
form.add_field("name", b"123", content_transfer_encoding="base64")
507+
form.add_field("name", b"123")
510508

511509
app = web.Application()
512510
app.router.add_post("/", handler)

0 commit comments

Comments
 (0)