def __recursive_object_hook__(o): def __regular_t2a__(p): return dict([(int(key), dict([(TimeSlot.__from_string__(timeslot), [Activity.__from_string__(activity) for activity in activities]) for timeslot, activities in timeslot2activites.iteritems()])) for key, timeslot2activites in p.iteritems()]) if isinstance(o, list): return [__recursive_object_hook__(value) for value in o] elif "__nephrologist__" in o: nephrologist = o["__nephrologist__"] id = int(nephrologist["id"]) if "id" in nephrologist else None name = str(nephrologist["name"].encode("latin-1")) if "name" in nephrologist else None activities = [Activity.__from_string__(flag) for flag in nephrologist["activities"] if "activities" in nephrologist] holidays = [__recursive_object_hook__(value) for value in nephrologist["holidays"] if "holidays" in nephrologist] preferences = __recursive_object_hook__(nephrologist["preferences"]) if "preferences" in nephrologist else None aversions = __recursive_object_hook__(nephrologist["aversions"]) if "aversions" in nephrologist else None counters = __recursive_object_hook__(nephrologist["initial_counters"]) if "initial_counters" in nephrologist else None return Nephrologist(id, name, activities, holidays, preferences, aversions, counters) elif "__date__" in o: return datetime.strptime(o["__date__"], "%Y-%m-%d").date() elif "__preferences__" in o: return Preferences(__regular_t2a__(o["__preferences__"])) elif "__aversions__" in o: return Aversions(__regular_t2a__(o["__aversions__"])) elif "__counter__" in o: return Counter(dict([(Activity.__from_string__(key), value) for key, value in o["__counter__"].iteritems()])) else: return o
def __regular_t2a__(p): return dict([(int(key), dict([(TimeSlot.__from_string__(timeslot), [Activity.__from_string__(activity) for activity in activities]) for timeslot, activities in timeslot2activites.iteritems()])) for key, timeslot2activites in p.iteritems()])