s3dol.values¶
Value refs and the write domain (ADR-0005).
The write domain is a small, closed, explicitly-named union:
BytesSource = bytes | bytearray | memoryview | BinaryIO | Filepath | Chunks | Streamable
Filepath/Chunks/Streamable are tiny frozen dataclasses — value
refs, not values (h5py’s SoftLink/ExternalLink are the precedent:
purpose-built objects meaning “the value is a reference to content elsewhere”,
assigned through an ordinary __setitem__).
The law that makes the asymmetric read/write types safe (ADR-0005 §3):
N1 (canonical form):
normalize: WriteDomain -> bytesis total onbytes | bytearray | memoryview | Filepathand one-shot onBinaryIO | Chunks | Streamable— a stream ref is consumed by its first write; assigning the same ref twice is a documented error, not a second copy.N3 (the honest invariant):
s[k] = v => s[k] == normalize(v)— for the re-readable half.
str is rejected, loudly, on decidability (§2): s['config'] = '{"a":1}'
and s['video'] = '/tmp/big.mp4' are both overwhelmingly plausible, and any
rule distinguishing them is a latent data-corruption bug. One word —
Filepath(p) — removes the ambiguity. Bare os.PathLike is rejected too:
accepting it while rejecting str would be a confusing half-rule.
>>> reject_str_value('{"a": 1}')
Traceback (most recent call last):
...
TypeError: ...
Module Attributes
The static write domain ( |
Functions
A binary file object for any member of the write domain. |
|
Whether |
|
The one error message for the |
Classes
|
The value is the concatenation of an iterable of |
|
The value is the content of this file. |
|
The value is whatever a zero-arg factory's stream yields — for sources that must be (re)opened at write time, e.g. an HTTP download. |
- s3dol.values.BytesSource¶
The static write domain (
BinaryIOis for mypy; runtime dispatch usesio.IOBase— seeas_fileobj()).alias of
bytes|bytearray|memoryview|BinaryIO|Filepath|Chunks|Streamable
- class s3dol.values.Chunks(chunks, consumed=list())[source]¶
Bases:
objectThe value is the concatenation of an iterable of
byteschunks. One-shot unless the iterable is re-iterable (a list is; a generator is not — and a consumed generator writesb'', which is why assigning the same one-shot ref twice is a documented error).
- class s3dol.values.Filepath(path)[source]¶
Bases:
objectThe value is the content of this file. Re-readable (N1-total).
- class s3dol.values.Streamable(open_stream)[source]¶
Bases:
objectThe value is whatever a zero-arg factory’s stream yields — for sources that must be (re)opened at write time, e.g. an HTTP download. The factory is called once per write, so unlike
Chunksthis ref IS safely re-writable (each write gets a fresh stream).
- s3dol.values.as_fileobj(v)[source]¶
- s3dol.values.as_fileobj(v)
- s3dol.values.as_fileobj(v)
- s3dol.values.as_fileobj(v)
- s3dol.values.as_fileobj(v)
- s3dol.values.as_fileobj(v)
- s3dol.values.as_fileobj(v)
- s3dol.values.as_fileobj(v)
A binary file object for any member of the write domain.
functools.singledispatch: the union is open for extension (users register their own ref types) and closed for modification. Everything non-bytesroutes throughupload_fileobjdownstream, so seekability is s3transfer’s problem.- Return type: