annals.prefs#

Each reader’s page preferences: a few named sections of JSON, kept on the server.

The page’s settings (the order of a document’s actions, first) follow the reader from the phone to the tablet to the desktop, and from Safari to the home-screen app, which on an iPhone keep separate browser storage. So they live here, one JSON file per reader beside the listening records (<root>/prefs/<reader>.json), and the page keeps a copy in the browser only to draw its first screen.

The page owns what a section means: its schema, defaults and the merge of a saved value with a newer default are in app.js (SETTINGS). The server keeps each section as the reader left it, refusing only what no section could be: a name that is not a short slug, a value that is not a JSON object, a section over MAX_SECTION_BYTES, or more than MAX_SECTIONS sections. That keeps a new setting a page-only change.

>>> clean_section("bar", {"order": ["links", "listen"]})
{'order': ['links', 'listen']}
>>> clean_section("Bar!", {})
Traceback (most recent call last):
...
ValueError: a section name is a lower-case slug of at most 32 characters

Functions

clean_section(name, value)

value as kept under name, or ValueError saying why it cannot be.

for_reader(root)

The default seam: each reader's preferences in <root>/prefs/<reader>.json.

put_section(records, name, value)

Keep value as the reader's name section; the sections as they now stand.

Classes

PrefsStore(path)

One reader's preferences: {section: object} in one JSON file.

class annals.prefs.PrefsStore(path)[source]#

Bases: JsonFileStore

One reader’s preferences: {section: object} in one JSON file.

valid(value)[source]#

Whether a value read from the file is kept (an invalid one is logged and skipped).

Return type:

bool

annals.prefs.clean_section(name, value)[source]#

value as kept under name, or ValueError saying why it cannot be.

Return type:

dict

annals.prefs.for_reader(root)[source]#

The default seam: each reader’s preferences in <root>/prefs/<reader>.json.

Return type:

Callable[[str], Records]

annals.prefs.put_section(records, name, value)[source]#

Keep value as the reader’s name section; the sections as they now stand.

Return type:

dict