<s> from __future__ import print_function , unicode_literals , with_statement , division <EOL> from django . http import HttpResponse <EOL> try : <EOL> import json <EOL> except ImportError : <EOL> from django . utils import simplejson as json <EOL> class JsonResponse ( HttpResponse ) : <EOL> def __init__ ( self , data = None , errors = None , success = True ) : <EOL> """<STR_LIT>""" <EOL> if not errors : <EOL> errors = [ ] <EOL> if not data : <EOL> data = { } <EOL> json_resp = json_response ( data = data , errors = errors , success = success ) <EOL> super ( JsonResponse , self ) . __init__ ( json_resp , content_type = '<STR_LIT:application/json>' ) <EOL> class JsonpResponse ( HttpResponse ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , request , data = None , errors = None , success = True ) : <EOL> """<STR_LIT>""" <EOL> if not errors : <EOL> errors = [ ] <EOL> if not data : <EOL> data = { } <EOL> json_resp = json_response ( data = data , errors = errors , success = success ) <EOL> js = "<STR_LIT>" . format ( request . GET . get ( "<STR_LIT>" , "<STR_LIT>" ) , json_resp ) <EOL> super ( JsonpResponse , self ) . __init__ ( js , mimetype = '<STR_LIT>' ) <EOL> def json_response ( data = None , errors = None , success = True ) : <EOL> if not errors : <EOL> errors = [ ] <EOL> if not data : <EOL> data = { } <EOL> data . update ( { <EOL> '<STR_LIT>' : errors , <EOL> '<STR_LIT:success>' : len ( errors ) == <NUM_LIT:0> and success , <EOL> } ) <EOL> return json . dumps ( data ) <EOL> class XMLResponse ( HttpResponse ) : <EOL> def __init__ ( self , data ) : <EOL> """<STR_LIT>""" <EOL> super ( XMLResponse , self ) . __init__ ( data , mimetype = '<STR_LIT>' ) </s>
