Asynchronously read until we have found the given delimiter. The result includes all the data read including the delimiter. If ``max_bytes`` is not None, the connection will be closed if more than ``max_bytes`` bytes have been read and the delimiter is not found.
(
self, delimiter: bytes, max_bytes: Optional[int] = None
)
| 366 | return future |
| 367 | |
| 368 | def read_until( |
| 369 | self, delimiter: bytes, max_bytes: Optional[int] = None |
| 370 | ) -> Awaitable[bytes]: |
| 371 | """Asynchronously read until we have found the given delimiter. |
| 372 | |
| 373 | The result includes all the data read including the delimiter. |
| 374 | |
| 375 | If ``max_bytes`` is not None, the connection will be closed |
| 376 | if more than ``max_bytes`` bytes have been read and the delimiter |
| 377 | is not found. |
| 378 | |
| 379 | .. versionchanged:: 4.0 |
| 380 | Added the ``max_bytes`` argument. The ``callback`` argument is |
| 381 | now optional and a `.Future` will be returned if it is omitted. |
| 382 | |
| 383 | .. versionchanged:: 6.0 |
| 384 | |
| 385 | The ``callback`` argument was removed. Use the returned |
| 386 | `.Future` instead. |
| 387 | """ |
| 388 | future = self._start_read() |
| 389 | self._read_delimiter = delimiter |
| 390 | self._read_max_bytes = max_bytes |
| 391 | try: |
| 392 | self._try_inline_read() |
| 393 | except UnsatisfiableReadError as e: |
| 394 | # Handle this the same way as in _handle_events. |
| 395 | gen_log.info("Unsatisfiable read, closing connection: %s" % e) |
| 396 | self.close(exc_info=e) |
| 397 | return future |
| 398 | except: |
| 399 | future.add_done_callback(lambda f: f.exception()) |
| 400 | raise |
| 401 | return future |
| 402 | |
| 403 | def read_bytes(self, num_bytes: int, partial: bool = False) -> Awaitable[bytes]: |
| 404 | """Asynchronously read a number of bytes. |