def set_authorizer(self, callback): try: authorizer = self.__func_cache[callback] except KeyError: @_ffi.callback("int(void*, int, const char*, const char*, " "const char*, const char*)") def authorizer(userdata, action, arg1, arg2, dbname, source): try: ret = callback(action, arg1, arg2, dbname, source) assert isinstance(ret, int) # try to detect cases in which cffi would swallow # OverflowError when casting the return value assert int(_ffi.cast('int', ret)) == ret return ret except Exception: return _lib.SQLITE_DENY self.__func_cache[callback] = authorizer ret = _lib.sqlite3_set_authorizer(self._db, authorizer, _ffi.NULL) if ret != _lib.SQLITE_OK: raise self._get_exception(ret)