def json_input(f):
    """
    Expects task input data in json format and parse this data.
    """

    @wraps(f)
    def json_input_decorator(*args, **kwargs):
        # If the data is already transformed, we do not transform it any
        # further.
        task_data = _get_data_from_args(args)

        if task_data is None:
            logging.error("Task data is empty during JSON decoding.")

        if task_data.payload:
            try:
                is_transformed = request.get_json()

                # We transform the data only in the case of plain POST requests.
                if not is_transformed:
                    task_data.transform_payload(json.loads)
            except (ValueError, RuntimeError):
                logging.error(
                    "Exception while processing JSON input decorator.")
                task_data.transform_payload(json.loads)
        else:
            task_data.transform_payload(lambda _: {})

        return f(*args, **kwargs)

    return json_input_decorator
def json_input ( f ) : @ wraps ( f ) def json_input_decorator ( * args , ** kwargs ) : task_data = _get_data_from_args ( args ) if task_data is None : logging . error ( "Task data is empty during JSON decoding." ) if task_data . payload : try : is_transformed = request . get_json ( ) if not is_transformed : task_data . transform_payload ( json . loads ) except ( ValueError , RuntimeError ) : logging . error ( "Exception while processing JSON input decorator." ) task_data . transform_payload ( json . loads ) else : task_data . transform_payload ( lambda _ : { } ) return f ( * args , ** kwargs ) return json_input_decorator
Expects task input data in json format and parse this data.