def decode_frozenset(d): set_data = d["__frozenset__"] if isinstance(set_data, dict): topic = set_data["topic"] state = set_data["state"] set_type = resolve_topic(topic) return set_type(state) else: return frozenset(set_data)
def decode_object(d): topic = d["__class__"]["topic"] state = d["__class__"]["state"] obj_class = resolve_topic(topic) obj = object.__new__(obj_class) if hasattr(obj, "__dict__"): obj.__dict__.update(state) else: for k, v in state.items(): object.__setattr__(obj, k, v) return obj
def decode_tuple(d): tuple_data = d["__tuple__"] if type(tuple_data) == dict: # For NamedTuple objects. topic = tuple_data["topic"] state = tuple_data["state"] tuple_type = resolve_topic(topic) obj = tuple_type(*state) else: # For standard tuple objects. obj = tuple(tuple_data) return obj
def decode_deque(d): deque_data = d["__deque__"] if type(deque_data) == dict: topic = deque_data["topic"] try: state = deque_data["state"] except KeyError: state = deque_data["values"] deque_type = resolve_topic(topic) return deque_type(state) else: return deque(deque_data)
def decode_dict(d): topic = d["__dict__"]["topic"] state = d["__dict__"]["state"] dict_type = resolve_topic(topic) return dict_type(state)
def decode_enum(d): topic = d["__enum__"]["topic"] name = d["__enum__"]["name"] enum = resolve_topic(topic) return getattr(enum, name)
def decode_type(d): return resolve_topic(d["__type__"])