List querying - libtmux._internal.query_list#

Utilities for filtering or searching list of objects / list data.


This is an internal API not covered by versioning policy.

exception libtmux._internal.query_list.MultipleObjectsReturned[source]#

The requested object does not exist

exception libtmux._internal.query_list.ObjectDoesNotExist[source]#

The query returned multiple objects when only one was expected.

libtmux._internal.query_list.keygetter(obj, path)[source]#

obj, “foods__breakfast”, obj[‘foods’][‘breakfast’]

>>> keygetter({ "foods": { "breakfast": "cereal" } }, "foods__breakfast")
:rtype: :py:data:`~typing.Union`\[:py:obj:`None`, :py:data:`~typing.Any`, :py:class:`str`, :py:class:`~typing.List`\[:py:class:`str`], :py:class:``\[:py:class:`str`, :py:class:`str`]]
>>> keygetter({ "foods": { "breakfast": "cereal" } }, "foods")
{'breakfast': 'cereal'}
libtmux._internal.query_list.parse_lookup(obj, path, lookup)[source]#

Check if field lookup key, e.g. “my__path__contains” has comparator, return val.

If comparator not used or value not found, return None.

mykey__endswith(“mykey”) -> “mykey” else None

Return type:


>>> parse_lookup({ "food": "red apple" }, "food__istartswith", "__istartswith")
'red apple'
class libtmux._internal.query_list.QueryList(iterable=(), /)[source]#

Filter list of object/dictionaries. For small, local datasets.

Experimental, unstable.

>>> query = QueryList(
...     [
...         {
...             "place": "Largo",
...             "city": "Tampa",
...             "state": "Florida",
...             "foods": {"fruit": ["banana", "orange"], "breakfast": "cereal"},
...         },
...         {
...             "place": "Chicago suburbs",
...             "city": "Elmhurst",
...             "state": "Illinois",
...             "foods": {"fruit": ["apple", "cantelope"], "breakfast": "waffles"},
...         },
...     ]
... )
>>> query.filter(place="Chicago suburbs")[0]['city']
>>> query.filter(place__icontains="chicago")[0]['city']
>>> query.filter(foods__breakfast="waffles")[0]['city']
>>> query.filter(foods__fruit__in="cantelope")[0]['city']
>>> query.filter(foods__fruit__in="orange")[0]['city']
>>> query.get(foods__fruit__in="orange")['city']
filter(matcher=None, **kwargs)[source]#

Filter list of objects.

Return type:

QueryList[TypeVar(T, Any, Any)]

get(matcher=None, default=<object object>, **kwargs)[source]#

Retrieve one object.

Raises MultipleObjectsReturned if multiple objects found.

Raises ObjectDoesNotExist if no object found, unless default stated.

Return type:

Optional[TypeVar(T, Any, Any)]