def markup_json(view_fun):
 def _markup_json(request, *args, **kwargs):
  request.IS_JSON = (request.GET.get('format') == 'json')
  if request.IS_JSON:
   request.JSON_CALLBACK = request.GET.get('callback', '').strip()
  else:
   request.JSON_CALLBACK = ''
  if request.IS_JSON:
   request.CONTENT_TYPE = ('application/x-javascript' if request.JSON_CALLBACK else 'application/json')
  else:
   request.CONTENT_TYPE = 'text/html'
  if (request.JSON_CALLBACK and (not jsonp_is_valid(request.JSON_CALLBACK))):
   return HttpResponse(json.dumps({'error': _('Invalid callback function.')}), content_type=request.CONTENT_TYPE, status=400)
  return view_fun(request, *args, **kwargs)
 return _markup_json

def markup_json ( view_fun ) : def _markup_json ( request , * args , ** kwargs ) : request . IS_JSON = ( request . GET . get ( 'format' ) == 'json' ) if request . IS_JSON : request . JSON_CALLBACK = request . GET . get ( 'callback' , '' ) . strip ( ) else : request . JSON_CALLBACK = '' if request . IS_JSON : request . CONTENT_TYPE = ( 'application/x-javascript' if request . JSON_CALLBACK else 'application/json' ) else : request . CONTENT_TYPE = 'text/html' if ( request . JSON_CALLBACK and ( not jsonp_is_valid ( request . JSON_CALLBACK ) ) ) : return HttpResponse ( json . dumps ( { 'error' : _ ( 'Invalid callback function.' ) } ) , content_type = request . CONTENT_TYPE , status = 400 ) return view_fun ( request , * args , ** kwargs ) return _markup_json
marks up the request object with json bits * is_json: whether or not this is a json request * json_callback: the json callback function to wrap with * content_type: the content type to return further .