nntp.yenc¶
yEnc decoding and trailer checks. 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¶
A yEnc decoder that keeps a running CRC32 of the decoded data. |
Functions¶
|
Parse the keyword=value pairs of a =ybegin, =ypart or =yend line. |
|
Extract the CRC32 value from a yEnc trailer. |
|
Check decoded data against a =yend trailer. |
Module Contents¶
- nntp.yenc.parse_keywords(line: bytes) dict[str, str]¶
Parse the keyword=value pairs of a =ybegin, =ypart or =yend line.
The name keyword (on =ybegin) runs to the end of the line and may contain spaces and “=”, so it and anything after it is left out.
- nntp.yenc.trailer_crc32(trailer: bytes, *, part: bool = False) int | None¶
Extract the CRC32 value from a yEnc trailer.
- Parameters:
trailer – The =yend line.
part – Return the CRC of this part (pcrc32) rather than of the whole file (crc32), for multipart posts.
- nntp.yenc.check_trailer(trailer: bytes, size: int, crc32: int, *, part: bool) str | None¶
Check decoded data against a =yend trailer.
- Parameters:
trailer – The =yend line.
size – Length of the decoded data.
crc32 – CRC32 of the decoded data.
part – The data is one part of a multipart post, so it is checked against pcrc32 rather than the whole-file crc32.
- Returns:
A description of the first problem, or None if the data matches. The size is required; a CRC is optional but must be valid if present.
- class nntp.yenc.YEnc¶
A yEnc decoder that keeps a running CRC32 of the decoded data.
- crc32 = 0¶
- _escape = False¶
- decode(buf: bytes) bytes¶
Decode a chunk of yEnc data and update crc32.
CR and LF are removed. An escape split across calls (a chunk ending in “=”) is completed by the next call.
- Parameters:
buf – yEnc data, without the =ybegin, =ypart and =yend lines.
- Returns:
The decoded bytes.