MCPcopy Create free account
hub / github.com/EasyIME/PIME / read_until_regex

Method read_until_regex

python/python3/tornado/iostream.py:329–366  ·  view source on GitHub ↗

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
    )

Source from the content-addressed store, hash-verified

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

Calls 4

_start_readMethod · 0.95
_try_inline_readMethod · 0.95
closeMethod · 0.95
infoMethod · 0.80