Coverage for python/lsst/images/serialization/_external_metadata.py: 26%
19 statements
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-30 04:21 -0700
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-30 04:21 -0700
1# This file is part of lsst-images.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# Use of this source code is governed by a 3-clause BSD-style
10# license that can be found in the LICENSE file.
12from __future__ import annotations
14__all__ = ("EmptyExternalMetadata", "ExternalMetadata", "ExternalMetadataValue")
16from abc import abstractmethod
17from collections.abc import Iterator, Mapping
19type ExternalMetadataValue = bool | int | float | complex | str | None
22class ExternalMetadata(Mapping[str, ExternalMetadataValue]):
23 """Read-only access to metadata that was carried in from an external
24 source, such as the primary header of a FITS file, and is not part of
25 the data model.
27 Notes
28 -----
29 Lookups and membership tests are case-insensitive. Iteration yields
30 each key once, in the form the underlying source reports it. When a key
31 is repeated in the source, which of its values ``[]`` returns is
32 unspecified; use `get_all` to obtain every value.
33 """
35 @abstractmethod
36 def get_all(self, key: str) -> tuple[ExternalMetadataValue, ...]:
37 """Return every value for a key, in source order.
39 Parameters
40 ----------
41 key
42 Key to look up (case-insensitive).
44 Returns
45 -------
46 values : `tuple`
47 All values for ``key``.
49 Raises
50 ------
51 KeyError
52 Raised if ``key`` is not present.
53 """
54 raise NotImplementedError()
56 def __repr__(self) -> str:
57 return f"{type(self).__name__}({dict(self)!r})"
60class EmptyExternalMetadata(ExternalMetadata):
61 """An `ExternalMetadata` with no keys."""
63 def __getitem__(self, key: str) -> ExternalMetadataValue:
64 raise KeyError(key)
66 def __iter__(self) -> Iterator[str]:
67 return iter(())
69 def __len__(self) -> int:
70 return 0
72 def get_all(self, key: str) -> tuple[ExternalMetadataValue, ...]:
73 # Docstring inherited.
74 raise KeyError(key)