ws.utils.containers module

class ws.utils.containers.ListOfDictsAttrWrapper(dict_list, attr)

Bases: object

A list-like wrapper around list of dicts, operating on a given attribute.

ws.utils.containers.bisect_find(data_list, key, index_list=None)

Find an element in a sorted list using the bisect method.

Parameters
  • data_list – list of elements to be returned from

  • key – element to be found in index_list

  • index_list – an optional list of indexes where key is searched for, by default data_list is taken. Has to be sorted.

Returns

data_list[i] if index_list[i] == key

Raises

IndexError – when key is not found

ws.utils.containers.bisect_insert_or_replace(data_list, key, data_element=None, index_list=None)

Insert an element into a sorted list using the bisect method. If an element is found in the list, it is replaced.

Parameters
  • data_list – list of elements to be inserted into

  • data_element – an element to be inserted. By default key is taken.

  • key – a key used for searching

  • index_list – an optional list of indexes where key is searched for, by default data_list is taken. Has to be sorted.

ws.utils.containers.dmerge(source, destination)

Deep merging of dictionaries.

ws.utils.containers.find_caseless(what, where, from_target=False)

Do a case-insensitive search in a list/iterable.

Parameters
  • what – element to be found

  • where – a list/iterable for searching

  • from_target – if True, return the element from the list/iterable instead of what

Raises

ValueError – when not found

ws.utils.containers.gen_nested_values(indict, keys=None)

Generator yielding all values stored in a nested structure of dicts, lists and tuples.

ws.utils.containers.parse_timestamps_in_struct(struct)

Convert all timestamps in a nested structure from str to datetime.datetime.

ws.utils.containers.serialize_timestamps_in_struct(struct)

Convert all timestamps in a nested structure from str to datetime.datetime.