Skip to content

Commit 0fc5e2d

Browse files
committed
Remove content_type from Field
1 parent f1e28d6 commit 0fc5e2d

File tree

2 files changed

+5
-32
lines changed

2 files changed

+5
-32
lines changed

python_multipart/multipart.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def finalize(self) -> None: ...
6868
def close(self) -> None: ...
6969

7070
class FieldProtocol(_FormProtocol, Protocol):
71-
def __init__(self, name: bytes, content_type: str | None = None) -> None: ...
71+
def __init__(self, name: bytes) -> None: ...
7272

7373
def set_none(self) -> None: ...
7474

@@ -226,10 +226,9 @@ class Field:
226226
content_type: The value of the Content-Type header for this field.
227227
"""
228228

229-
def __init__(self, name: bytes, content_type: str | None = None) -> None:
229+
def __init__(self, name: bytes) -> None:
230230
self._name = name
231231
self._value: list[bytes] = []
232-
self._content_type = content_type
233232

234233
# We cache the joined version of _value for speed.
235234
self._cache = _missing
@@ -321,11 +320,6 @@ def value(self) -> bytes | None:
321320
assert isinstance(self._cache, bytes) or self._cache is None
322321
return self._cache
323322

324-
@property
325-
def content_type(self) -> str | None:
326-
"""This property returns the content_type value of the field."""
327-
return self._content_type
328-
329323
def __eq__(self, other: object) -> bool:
330324
if isinstance(other, Field):
331325
return self.field_name == other.field_name and self.value == other.value
@@ -1601,7 +1595,7 @@ def on_field_name(data: bytes, start: int, end: int) -> None:
16011595
def on_field_data(data: bytes, start: int, end: int) -> None:
16021596
nonlocal f
16031597
if f is None:
1604-
f = FieldClass(b"".join(name_buffer), content_type=None)
1598+
f = FieldClass(b"".join(name_buffer))
16051599
del name_buffer[:]
16061600
f.write(data[start:end])
16071601

@@ -1611,7 +1605,7 @@ def on_field_end() -> None:
16111605
if f is None:
16121606
# If we get here, it's because there was no field data.
16131607
# We create a field, set it to None, and then continue.
1614-
f = FieldClass(b"".join(name_buffer), content_type=None)
1608+
f = FieldClass(b"".join(name_buffer))
16151609
del name_buffer[:]
16161610
f.set_none()
16171611

@@ -1700,7 +1694,7 @@ def on_headers_finished() -> None:
17001694
content_type_b = headers.get("content-type")
17011695
content_type = content_type_b.decode("latin-1") if content_type_b is not None else None
17021696
if file_name is None:
1703-
f_multi = FieldClass(field_name, content_type=content_type)
1697+
f_multi = FieldClass(field_name)
17041698
else:
17051699
f_multi = FileClass(
17061700
file_name, field_name, config=cast("FileConfig", self.config), content_type=content_type

tests/test_multipart.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -971,27 +971,6 @@ def test_file_content_type_header(self) -> None:
971971
actual_content_type = self.files[0].content_type
972972
self.assertEqual(actual_content_type, expected_content_type)
973973

974-
def test_field_content_type_header(self) -> None:
975-
"""
976-
This test checks content-tpye for a field part are read and passed.
977-
"""
978-
# Load test data.
979-
test_file = "single_field.http"
980-
with open(os.path.join(http_tests_dir, test_file), "rb") as f:
981-
test_data = f.read()
982-
983-
expected_content_type = None
984-
985-
# Create form parser.
986-
self.make(boundary="----WebKitFormBoundaryTkr3kCBQlBe1nrhc")
987-
self.f.write(test_data)
988-
self.f.finalize()
989-
990-
# Assert that our field is here.
991-
self.assertEqual(1, len(self.fields))
992-
actual_content_type = self.fields[0].content_type
993-
self.assertEqual(actual_content_type, expected_content_type)
994-
995974
def test_request_body_fuzz(self) -> None:
996975
"""
997976
This test randomly fuzzes the request body to ensure that no strange

0 commit comments

Comments
 (0)