timetoshare.files#
Manifest files: the form a file writes its manifest in, and writing it back.
A manifest file is the text of one manifest in one serialization, in the
minimal or the complete form, with or without its graphical object.
file_form() reads that FileForm off a text, and
dumps_file() writes a manifest in a given one, so that an editor or a
library writes a file back as it came: dumps_file(loads(text),
file_form(text)) gives text for every text a writer of this package
wrote. The JavaScript package’s fileForm and dumpsFile give the same
form and the same bytes.
- class timetoshare.files.FileForm(minimal, styling, serialization)[source]#
Bases:
objectHow a manifest file writes its manifest.
- serialization#
"yaml"(canonical YAML),"json"(pretty JSON) or"jcs"(RFC 8785 JSON).- Type:
Literal[‘yaml’, ‘json’, ‘jcs’]
- timetoshare.files.dumps_file(value, form)[source]#
Return the text of a manifest as a file of the given form writes it.
A top-level
graphicalis left out unlessform.styling; the rest is written in the minimal form ifform.minimal, else in the complete form, inform.serialization.valueis not changed.- Raises:
ValueError – If the serialization refuses the value or names no serialization (as
dumps()raises).TypeError – If the value is not JSON.
- timetoshare.files.file_form(text)[source]#
Read the form of a manifest file off its text.
The manifest is minimal when its minimal form writes the same canonical YAML as the value the text holds: a key stated at its default makes a text not minimal, and the order canonical order sorts does not count. Defaults are recognized by exact value (a
LinearMap’sscalar: 1.0is the default1) and own-axis values respelled by the declared number type on both sides, so an RFC 8785 JSON text, which writes an integral float as an integer, reads as the form it was written in. It holds its styling when it has a top-levelgraphicalkey; the serialization is the oneserialization_of()names. A text whose value states some defaults and leaves out others is not minimal. The value is not validated.- Raises:
ValueError – If
loads()refuses the text, or canonical YAML cannot write its value.TypeError – If
textis not astr.