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: object

How a manifest file writes its manifest.

minimal#

Whether the manifest is in the minimal form rather than the complete form.

Type:

bool

styling#

Whether the manifest’s graphical object is written.

Type:

bool

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 graphical is left out unless form.styling; the rest is written in the minimal form if form.minimal, else in the complete form, in form.serialization. value is 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’s scalar: 1.0 is the default 1) 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-level graphical key; the serialization is the one serialization_of() names. A text whose value states some defaults and leaves out others is not minimal. The value is not validated.

Raises: