annals.originals#
Originals: a pick’s files, exactly as published, as one streamed .zip.
One file (annals.combine) cannot hold audio or video, so a pick of originals has its
own form: one folder per document, named after its title, holding the document’s files with
their published names. The zip is streamed (members are stored, since audio, video, PDFs
and images are already compressed), so the server never holds it whole; the size is known
before it starts (plan()), and a pick over the cap is refused with the cap in the
message (TooBig), never started and abandoned half way.
>>> import io, zipfile
>>> from pathlib import Path
>>> import tempfile
>>> d = Path(tempfile.mkdtemp()); (d / "a.txt").write_text("hi")
2
>>> docs = [{"id": "x", "title": "My / doc", "files": ["a.txt"]}]
>>> p = plan(docs, path_of=lambda i, rel: d / rel)
>>> [e.arcname for e in p.entries], p.bytes
(['My doc/a.txt'], 2)
>>> zipfile.ZipFile(io.BytesIO(b"".join(stream(p)))).read("My doc/a.txt")
b'hi'
Functions
|
A title as a folder name: no separators or control characters, no leading dots, bounded. |
|
The files of |
|
Bytes as the page says them. |
|
The zip of |
Classes
|
One file: where it is, its name in the zip, its size and modification time. |
|
What a zip will hold: the entries, their total size, and the documents they came from. |
Exceptions
The pick is over a cap; the message names the cap. |
- class annals.originals.Entry(path, arcname, size, mtime)[source]#
Bases:
objectOne file: where it is, its name in the zip, its size and modification time.
- class annals.originals.Plan(entries, bytes, docs)[source]#
Bases:
objectWhat a zip will hold: the entries, their total size, and the documents they came from.
- exception annals.originals.TooBig[source]#
Bases:
ValueErrorThe pick is over a cap; the message names the cap.
- annals.originals.folder_name(title, fallback)[source]#
A title as a folder name: no separators or control characters, no leading dots, bounded.
>>> folder_name("Q3: plans / draft", "id1") 'Q3 plans draft' >>> folder_name(" .. ", "id1") 'id1' >>> folder_name("con", "id1") 'con_'
- Return type:
- annals.originals.plan(docs, *, path_of, max_bytes=None, max_docs=None)[source]#
The files of
docs(metas withid,title,files) and their total size.path_of(doc_id, rel)finds a file on disk (and refuses one that is not the document’s). Two documents with one title gettitle,title (2)… A file that is gone from disk is skipped. Overmax_docsdocuments ormax_bytesbytes:TooBig.- Return type: