Read at most amt bytes from the stream. If the amt argument is omitted, read all data.
(self, amt=None)
| 78 | raise |
| 79 | |
| 80 | def read(self, amt=None): |
| 81 | """Read at most amt bytes from the stream. |
| 82 | |
| 83 | If the amt argument is omitted, read all data. |
| 84 | """ |
| 85 | try: |
| 86 | chunk = self._raw_stream.read(amt) |
| 87 | except URLLib3ReadTimeoutError as e: |
| 88 | # TODO: the url will be None as urllib3 isn't setting it yet |
| 89 | raise ReadTimeoutError(endpoint_url=e.url, error=e) |
| 90 | self._amount_read += len(chunk) |
| 91 | if amt is None or (not chunk and amt > 0): |
| 92 | # If the server sends empty contents or |
| 93 | # we ask to read all of the contents, then we know |
| 94 | # we need to verify the content length. |
| 95 | self._verify_content_length() |
| 96 | return chunk |
| 97 | |
| 98 | def __iter__(self): |
| 99 | """Return an iterator to yield 1k chunks from the raw stream.""" |