Exemple #1
0
def _json_response(value, pretty=False):
    """Generate JSON flask response

    Args:
        value (dict): what to format
        pretty (bool): pretty print [False]
    Returns:
        Response: flask response
    """
    return app.response_class(
        simulation_db.generate_json(value, pretty=pretty),
        mimetype=app.config.get('JSONIFY_MIMETYPE', 'application/json'),
    )
Exemple #2
0
def _json_response(value, pretty=False):
    """Generate JSON flask response

    Args:
        value (dict): what to format
        pretty (bool): pretty print [False]
    Returns:
        Response: flask response
    """
    return app.response_class(
        simulation_db.generate_json(value, pretty=pretty),
        mimetype=app.config.get('JSONIFY_MIMETYPE', 'application/json'),
    )
Exemple #3
0
def app_error_logging():
    ip = flask.request.remote_addr
    try:
        pkdlog(
            '{}: javascript error: {}',
            ip,
            simulation_db.generate_json(_json_input(), pretty=True),
        )
    except ValueError as e:
        pkdlog(
            '{}: error parsing javascript app_error: {} input={}',
            ip,
            e,
            flask.request.data.decode('unicode-escape'),
        )
    return _json_response_ok();
Exemple #4
0
def api_errorLogging():
    ip = flask.request.remote_addr
    try:
        pkdlog(
            '{}: javascript error: {}',
            ip,
            simulation_db.generate_json(_json_input(), pretty=True),
        )
    except ValueError as e:
        pkdlog(
            '{}: error parsing javascript app_error: {} input={}',
            ip,
            e,
            flask.request.data.decode('unicode-escape'),
        )
    return _json_response_ok()
Exemple #5
0
def api_errorLogging():
    ip = flask.request.remote_addr
    try:
        pkdlog(
            '{}: javascript error: {}',
            ip,
            simulation_db.generate_json(http_request.parse_json(),
                                        pretty=True),
        )
    except Exception as e:
        pkdlog(
            'ip={}: error parsing javascript exception={} input={}',
            ip,
            e,
            flask.request.data and flask.request.data.decode('unicode-escape'),
        )
    return http_reply.gen_json_ok()
Exemple #6
0
def gen_json(value, pretty=False):
    """Generate JSON flask response

    Args:
        value (dict): what to format
        pretty (bool): pretty print [False]
    Returns:
        Response: flask response
    """
    global _JSON_MIMETYPE

    app = flask.current_app
    if not _JSON_MIMETYPE:
        _JSON_MIMETYPE = app.config.get('JSONIFY_MIMETYPE', 'application/json')
    return app.response_class(
        simulation_db.generate_json(value, pretty=pretty),
        mimetype=_JSON_MIMETYPE,
    )
Exemple #7
0
def gen_json(value, pretty=False):
    """Generate JSON flask response

    Args:
        value (dict): what to format
        pretty (bool): pretty print [False]
    Returns:
        Response: flask response
    """
    global _JSON_MIMETYPE

    app = flask.current_app
    if not _JSON_MIMETYPE:
        _JSON_MIMETYPE = app.config.get('JSONIFY_MIMETYPE', 'application/json')
    return app.response_class(
        simulation_db.generate_json(value, pretty=pretty),
        mimetype=_JSON_MIMETYPE,
    )