requests: Fix detection of iterators in chunked data requests.

Chunked detection does not work as generators never have an `__iter__`
attribute.  They do have `__next__`.

Example that now works with this commit:

    def read_in_chunks(file_object, chunk_size=4096):
        while True:
            data = file_object.read(chunk_size)
            if not data:
                break
            yield data

    file = open(filename, "rb")
    r = requests.post(url, data=read_in_chunks(file))
pull/670/head v1.21.0
Brian Whitman 2023-05-29 20:27:49 -07:00 zatwierdzone przez Damien George
rodzic 46748d2817
commit e025c843b6
2 zmienionych plików z 2 dodań i 2 usunięć

Wyświetl plik

@ -1,3 +1,3 @@
metadata(version="0.8.0", pypi="requests")
metadata(version="0.8.1", pypi="requests")
package("requests")

Wyświetl plik

@ -45,7 +45,7 @@ def request(
parse_headers=True,
):
redirect = None # redirection url, None means no redirection
chunked_data = data and getattr(data, "__iter__", None) and not getattr(data, "__len__", None)
chunked_data = data and getattr(data, "__next__", None) and not getattr(data, "__len__", None)
if auth is not None:
import ubinascii