(func, *args, **kwargs)
return simplejson.dumps(data, cls=JSONEncoder, encoding='utf-8')
Action decorator that formats output for JSON

    Given a function that will return content, this decorator will turn
    the result into JSON, with a content-type of 'application/json' and
    output it.
Action decorator that formats output for JSON
Action decorator that formats output for JSON
def jsonify(func, *args, **kwargs):
    """Action decorator that formats output for JSON

    Given a function that will return content, this decorator will turn
    the result into JSON, with a content-type of 'application/json' and
    output it.

    """
    pylons = get_pylons(args)
    pylons.response.headers['Content-Type'] = 'application/json; charset=utf-8'
    data = func(*args, **kwargs)
    if isinstance(data, (list, tuple)):
        msg = "JSON responses with Array envelopes are susceptible to " \
              "cross-site data leak attacks, see " \
              "http://wiki.pylonshq.com/display/pylonsfaq/Warnings"
        warnings.warn(msg, Warning, 2)
        log.warning(msg)
    log.debug("Returning JSON wrapped action output")
    return simplejson.dumps(data, cls=JSONEncoder, encoding='utf-8')
def jsonify ( func , * args , * * kwargs ) : pylons = get_pylons ( args ) pylons . response . headers [ 'Content-Type' ] = 'application/json; charset=utf-8' data = func ( * args , * * kwargs ) if isinstance ( data , ( list , tuple ) ) : msg = "JSON responses with Array envelopes are susceptible to " "cross-site data leak attacks, see " "http://wiki.pylonshq.com/display/pylonsfaq/Warnings" warnings . warn ( msg , Warning , 2 ) log . warning ( msg ) log . debug ( "Returning JSON wrapped action output" ) return simplejson . dumps ( data , cls = JSONEncoder , encoding = 'utf-8' )