Push some new data into this object.
(self, data)
| 100 | self._lines.appendleft(line) |
| 101 | |
| 102 | def push(self, data): |
| 103 | """Push some new data into this object.""" |
| 104 | self._partial.write(data) |
| 105 | if '\n' not in data and '\r' not in data: |
| 106 | # No new complete lines, wait for more. |
| 107 | return |
| 108 | |
| 109 | # Crack into lines, preserving the linesep characters. |
| 110 | self._partial.seek(0) |
| 111 | parts = self._partial.readlines() |
| 112 | self._partial.seek(0) |
| 113 | self._partial.truncate() |
| 114 | |
| 115 | # If the last element of the list does not end in a newline, then treat |
| 116 | # it as a partial line. We only check for '\n' here because a line |
| 117 | # ending with '\r' might be a line that was split in the middle of a |
| 118 | # '\r\n' sequence (see bugs 1555570 and 1721862). |
| 119 | if not parts[-1].endswith('\n'): |
| 120 | self._partial.write(parts.pop()) |
| 121 | self.pushlines(parts) |
| 122 | |
| 123 | def pushlines(self, lines): |
| 124 | self._lines.extend(lines) |