Writes chunk of data to a stream by using different writers. writer uses filter to modify chunk of data. write_eof() indicates end of stream. writer can't be used after write_eof() method being called. write() return drain future.
(self, chunk, *,
drain=False, EOF_MARKER=EOF_MARKER, EOL_MARKER=EOL_MARKER)
| 690 | self.headers[hdrs.CONNECTION] = connection |
| 691 | |
| 692 | def write(self, chunk, *, |
| 693 | drain=False, EOF_MARKER=EOF_MARKER, EOL_MARKER=EOL_MARKER): |
| 694 | class="st">"""Writes chunk of data to a stream by using different writers. |
| 695 | |
| 696 | writer uses filter to modify chunk of data. |
| 697 | write_eof() indicates end of stream. |
| 698 | writer can&class="cm">#x27;t be used after write_eof() method being called. |
| 699 | write() return drain future. |
| 700 | class="st">""" |
| 701 | assert (isinstance(chunk, (bytes, bytearray)) or |
| 702 | chunk is EOF_MARKER), chunk |
| 703 | |
| 704 | size = self.output_length |
| 705 | |
| 706 | if self._send_headers and not self.headers_sent: |
| 707 | self.send_headers() |
| 708 | |
| 709 | assert self.writer is not None, &class="cm">#x27;send_headers() is not called.' |
| 710 | |
| 711 | if self.filter: |
| 712 | chunk = self.filter.send(chunk) |
| 713 | while chunk not in (EOF_MARKER, EOL_MARKER): |
| 714 | if chunk: |
| 715 | self.writer.send(chunk) |
| 716 | chunk = next(self.filter) |
| 717 | else: |
| 718 | if chunk is not EOF_MARKER: |
| 719 | self.writer.send(chunk) |
| 720 | |
| 721 | self._output_size += self.output_length - size |
| 722 | |
| 723 | if self._output_size > 64 * 1024: |
| 724 | if drain: |
| 725 | self._output_size = 0 |
| 726 | return self.transport.drain() |
| 727 | |
| 728 | return () |
| 729 | |
| 730 | def write_eof(self): |
| 731 | self.write(EOF_MARKER) |