MCPcopy Index your code
hub / github.com/RustPython/RustPython / readuntil

Method readuntil

Lib/asyncio/streams.py:574–686  ·  view source on GitHub ↗

Read data from the stream until ``separator`` is found. On success, the data and separator will be removed from the internal buffer (consumed). Returned data will include the separator at the end. Configured stream limit is used to check result. Limit sets the

(self, separator=b'\n')

Source from the content-addressed store, hash-verified

572 return line
573
574 async def readuntil(self, separator=b'\n'):
575 """Read data from the stream until ``separator`` is found.
576
577 On success, the data and separator will be removed from the
578 internal buffer (consumed). Returned data will include the
579 separator at the end.
580
581 Configured stream limit is used to check result. Limit sets the
582 maximal length of data that can be returned, not counting the
583 separator.
584
585 If an EOF occurs and the complete separator is still not found,
586 an IncompleteReadError exception will be raised, and the internal
587 buffer will be reset. The IncompleteReadError.partial attribute
588 may contain the separator partially.
589
590 If the data cannot be read because of over limit, a
591 LimitOverrunError exception will be raised, and the data
592 will be left in the internal buffer, so it can be read again.
593
594 The ``separator`` may also be a tuple of separators. In this
595 case the return value will be the shortest possible that has any
596 separator as the suffix. For the purposes of LimitOverrunError,
597 the shortest possible separator is considered to be the one that
598 matched.
599 """
600 if isinstance(separator, tuple):
601 # Makes sure shortest matches wins
602 separator = sorted(separator, key=len)
603 else:
604 separator = [separator]
605 if not separator:
606 raise ValueError('Separator should contain at least one element')
607 min_seplen = len(separator[0])
608 max_seplen = len(separator[-1])
609 if min_seplen == 0:
610 raise ValueError('Separator should be at least one-byte string')
611
612 if self._exception is not None:
613 raise self._exception
614
615 # Consume whole buffer except last bytes, which length is
616 # one less than max_seplen. Let's check corner cases with
617 # separator[-1]='SEPARATOR':
618 # * we have received almost complete separator (without last
619 # byte). i.e buffer='some textSEPARATO'. In this case we
620 # can safely consume max_seplen - 1 bytes.
621 # * last byte of buffer is first byte of separator, i.e.
622 # buffer='abcdefghijklmnopqrS'. We may safely consume
623 # everything except that last byte, but this require to
624 # analyze bytes of buffer that match partial separator.
625 # This is slow and/or require FSM. For this case our
626 # implementation is not optimal, since require rescanning
627 # of data that is known to not belong to separator. In
628 # real world, separator will not be so long to notice
629 # performance problems. Even when reading MIME-encoded
630 # messages :)
631

Calls 8

_wait_for_dataMethod · 0.95
isinstanceFunction · 0.85
sortedFunction · 0.85
lenFunction · 0.85
maxFunction · 0.85
findMethod · 0.45
clearMethod · 0.45