Skip to content

Commit

Permalink
chore: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhantgoel committed Nov 5, 2024
1 parent 26c59e1 commit dd9d439
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 56 deletions.
3 changes: 2 additions & 1 deletion streaming_form_data/targets.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import hashlib
from pathlib import Path
import smart_open # type: ignore
from typing import Callable, List, Optional

import smart_open # type: ignore


class BaseTarget:
"""
Expand Down
72 changes: 17 additions & 55 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ def test_multiple_inputs():
third
-----------------------------111217161535371856203688828--
""".replace(
b"\n", b"\r\n"
)
""".replace(b"\n", b"\r\n")

target = ValueTarget()

Expand All @@ -158,12 +156,10 @@ def test_multiple_inputs():
"Content-Type": "multipart/form-data; boundary=111217161535371856203688828"
}
)
parser.register("files", target)
parser.register("files")

parser.data_received(data)

parser.register("files", FileTarget("first.txt"))

breakpoint()
assert target.multipart_filename == "ab.txt"

Expand Down Expand Up @@ -406,9 +402,7 @@ def test_parameter_contains_part_of_delimiter():
Foo
--123
--1234--""".replace(
b"\n", b"\r\n"
)
--1234--""".replace(b"\n", b"\r\n")

target = ValueTarget()

Expand Down Expand Up @@ -490,9 +484,7 @@ def test_file_upload():
Content-Disposition: form-data; name="files"; filename="ab.txt"
Foo
--1234--""".replace(
b"\n", b"\r\n"
)
--1234--""".replace(b"\n", b"\r\n")

target = ValueTarget()

Expand All @@ -519,9 +511,7 @@ def test_directory_upload(tmp_path):
Content-Disposition: form-data; name="files"; filename="cd.txt"
Bar
--1234--""".replace(
b"\n", b"\r\n"
)
--1234--""".replace(b"\n", b"\r\n")

target = DirectoryTarget(tmp_path)

Expand Down Expand Up @@ -550,9 +540,7 @@ def test_unquoted_names():
Content-Disposition: form-data; name=files; filename=ab.txt
Foo
--1234--""".replace(
b"\n", b"\r\n"
)
--1234--""".replace(b"\n", b"\r\n")

target = ValueTarget()

Expand Down Expand Up @@ -584,9 +572,7 @@ def test_special_filenames():
Content-Disposition: form-data; name=files; filename={}
Foo
--1234--""".format(
filename
)
--1234--""".format(filename)
.replace("\n", "\r\n")
.encode("utf-8")
)
Expand All @@ -609,9 +595,7 @@ def test_boundary_starts_and_ends_with_quotes():
Content-Disposition: form-data; name="files"; filename="ab.txt"
Foo
--1234--""".replace(
b"\n", b"\r\n"
)
--1234--""".replace(b"\n", b"\r\n")

target = ValueTarget()

Expand All @@ -631,11 +615,7 @@ def test_missing_headers():
--1234
Foo
--1234--""".replace(
"\n", "\r\n"
).encode(
"utf-8"
)
--1234--""".replace("\n", "\r\n").encode("utf-8")

target = ValueTarget()

Expand All @@ -655,9 +635,7 @@ def test_invalid_content_disposition():
Content-Disposition: invalid; name="files"; filename="ab.txt"
Foo
--1234--""".replace(
b"\n", b"\r\n"
)
--1234--""".replace(b"\n", b"\r\n")

target = ValueTarget()

Expand All @@ -678,9 +656,7 @@ def test_without_name_parameter():
Content-Disposition: form-data; filename="ab.txt"
Foo
--1234--""".replace(
b"\n", b"\r\n"
)
--1234--""".replace(b"\n", b"\r\n")

target = ValueTarget()

Expand All @@ -701,9 +677,7 @@ def test_data_after_final_boundary():
Foo
--1234--
""".replace(
b"\n", b"\r\n"
)
""".replace(b"\n", b"\r\n")

target = ValueTarget()

Expand Down Expand Up @@ -734,9 +708,7 @@ def test_missing_filename_directive():
Foo
--1234--
""".replace(
b"\n", b"\r\n"
)
""".replace(b"\n", b"\r\n")

target = ValueTarget()

Expand Down Expand Up @@ -793,9 +765,7 @@ def test_target_exceeds_max_size():
Content-Disposition: form-data; name="files"; filename="ab.txt"
Foo
--1234--""".replace(
b"\n", b"\r\n"
)
--1234--""".replace(b"\n", b"\r\n")

target = ValueTarget(validator=MaxSizeValidator(1))

Expand All @@ -817,9 +787,7 @@ def test_file_target_exceeds_max_size(tmp_path):
Content-Disposition: form-data; name="files"; filename="ab.txt"
Foo
--1234--""".replace(
b"\n", b"\r\n"
)
--1234--""".replace(b"\n", b"\r\n")

target = FileTarget(tmp_path / "file.txt", validator=MaxSizeValidator(1))

Expand Down Expand Up @@ -896,9 +864,7 @@ def test_extra_headers():
Content-Transfer-Encoding: quoted-printable
Joe owes =80100.
--1234--""".replace(
b"\n", b"\r\n"
)
--1234--""".replace(b"\n", b"\r\n")

target = ValueTarget()

Expand All @@ -925,11 +891,7 @@ def test_case_insensitive_content_disposition_header():
{header}: form-data; name="files"; filename="ab.txt"
Foo
--1234--""".replace(
b"\n", b"\r\n"
).replace(
b"{header}", header.encode("utf-8")
)
--1234--""".replace(b"\n", b"\r\n").replace(b"{header}", header.encode("utf-8"))

target = ValueTarget()

Expand Down

0 comments on commit dd9d439

Please sign in to comment.