From: Tom Christie Date: Mon, 12 Dec 2022 16:31:29 +0000 (+0000) Subject: Drop private import of 'format_form_param' from tests (#2500) X-Git-Tag: 0.23.2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b82fbe2c139162e10d1a3ee1b4579cc8d72b3535;p=thirdparty%2Fhttpx.git Drop private import of 'format_form_param' from tests (#2500) * Drop private import of 'format_form_param' from tests * Drop unused code path --- diff --git a/httpx/_utils.py b/httpx/_utils.py index 126936db..1f64deed 100644 --- a/httpx/_utils.py +++ b/httpx/_utils.py @@ -81,12 +81,10 @@ def is_known_encoding(encoding: str) -> bool: return True -def format_form_param(name: str, value: typing.Union[str, bytes]) -> bytes: +def format_form_param(name: str, value: str) -> bytes: """ Encode a name/value pair within a multipart form. """ - if isinstance(value, bytes): - value = value.decode() def replacer(match: typing.Match[str]) -> str: return _HTML5_FORM_ENCODING_REPLACEMENTS[match.group(0)] diff --git a/tests/test_multipart.py b/tests/test_multipart.py index 6d281ed7..99f97c51 100644 --- a/tests/test_multipart.py +++ b/tests/test_multipart.py @@ -8,7 +8,6 @@ import pytest import httpx from httpx._content import encode_request -from httpx._utils import format_form_param def echo_request_content(request: httpx.Request) -> httpx.Response: @@ -437,17 +436,29 @@ def test_multipart_rewinds_files(): class TestHeaderParamHTML5Formatting: def test_unicode(self): - param = format_form_param("filename", "n\u00e4me") - assert param == b'filename="n\xc3\xa4me"' + filename = "n\u00e4me" + expected = b'filename="n\xc3\xa4me"' + files = {"upload": (filename, b"")} + request = httpx.Request("GET", "https://www.example.com", files=files) + assert expected in request.read() def test_ascii(self): - param = format_form_param("filename", b"name") - assert param == b'filename="name"' + filename = "name" + expected = b'filename="name"' + files = {"upload": (filename, b"")} + request = httpx.Request("GET", "https://www.example.com", files=files) + assert expected in request.read() def test_unicode_escape(self): - param = format_form_param("filename", "hello\\world\u0022") - assert param == b'filename="hello\\\\world%22"' + filename = "hello\\world\u0022" + expected = b'filename="hello\\\\world%22"' + files = {"upload": (filename, b"")} + request = httpx.Request("GET", "https://www.example.com", files=files) + assert expected in request.read() def test_unicode_with_control_character(self): - param = format_form_param("filename", "hello\x1A\x1B\x1C") - assert param == b'filename="hello%1A\x1B%1C"' + filename = "hello\x1A\x1B\x1C" + expected = b'filename="hello%1A\x1B%1C"' + files = {"upload": (filename, b"")} + request = httpx.Request("GET", "https://www.example.com", files=files) + assert expected in request.read()