livery.strongroom._fields¶
livery.strongroom._fields ¶
Decoding helpers shared by the structured formats.
Each format decodes from a JSON value with the same discipline: the
value is an object, it has exactly the keys the format names, and each
field has the type the format says. A refusal names the format, the
field and the rule. The formats themselves are _tree, _version and
_records; this module is the part they share.
Classes:
| Name | Description |
|---|---|
Subject |
A subject slot: a person, a call key, a receipt digest, or code. |
Functions:
| Name | Description |
|---|---|
expect_object |
Return value as an object with exactly keys, or refuse. |
expect_str |
Return value as a string, or refuse. |
expect_int |
Return value as a non-negative integer, or refuse. |
expect_bool |
Return value as a boolean, or refuse. |
expect_list |
Return value as a list, or refuse. |
expect_digest |
Return value parsed as a digest string, or refuse. |
expect_optional_digest |
Return value as a digest or None, or refuse. |
check_timestamp |
Return value when it is an RFC 3339 UTC instant, or refuse. |
nfc |
Return value when it is already in Unicode NFC, or refuse. |
Attributes:
| Name | Type | Description |
|---|---|---|
SubjectKind |
Who or what may fill a subject slot. |
|
SUBJECT_KINDS |
tuple[SubjectKind, ...]
|
|
SubjectKind
module-attribute
¶
SubjectKind = Literal['person', 'call', 'receipt', 'code']
Who or what may fill a subject slot.
SUBJECT_KINDS
module-attribute
¶
SUBJECT_KINDS: tuple[SubjectKind, ...] = ('person', 'call', 'receipt', 'code')
Subject
dataclass
¶
Subject(kind: SubjectKind, value: str)
A subject slot: a person, a call key, a receipt digest, or code.
A version's producer, a ref record's writer and a tombstone's authority are subjects. The slot is shaped so that attested code fits it from the first persisted byte.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
SubjectKind
|
which of the four the subject is. |
value |
str
|
the subject's identity, its spelling owned by the kind: a person's identifier, a call key, a receipt or code digest as a digest string. |
Methods:
| Name | Description |
|---|---|
to_json |
The subject as a JSON object. |
from_json |
Decode a subject, refusing an unknown kind or an empty value. |
to_json ¶
from_json
classmethod
¶
Decode a subject, refusing an unknown kind or an empty value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Value
|
the JSON value to decode. |
required |
where
|
str
|
the field being decoded, for the refusal's message. |
required |
Returns:
| Type | Description |
|---|---|
Subject
|
The subject. |
Raises:
| Type | Description |
|---|---|
FormatError
|
when the shape or the kind is wrong. |
Source code in packages/strongroom/src/livery/strongroom/_fields.py
expect_object ¶
Return value as an object with exactly keys, or refuse.
Source code in packages/strongroom/src/livery/strongroom/_fields.py
expect_str ¶
Return value as a string, or refuse.
expect_int ¶
Return value as a non-negative integer, or refuse.
A boolean is refused although Python counts it as an integer, and a float is refused although it may be whole: the formats carry integers only.
Source code in packages/strongroom/src/livery/strongroom/_fields.py
expect_bool ¶
Return value as a boolean, or refuse.
expect_list ¶
Return value as a list, or refuse.
expect_digest ¶
expect_optional_digest ¶
Return value as a digest or None, or refuse.
check_timestamp ¶
Return value when it is an RFC 3339 UTC instant, or refuse.
The form is YYYY-MM-DDTHH:MM:SS[.fraction]Z: seconds required,
up to nine fractional digits, the Z designator and no offset, so
one instant has one spelling.
Source code in packages/strongroom/src/livery/strongroom/_fields.py
nfc ¶
Return value when it is already in Unicode NFC, or refuse.