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 line
(self, size=-1)
| 507 | ### Readline[s] and writelines ### |
| 508 | |
| 509 | def readline(self, size=-1): |
| 510 | r"""Read and return a line of bytes from the stream. |
| 511 | |
| 512 | If size is specified, at most size bytes will be read. |
| 513 | Size should be an int. |
| 514 | |
| 515 | The line terminator is always b'\n' for binary files; for text |
| 516 | files, the newlines argument to open can be used to select the line |
| 517 | terminator(s) recognized. |
| 518 | """ |
| 519 | # For backwards compatibility, a (slowish) readline(). |
| 520 | if hasattr(self, "peek"): |
| 521 | def nreadahead(): |
| 522 | readahead = self.peek(1) |
| 523 | if not readahead: |
| 524 | return 1 |
| 525 | n = (readahead.find(b"\n") + 1) or len(readahead) |
| 526 | if size >= 0: |
| 527 | n = min(n, size) |
| 528 | return n |
| 529 | else: |
| 530 | def nreadahead(): |
| 531 | return 1 |
| 532 | if size is None: |
| 533 | size = -1 |
| 534 | else: |
| 535 | try: |
| 536 | size_index = size.__index__ |
| 537 | except AttributeError: |
| 538 | raise TypeError(f"{size!r} is not an integer") |
| 539 | else: |
| 540 | size = size_index() |
| 541 | res = bytearray() |
| 542 | while size < 0 or len(res) < size: |
| 543 | b = self.read(nreadahead()) |
| 544 | if not b: |
| 545 | break |
| 546 | res += b |
| 547 | if res.endswith(b"\n"): |
| 548 | break |
| 549 | return res.take_bytes() |
| 550 | |
| 551 | def __iter__(self): |
| 552 | self._checkClosed() |
no test coverage detected