def pyserver_core_keyvalue_handlers_get_data_for(key=None): """ For a given key return the data stored, if any. :statuscode 200: data found, and returned :statuscode 404: no stored data found for provided key """ return404 = request.values.get("return404", None) content_type, value, file_path = read_it(key) callback = request.values.get("callback", None) if not value: if callback: # this is specifically to handle the (most common) use case of JSONP blowing # chunks if the response is a 404 as the borwser will not do anything further # causing the callback in your javascript library to never fire response = json_response(**dict(message="no data for key")) elif return404 and return404 == "false": response = json_response(**dict(message="no data for key")) else: response = json_response(**dict(message="no data for key", status_code=404)) else: if callback: response = ("%s(%s);" % (callback, value), 200, {"Content-Type": "application/javascript"}) else: response = (value, 200, {"Content-Type": content_type}) response[2]["X-File-Path"] = file_path return response
def pyserver_core_keyvalue_handlers_get_data_for(key=None): """ For a given key return the data stored, if any. :statuscode 200: data found, and returned :statuscode 404: no stored data found for provided key """ return404 = request.values.get("return404", None) content_type, value, file_path = read_it(key) callback = request.values.get("callback", None) if not value: if callback: # this is specifically to handle the (most common) use case of JSONP blowing # chunks if the response is a 404 as the borwser will not do anything further # causing the callback in your javascript library to never fire response = json_response(**dict(message="no data for key")) elif return404 and return404 == "false": response = json_response(**dict(message="no data for key")) else: response = json_response( **dict(message="no data for key", status_code=404)) else: if callback: response = ("%s(%s);" % (callback, value), 200, { "Content-Type": "application/javascript" }) else: response = (value, 200, {"Content-Type": content_type}) response[2]['X-File-Path'] = file_path return response
def pyserver_core_keyvalue_handlers_get_data_for_multi(keys=None): """ For a given set of keys return the data stored, if any. :statuscode 200: data found, and returned :statuscode 404: no stored data found for provided keys """ keys = keys.split('/') values = {} first_content_type = None for key in keys: content_type, value, file_path = read_it(key) if value: if content_type == 'application/json': value = json.loads(value) first_content_type = content_type values[key] = value if first_content_type and first_content_type == 'application/json': values = json.dumps(values) return404 = request.values.get("return404", None) callback = request.values.get("callback", None) if not values: if callback: # this is specifically to handle the (most common) use case of JSONP blowing # chunks if the response is a 404 as the borwser will not do anything further # causing the callback in your javascript library to never fire response = json_response(**dict(message="no data for key")) elif return404 and return404 == "false": response = json_response(**dict(message="no data for key")) else: response = json_response( **dict(message="no data for key", status_code=404)) else: if callback: response = "%s(%s);" % (callback, values), 200, { "Content-Type": "application/javascript" } else: response = values, 200, {"Content-Type": first_content_type} return response
def pyserver_core_keyvalue_handlers_get_data_for_multi(keys=None): """ For a given set of keys return the data stored, if any. :statuscode 200: data found, and returned :statuscode 404: no stored data found for provided keys """ keys = keys.split("/") values = {} first_content_type = None for key in keys: content_type, value, file_path = read_it(key) if value: if content_type == "application/json": value = json.loads(value) first_content_type = content_type values[key] = value if first_content_type and first_content_type == "application/json": values = json.dumps(values) return404 = request.values.get("return404", None) callback = request.values.get("callback", None) if not values: if callback: # this is specifically to handle the (most common) use case of JSONP blowing # chunks if the response is a 404 as the borwser will not do anything further # causing the callback in your javascript library to never fire response = json_response(**dict(message="no data for key")) elif return404 and return404 == "false": response = json_response(**dict(message="no data for key")) else: response = json_response(**dict(message="no data for key", status_code=404)) else: if callback: response = "%s(%s);" % (callback, values), 200, {"Content-Type": "application/javascript"} else: response = values, 200, {"Content-Type": first_content_type} return response