def config(fmt: str = "html") -> Union[Response, RespTuple]: if fmt == "json": if http_request.method == "GET": return ( json.dumps(state.get_raw_configs()), 200, { "Content-Type": "application/json" }, ) else: assert http_request.method == "POST" state.set_configs( json.loads(http_request.data), user=http_request.headers.get("x-forwarded-email"), ) return ( json.dumps(state.get_raw_configs()), 200, { "Content-Type": "application/json" }, ) else: return application.send_static_file("config.html")
def disable_query_cache() -> Generator[None, None, None]: cache, readthrough = state.get_configs( [("use_cache", settings.USE_RESULT_CACHE), ("use_readthrough_query_cache", 1)] ) state.set_configs({"use_cache": 0, "use_readthrough_query_cache": 0}) yield state.set_configs({"use_cache": cache, "use_readthrough_query_cache": readthrough})
def set_many(*, data: str, force_type: bool) -> None: "Set multiple keys, input as JSON." try: state.set_configs(json.loads(data), user=get_user(), force=force_type) except MismatchedTypeException as exc: print( f"Mismatched types for {exc.key}: Original type: {exc.original_type}, New type: {exc.new_type}. Use the force option to disable this check" )
def config(fmt='html'): if fmt == 'json': if request.method == 'GET': return (json.dumps(state.get_raw_configs()), 200, {'Content-Type': 'application/json'}) elif request.method == 'POST': state.set_configs(json.loads(request.data), user=request.headers.get('x-forwarded-email')) return (json.dumps(state.get_raw_configs()), 200, {'Content-Type': 'application/json'}) else: return application.send_static_file('config.html')
def test_config(self): state.set_config("foo", 1) state.set_configs({"bar": 2, "baz": 3}) assert state.get_config("foo") == 1 assert state.get_config("bar") == 2 assert state.get_config("noexist", 4) == 4 all_configs = state.get_all_configs() assert all(all_configs[k] == v for k, v in [("foo", 1), ("bar", 2), ("baz", 3)]) assert state.get_configs([("foo", 100), ("bar", 200), ("noexist", 300), ("noexist-2", None)]) == [1, 2, 300, None] state.set_configs({"bar": "quux"}) all_configs = state.get_all_configs() assert all(all_configs[k] == v for k, v in [("foo", 1), ("bar", "quux"), ("baz", 3)])
def test_config(self): state.set_config('foo', 1) state.set_configs({'bar': 2, 'baz': 3}) assert state.get_config('foo') == 1 assert state.get_config('bar') == 2 assert state.get_config('noexist', 4) == 4 all_configs = state.get_all_configs() assert all(all_configs[k] == v for k, v in [('foo', 1), ('bar', 2), ('baz', 3)]) assert state.get_configs([('foo', 100), ('bar', 200), ('noexist', 300), ('noexist-2', None)]) == [1, 2, 300, None] state.set_configs({'bar': 'quux'}) all_configs = state.get_all_configs() assert all(all_configs[k] == v for k, v in [('foo', 1), ('bar', 'quux'), ('baz', 3)])
def config(fmt: str = "html") -> Union[Response, RespTuple]: if fmt == "json": if http_request.method == "GET": return ( json.dumps(state.get_raw_configs()), 200, {"Content-Type": "application/json"}, ) else: assert http_request.method == "POST" try: state.set_configs( json.loads(http_request.data), user=http_request.headers.get("x-forwarded-email"), ) return ( json.dumps(state.get_raw_configs()), 200, {"Content-Type": "application/json"}, ) except MismatchedTypeException as exc: return ( json.dumps( { "error": { "type": "client_error", "message": "Existing value and New value have different types. Use option force to override check", "key": str(exc.key), "original value type": str(exc.original_type), "new_value_type": str(exc.new_type), } }, indent=4, ), 400, {"Content-Type": "application/json"}, ) else: return application.send_static_file("config.html")
def set_many(*, data: str) -> None: "Set multiple keys, input as JSON." state.set_configs(json.loads(data), user=get_user())