Text Protocol Lines¶
pcapkit.utilities.lines reads and writes what the line-based text
protocols exchange: CRLF-terminated lines, a reply that runs over several lines,
a block of dot-stuffed lines ended by a line holding a single period, and the
text a line carries. FTP and SMTP share it, so it lives beside neither
(Choosing Between utilities and corekit).
Added in version 1.10.0.
- pcapkit.utilities.lines.split_lines(data)[source]¶
Cut
datainto its CRLF-terminated lines.Only a CRLF ends a line, so a CR or LF outside one stays in the line holding it (RFC 5321 Section 2.3.8), for the caller to accept or refuse.
- pcapkit.utilities.lines.join_lines(lines)[source]¶
Write each of
linesfollowed by its CRLF, assplit_lines()reads them.
- pcapkit.utilities.lines.closes_reply(code, lines, *, marked)[source]¶
Whether
linesend a multi-line reply that opened withcode.A multi-line reply opens with
codeand a hyphen, and ends at the first line opening withcodeand SP (RFC 959 Section 4.2). Withmarked, as in SMTP, every line before that one opens withcodeand a hyphen too, and the closing line may becodealone, which a client must accept (RFC 5321 Section 4.2.1). Without it, as in FTP, those lines are free text, which may open withcodeand a hyphen as well.- Parameters:
- Return type:
- Returns:
Whether each line is
bytesholding no LF, and the last line, and only the last, closes the reply.
- pcapkit.utilities.lines.block_end(lines)[source]¶
Index of the line that ends a block of
lines.A block ends at a line holding a single period, as SMTP’s mail data does (RFC 5321 Section 4.1.1.4), and a line of the block opening with a period is sent with one more (
stuff()), so none holds one alone.
- pcapkit.utilities.lines.stuff(line)[source]¶
Dot-stuff
line, a line of a block, for sending.A line opening with a period is sent with one more (RFC 5321 Section 4.5.2).
- pcapkit.utilities.lines.unstuff(line)[source]¶
Undo the dot-stuffing of
line, a line of a block as sent.A line opening with a period and holding more loses that period (RFC 5321 Section 4.5.2), so
stuff()and then this give back any line. A line holding a single period ends the block (block_end()), so it comes back as is.
- pcapkit.utilities.lines.decode_text(text)[source]¶
Decode the text a line carries, recording how to encode it back.
The text is decoded with the charset chardet detects, or as
'unicode_escape'with errors replaced if that fails. Where the result does not encode back totextas UTF-8, the detected charset is returned with it, or'latin-1', decoding again, if that does not reproducetexteither, so the octets survive a rebuild.