Expand description
DICT (RFC 2229) wire format: command parsing and response rendering.
Everything here is a pure function of its arguments, so the session loop, the action
executor and the tests all share one definition of what a DICT line looks like. The model
never writes a byte of framing: it supplies words, database names and free text, and this
module decides the status lines, the quoting, the dot-stuffing and the terminator. A model
that writes a definition whose line happens to be . produces a line reading .. on the
wire, and the client’s un-stuffing turns it back into . — not a premature end of the text.
Structs§
- Definition
- One definition, as the model supplies it.
Enums§
- ArgError
- Why a command line could not be split into parameters.
Constants§
- ERROR_
CODES - The 5xx codes
send_dict_errormay send, each with RFC 2229’s own text as its default. - MAX_
LINE_ BYTES - The longest command line a peer may send, including the trailing CRLF.
- MAX_
TEXT_ LINE_ CONTENT - The longest text line this server writes, before dot-stuffing and CRLF.
- MIME_
HEADER - The header a MIME-mode text block is prefaced with (RFC 2229 §3.10.1, OPTION MIME).
- TEXT_
CODES - The three informational text responses
send_dict_textrenders, with their status text. - TEXT_
FOLLOWS_ CODES - Status codes whose response is followed by a dot-terminated text block.
Functions§
- apply_
mime - Insert
MIME_HEADERafter every status line that opens a text block. - atom
- Render a database or strategy name: bare when it is a plain atom (which every real name
is —
wn,gcide,prefix), quoted otherwise so a name with a space in it cannot split one listing line into two columns. - leading_
code - The numeric code a rendered response begins with.
- quoted
- Render a string as a DICT double-quoted string: control characters become spaces (a CR or
LF would end the status line and forge the next one), and
\and"are escaped. - render_
databases - render_
definitions 150+ one151block per definition +250, or552 no matchwhen there are none.- render_
error - A single 5xx status line.
Nonefor a code outsideERROR_CODES. - render_
listing - A
name "description"listing (110databases or111strategies) +250, or the listing’s own empty-set code (554/555). - render_
matches 152+ onedatabase "word"line per match +250, or552 no match.- render_
strategies - render_
text 112/113/114+ a text block +250.Nonefor any other code.- split_
args - Split a command line into parameters per RFC 2229 §2.2.
- stuff
- Dot-stuff one text line (RFC 2229 §2.4.1): a line that begins with
.gets a second one, so the only line that reads as.alone is the terminator this module writes. - text_
block - A status line followed by a dot-terminated text block.
- text_
lines - The lines of a model-supplied text body, ready for a text block: line endings normalised,
control characters other than tab removed, long lines wrapped, trailing blank lines
dropped. Not yet dot-stuffed —
text_blockdoes that, once, for every line it writes.