calamari.io.base.LoaderRegistry#

class calamari.io.base.LoaderRegistry#

Bases: object

Central registry of available content-sniffing loaders.

classmethod register(loader)#

Register loader; usable directly or as a class decorator.

Returns the loader unchanged so it can be applied as @LoaderRegistry.register above a loader class definition. Registration is idempotent (registering the same class twice is a no-op), which keeps re-imports from duplicating entries.

Return type:

type[BaseLoader]

classmethod detect_lines(lines)#

Return the loader whose BaseLoader.sniff() claims lines.

The pure matching half of detect(), split out so a caller that has already read the signature region (or that needs read errors to propagate rather than be swallowed – see read_signature_lines()) does not have to read the file twice or re-implement the dispatch order.

Loaders are offered the lines in registration order and the first match wins; None means no registered loader recognises the content.

Return type:

type[BaseLoader] | None

classmethod detect(path)#

Return the loader that claims path, or None.

Reads the first _SIGNATURE_SCAN_LINES lines once and offers them to detect_lines(). Unreadable files (permission/encoding errors) yield None rather than raising, so this doubles as a safe “is this a supported file?” probe over a directory of mixed content – which is precisely why calamari.io.load() does not use it: a caller loading one named file needs “could not read” and “not a magnetometry file” to be different outcomes.

Return type:

type[BaseLoader] | None

classmethod loaders()#

Return the registered loaders in registration order (a copy).

Return type:

list[type[BaseLoader]]

classmethod by_name(format_name)#

Return the registered loader whose format_name matches (case-insensitively), or None. Used to honour an explicit fmt= override that bypasses sniffing.

Return type:

type[BaseLoader] | None