|
35 | 35 | from urllib3.filepost import encode_multipart_formdata |
36 | 36 | from urllib3.util import parse_url |
37 | 37 |
|
| 38 | +from . import _types as _t |
38 | 39 | from ._internal_utils import to_native_string, unicode_is_ascii |
39 | | -from ._types import SupportsRead as _SupportsRead |
40 | 40 | from .auth import HTTPBasicAuth |
41 | 41 | from .compat import ( |
42 | 42 | JSONDecodeError, |
|
87 | 87 |
|
88 | 88 | from typing_extensions import Self |
89 | 89 |
|
90 | | - from . import _types as _t |
91 | 90 | from .adapters import HTTPAdapter |
92 | 91 | from .cookies import RequestsCookieJar |
93 | 92 |
|
@@ -161,7 +160,7 @@ def _encode_params( |
161 | 160 |
|
162 | 161 | if isinstance(data, (str, bytes)): |
163 | 162 | return data |
164 | | - elif isinstance(data, _SupportsRead): |
| 163 | + elif _t.has_read(data): |
165 | 164 | return data |
166 | 165 | elif hasattr(data, "__iter__"): |
167 | 166 | result: list[tuple[bytes, bytes]] = [] |
@@ -236,9 +235,7 @@ def _encode_files( |
236 | 235 |
|
237 | 236 | if isinstance(fp, (str, bytes, bytearray)): |
238 | 237 | fdata = fp |
239 | | - # data that proxies attributes to underlying objects needs hasattr |
240 | | - # defensive check for untyped callers |
241 | | - elif isinstance(fp, _SupportsRead) or hasattr(fp, "read"): |
| 238 | + elif _t.has_read(fp): |
242 | 239 | fdata = fp.read() |
243 | 240 | elif fp is None: # defensive check for untyped callers |
244 | 241 | continue |
@@ -641,7 +638,7 @@ def prepare_body( |
641 | 638 | else: |
642 | 639 | if raw_data: |
643 | 640 | body = self._encode_params(raw_data) |
644 | | - if isinstance(data, basestring) or isinstance(data, _SupportsRead): |
| 641 | + if isinstance(data, basestring) or _t.has_read(data): |
645 | 642 | content_type = None |
646 | 643 | else: |
647 | 644 | content_type = "application/x-www-form-urlencoded" |
|
0 commit comments