pvl/web/response.py
author Tero Marttila <terom@paivola.fi>
Sun, 07 Sep 2014 16:04:42 +0300
changeset 431 4e920e09fc60
parent 197 9f18b11647fb
permissions -rw-r--r--
version 0.7.3

* pvl.rrd-interfaces: ignore .txt on input files
from werkzeug.wrappers import Response
from werkzeug.exceptions import (
        HTTPException, 
        BadRequest,         # 400
        NotFound,           # 404
)
from werkzeug.utils import redirect


import json as _json

def html (tag, **opts) :
    """
        Return text/html response for given pvl.web.html
    """

    return Response(unicode(tag), mimetype='text/html', **opts)

def json (data, **opts) :
    """
        Return text/json response for given object.
    """

    return Response(_json.dumps(data), mimetype='text/json', **opts)

def image (file, type='png') :
    """
        Return image/{type} response for given file-like object.
    """
 
    # respond with file wrapper
    return Response(file, mimetype='image/{type}'.format(type=type), direct_passthrough=True)