(self, b: bytearray)
| 532 | return b"" |
| 533 | |
| 534 | def readinto(self, b: bytearray) -> int | None: # type: ignore[override] |
| 535 | size = len(b) |
| 536 | remaining = self.limit - self._pos |
| 537 | |
| 538 | if remaining <= 0: |
| 539 | self.on_exhausted() |
| 540 | return 0 |
| 541 | |
| 542 | if hasattr(self._stream, "readinto"): |
| 543 | # Use stream.readinto if it's available. |
| 544 | if size <= remaining: |
| 545 | # The size fits in the remaining limit, use the buffer directly. |
| 546 | try: |
| 547 | out_size: int | None = self._stream.readinto(b) |
| 548 | except (OSError, ValueError) as e: |
| 549 | self.on_disconnect(error=e) |
| 550 | return 0 |
| 551 | else: |
| 552 | # Use a temp buffer with the remaining limit as the size. |
| 553 | temp_b = bytearray(remaining) |
| 554 | |
| 555 | try: |
| 556 | out_size = self._stream.readinto(temp_b) |
| 557 | except (OSError, ValueError) as e: |
| 558 | self.on_disconnect(error=e) |
| 559 | return 0 |
| 560 | |
| 561 | if out_size: |
| 562 | b[:out_size] = temp_b |
| 563 | else: |
| 564 | # WSGI requires that stream.read is available. |
| 565 | try: |
| 566 | data = self._stream.read(min(size, remaining)) |
| 567 | except (OSError, ValueError) as e: |
| 568 | self.on_disconnect(error=e) |
| 569 | return 0 |
| 570 | |
| 571 | out_size = len(data) |
| 572 | b[:out_size] = data |
| 573 | |
| 574 | if not out_size: |
| 575 | # Read zero bytes from the stream. |
| 576 | self.on_disconnect() |
| 577 | return 0 |
| 578 | |
| 579 | self._pos += out_size |
| 580 | return out_size |
| 581 | |
| 582 | def readall(self) -> bytes: |
| 583 | if self.is_exhausted: |
nothing calls this directly
no test coverage detected