nntp.fifo¶
A reasonably efficient FIFO buffer. Copyright (C) 2013-2020 Byron Platt
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
Classes¶
FIFO byte buffer that reads CRLF-terminated lines. |
Module Contents¶
- class nntp.fifo.BytesFifo(data: bytes = b'')¶
FIFO byte buffer that reads CRLF-terminated lines.
Writes are queued and only joined into the buffer once they complete a line (or on read()), so many small writes are cheap and a long partial line is not copied or searched again on every write. Iterating yields complete lines and stops at the first incomplete one; iteration can resume after more data is written.
- _buf = b''¶
- _buflist: list[bytes] = []¶
- _pending = 0¶
- _eol_queued = False¶
- _pos = 0¶
- __len__() int¶
Number of unread bytes, including queued writes.
- __next__() bytes¶
- _append() None¶
- _advance(newpos: int) None¶
- write(data: bytes) None¶
Append data to the end of the buffer.
- read(length: int = 0) bytes¶
Remove and return up to length bytes.
- Parameters:
length – Maximum number of bytes to read. A length of 0 (the default) reads all buffered data.
- readline() bytes¶
Remove and return one line, including its CRLF.
- Returns:
The line, or b”” if no complete line is buffered yet.