hertzforge.io.sniffing¶
sniffing
¶
The checks every sniffer makes before it reads anything.
A sniffer answers "is this file one this importer reads?" and must never raise while answering: a file it cannot read is not its file, whatever the reason. The open and the exception handling for that are here, once, for every importer.
Functions:
| Name | Description |
|---|---|
text_head |
The first |
npz_has |
True when |
npz_summary |
A one-line description of what an |
npy_summary |
Why a |
describe |
What a file is, for an error message: |
Functions:¶
text_head
¶
The first size characters of a text file, or None when the file
cannot be read.
Undecodable bytes are replaced rather than raised, because a sniff judges the shape of the text, and one undecodable byte must not reject a file the loader would read.
npz_has
¶
True when path is an .npz holding every one of keys; False
for any other file, or one that cannot be read.
Only the archive's list of names is read. A sniff never unpickles: it runs on any file that is dropped or listed, before anyone has asked for it to be read.
npz_summary
¶
A one-line description of what an .npz holds (the number of
arrays and the first eight names), for an error that would otherwise
say only that no importer recognized it. None when the file is not
an .npz.
npy_summary
¶
Why a .npy is not read, when that is something other than being
the wrong array: it holds objects, or is not a NumPy file at all. None
for anything else.
describe
¶
What a file is, for an error message: npz_summary for an .npz,
npy_summary for a .npy, None for anything else.
An .npz is a container whose contents decide which reader takes it,
and an error that names only the path cannot tell the wrong file
from an unsupported one.