def __init__(self):
        self._revivers = _revivers = {}
    
        def loads(text):
            return JSON.parse(text, _reviver)
        
        def saves(obj):
            return JSON.stringify(obj, _replacer)
        
        def add_reviver(type_name, func):
            assert isinstance(type_name, str)
            _revivers[type_name] = func
        
        def _reviver(dct, val=undefined):
            if val is not undefined:  # pragma: no cover
                dct = val
            if isinstance(dct, dict):
                type = dct.get('__type__', None)
                if type is not None:
                    func = _revivers.get(type, None)
                    if func is not None:
                        return func(dct)
            return dct
        
        def _replacer(obj, val=undefined):
            if val is undefined:  # Py
                
                try:
                    return obj.__json__()  # same as in Pyramid
                except __HOLE__:
                    raise TypeError('Cannot serialize object to JSON: %r' % obj)
            else:  # JS - pragma: no cover
                if (val is not None) and val.__json__:
                    return val.__json__()
                return val
        
        self.loads = loads
        self.saves = saves
        self.add_reviver = add_reviver
dataset/ETHPy150Open zoofIO/flexx/flexx/app/serialize.py/Serializer.__init__