MCPcopy Index your code
hub / github.com/python/cpython / readline

Method readline

Lib/asyncio/streams.py:541–570  ·  view source on GitHub ↗

Read chunk of data from the stream until newline (b'\n') is found. On success, return chunk that ends with newline. If only partial line can be read due to EOF, return incomplete line without terminating newline. When EOF was reached while no bytes read, empty bytes

(self)

Source from the content-addressed store, hash-verified

539 self._waiter = None
540
541 async def readline(self):
542 """Read chunk of data from the stream until newline (b'\n') is found.
543
544 On success, return chunk that ends with newline. If only partial
545 line can be read due to EOF, return incomplete line without
546 terminating newline. When EOF was reached while no bytes read, empty
547 bytes object is returned.
548
549 If limit is reached, ValueError will be raised. In that case, if
550 newline was found, complete line including newline will be removed
551 from internal buffer. Else, internal buffer will be cleared. Limit is
552 compared against part of the line without newline.
553
554 If stream was paused, this function will automatically resume it if
555 needed.
556 """
557 sep = b'\n'
558 seplen = len(sep)
559 try:
560 line = await self.readuntil(sep)
561 except exceptions.IncompleteReadError as e:
562 return e.partial
563 except exceptions.LimitOverrunError as e:
564 if self._buffer.startswith(sep, e.consumed):
565 del self._buffer[:e.consumed + seplen]
566 else:
567 self._buffer.clear()
568 self._maybe_resume_transport()
569 raise ValueError(e.args[0])
570 return line
571
572 async def readuntil(self, separator=b'\n'):
573 """Read data from the stream until ``separator`` is found.

Callers 12

__anext__Method · 0.95
test_readlineMethod · 0.95
test_at_eofMethod · 0.95
test_readline_limitMethod · 0.95
test_readline_eofMethod · 0.95
test_exception_waiterMethod · 0.95
test_exception_cancelMethod · 0.95

Calls 4

readuntilMethod · 0.95
startswithMethod · 0.45
clearMethod · 0.45

Tested by 11

test_readlineMethod · 0.76
test_at_eofMethod · 0.76
test_readline_limitMethod · 0.76
test_readline_eofMethod · 0.76
test_exception_waiterMethod · 0.76
test_exception_cancelMethod · 0.76