diff --git a/streaming_form_data/targets.py b/streaming_form_data/targets.py index 21a0474..6b9c825 100644 --- a/streaming_form_data/targets.py +++ b/streaming_form_data/targets.py @@ -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: """ diff --git a/tests/test_parser.py b/tests/test_parser.py index f2c77ae..5b9f365 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -147,9 +147,7 @@ def test_multiple_inputs(): third -----------------------------111217161535371856203688828-- -""".replace( - b"\n", b"\r\n" - ) +""".replace(b"\n", b"\r\n") target = ValueTarget() @@ -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" @@ -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() @@ -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() @@ -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) @@ -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() @@ -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") ) @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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)) @@ -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)) @@ -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() @@ -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()