MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / readline

Method readline

tools/python-3.11.9-amd64/Lib/_pyio.py:540–580  ·  view source on GitHub ↗

r"""Read and return a line of bytes from the stream. If size is specified, at most size bytes will be read. Size should be an int. The line terminator is always b'\n' for binary files; for text files, the newlines argument to open can be used to select the lin

(self, size=-1)

Source from the content-addressed store, hash-verified

538 ### Readline[s] and writelines ###
539
540 def readline(self, size=-1):
541 r"""Read and return a line of bytes from the stream.
542
543 If size is specified, at most size bytes will be read.
544 Size should be an int.
545
546 The line terminator is always b'\n' for binary files; for text
547 files, the newlines argument to open can be used to select the line
548 terminator(s) recognized.
549 """
550 # For backwards compatibility, a (slowish) readline().
551 if hasattr(self, "peek"):
552 def nreadahead():
553 readahead = self.peek(1)
554 if not readahead:
555 return 1
556 n = (readahead.find(b"\n") + 1) or len(readahead)
557 if size >= 0:
558 n = min(n, size)
559 return n
560 else:
561 def nreadahead():
562 return 1
563 if size is None:
564 size = -1
565 else:
566 try:
567 size_index = size.__index__
568 except AttributeError:
569 raise TypeError(f"{size!r} is not an integer")
570 else:
571 size = size_index()
572 res = bytearray()
573 while size < 0 or len(res) < size:
574 b = self.read(nreadahead())
575 if not b:
576 break
577 res += b
578 if res.endswith(b"\n"):
579 break
580 return bytes(res)
581
582 def __iter__(self):
583 self._checkClosed()

Callers 1

__next__Method · 0.95

Calls 2

endswithMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected