import uuid from weakref import WeakValueDictionary from collections import defaultdict class StringWrapper: def __init__(self, s): self.s = s class OrderedMultiIndexMapWeakRef: def __init__(self): self.data = [] self.ids = [] self.index_list = [] def insert(self, id, text, title: str, sub_title: str): self.data.append(text) self.ids.append(int(uuid.UUID(id))) self.index_list.append(WeakValueDictionary({'title': StringWrapper(title), 'sub_title': StringWrapper(sub_title)})) def all_ids(self): return self.ids def all_metadatas(self): return [dict(d) for d in self.index_list] def all_texts(self): return self.data