# Path: nudge/json.py
# def json_encode(o):
#     return _encoder.encode(o)
# 
# Path: nudge/error.py
# DEFAULT_ERROR_CODE = 500
# DEFAULT_ERROR_CONTENT_TYPE = "application/json; charset=UTF-8"
# DEFAULT_ERROR_CONTENT = '{"message": "%s", "code": %i}' % (
#     "Internal Server Error",
#     DEFAULT_ERROR_CODE,
# )
# class JsonErrorHandler(object):
# class HTTPError(Exception):
# class SecurityException(Exception):
#     def __call__(self, exp, req=None, log_assert=True):
# def handle_exception(exp, exp_handlers, default_handler=None):
#     def __init__(self, status_code, message=None):


import base64
import types
from cStringIO import StringIO
from nudge.json import json_encode
from nudge.error import HTTPException, SecurityException

class Json(object):
    ''' Default Nudge HTTP Content Type. Encodes the entire endpoint
        result as json, and returns.

        Note this renderer will not allow you to pass back a top level
        list or tuple (javascript array) because it is insecure, and could
        allow a CSRF attack. See here:
        http://flask.pocoo.org/docs/security/#json-security
    '''
    def __call__(self, result):
        if result == None:
            raise HTTPException(404)
        if isinstance(result, (types.ListType, types.TupleType)):
            raise SecurityException(
                'Results that encode as json arrays are not '+\
                'allowed for security concerns'
            )
        return Result(
            content=json_encode(result),
            content_type='application/json; charset=UTF-8',
            http_status=200,
        )

class InsecureJson(object):
    ''' See the notes above for Json. This does not check returned types. '''
    def __call__(self, result):
        if result == None:
            raise HTTPException(404)
        return Result(

# Path: nudge/json.py
# def json_encode(o):
#     return _encoder.encode(o)
# 
# Path: nudge/error.py
# DEFAULT_ERROR_CODE = 500
# DEFAULT_ERROR_CONTENT_TYPE = "application/json; charset=UTF-8"
# DEFAULT_ERROR_CONTENT = '{"message": "%s", "code": %i}' % (
#     "Internal Server Error",
#     DEFAULT_ERROR_CODE,
# )
# class JsonErrorHandler(object):
# class HTTPError(Exception):
# class SecurityException(Exception):
#     def __call__(self, exp, req=None, log_assert=True):
# def handle_exception(exp, exp_handlers, default_handler=None):
#     def __init__(self, status_code, message=None):


# Path: nudge/renderer.py
import base64
import types
from cStringIO import StringIO
from nudge.json import json_encode
from nudge.error import HTTPException, SecurityException


class Json(object):
    ''' Default Nudge HTTP Content Type. Encodes the entire endpoint
        result as json, and returns.

        Note this renderer will not allow you to pass back a top level
        list or tuple (javascript array) because it is insecure, and could
        allow a CSRF attack. See here:
        http://flask.pocoo.org/docs/security/#json-security
    '''
    def __call__(self, result):
        if result == None:
            raise HTTPException(404)
        if isinstance(result, (types.ListType, types.TupleType)):
            raise SecurityException(
                'Results that encode as json arrays are not '+\
                'allowed for security concerns'
            )
        return Result(
            content=json_encode(result),
            content_type='application/json; charset=UTF-8',
            http_status=200,
        )

class InsecureJson(object):
    ''' See the notes above for Json. This does not check returned types. '''
    def __call__(self, result):
        if result == None:
            raise HTTPException(404)
        return Result(

            content=json_encode(result),