Skip to content
Myr

Fix `_encode_files` detection for `__getattr__`-based file wrappers (#7502)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Loïc Pernod · committed by GitHub · parent 661970d · Browse files · 2 files+14 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+14 added−1 removed

  • tests:+11 added−0 removed
  • other:+3 added−1 removed

2 files+14 added−1 removed

modified:src/requests/models.py+3 added-1 removed
234 unmodified lines
235 fp = v236237 if isinstance(fp, (str, bytes, bytearray)):238 fdata = fp239 elif isinstance(fp, _SupportsRead): # defensive check for untyped callers239 # data that proxies attributes to underlying objects needs hasattr240 # defensive check for untyped callers241 elif isinstance(fp, _SupportsRead) or hasattr(fp, "read"):242 fdata = fp.read()243 elif fp is None: # defensive check for untyped callers244 continue245 else:
942 unmodified lines
modified:tests/test_requests.py+11 added
1085 unmodified lines
1086 files={"file": ("test_requests.py", f)},1087 )1088 assert r.status_code == 20010891090 def test_post_named_tempfile(self, httpbin):1091 with tempfile.NamedTemporaryFile(mode="w+") as f:1092 f.write("named temp file contents\n")1093 f.seek(0)1094 r = requests.post(1095 httpbin("post"),1096 files={"file": f},1097 )1098 assert r.status_code == 2001099 assert r.json()["files"]["file"] == "named temp file contents\n"11001101 @pytest.mark.parametrize(1102 "data",1103 (1104 {"stuff": "ëlïxr"},
1975 unmodified lines