Exemple #1
0
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)
Exemple #2
0
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
Exemple #3
0
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
Exemple #4
0
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)
Exemple #5
0
def decode_dict(d):
    topic = d["__dict__"]["topic"]
    state = d["__dict__"]["state"]
    dict_type = resolve_topic(topic)
    return dict_type(state)
Exemple #6
0
def decode_enum(d):
    topic = d["__enum__"]["topic"]
    name = d["__enum__"]["name"]
    enum = resolve_topic(topic)
    return getattr(enum, name)
Exemple #7
0
def decode_type(d):
    return resolve_topic(d["__type__"])