Asynchronously read until we have matched the given regex. The result includes the data that matches the regex and anything that came before it. If ``max_bytes`` is not None, the connection will be closed if more than ``max_bytes`` bytes have been read and the regex
(
self, regex: bytes, max_bytes: Optional[int] = None
)
| 324 | return None |
| 325 | |
| 326 | def read_until_regex( |
| 327 | self, regex: bytes, max_bytes: Optional[int] = None |
| 328 | ) -> Awaitable[bytes]: |
| 329 | """Asynchronously read until we have matched the given regex. |
| 330 | |
| 331 | The result includes the data that matches the regex and anything |
| 332 | that came before it. |
| 333 | |
| 334 | If ``max_bytes`` is not None, the connection will be closed |
| 335 | if more than ``max_bytes`` bytes have been read and the regex is |
| 336 | not satisfied. |
| 337 | |
| 338 | .. versionchanged:: 4.0 |
| 339 | Added the ``max_bytes`` argument. The ``callback`` argument is |
| 340 | now optional and a `.Future` will be returned if it is omitted. |
| 341 | |
| 342 | .. versionchanged:: 6.0 |
| 343 | |
| 344 | The ``callback`` argument was removed. Use the returned |
| 345 | `.Future` instead. |
| 346 | |
| 347 | """ |
| 348 | future = self._start_read() |
| 349 | self._read_regex = re.compile(regex) |
| 350 | self._read_max_bytes = max_bytes |
| 351 | try: |
| 352 | self._try_inline_read() |
| 353 | except UnsatisfiableReadError as e: |
| 354 | # Handle this the same way as in _handle_events. |
| 355 | gen_log.info("Unsatisfiable read, closing connection: %s" % e) |
| 356 | self.close(exc_info=e) |
| 357 | return future |
| 358 | except: |
| 359 | # Ensure that the future doesn't log an error because its |
| 360 | # failure was never examined. |
| 361 | future.add_done_callback(lambda f: f.exception()) |
| 362 | raise |
| 363 | return future |
| 364 | |
| 365 | def read_until( |
| 366 | self, delimiter: bytes, max_bytes: Optional[int] = None |