keyvalue.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. """
  3. Typification of the *keyvalue* results. Results of this type are rendered in
  4. the :origin:`keyvalue.html <searx/templates/simple/result_templates/keyvalue.html>`
  5. template.
  6. ----
  7. .. autoclass:: KeyValue
  8. :members:
  9. :show-inheritance:
  10. """
  11. # pylint: disable=too-few-public-methods
  12. from __future__ import annotations
  13. __all__ = ["KeyValue"]
  14. import typing
  15. from collections import OrderedDict
  16. from ._base import MainResult
  17. class KeyValue(MainResult, kw_only=True):
  18. """Simple table view which maps *key* names (first col) to *values*
  19. (second col)."""
  20. template: str = "keyvalue.html"
  21. kvmap: dict[str, typing.Any] | OrderedDict[str, typing.Any]
  22. """Dictionary with keys and values. To sort keys, use :py:obj:`OrderedDict`."""
  23. caption: str = ""
  24. """Optional caption for this result."""
  25. key_title: str = ""
  26. """Optional title for the *key column*."""
  27. value_title: str = ""
  28. """Optional title for the *value column*."""
  29. def __hash__(self) -> int:
  30. """The KeyValues objects are checked for object identity, even if all
  31. fields of two results have the same values, they are different from each
  32. other.
  33. """
  34. return id(self)