#NEWLINE# def __call__( self , environ , start_response ) : #NEWLINE# #INDENT# response = { #NEWLINE# #INDENT# 'status' : '200 OK' , #NEWLINE# 'headers' : [ ] , #NEWLINE# #UNINDENT# } #NEWLINE# def json_start_response( status , headers ) : #NEWLINE# #INDENT# response [ 'status' ] = status #NEWLINE# response [ 'headers' ] . extend ( headers ) #NEWLINE# #UNINDENT# environ [ 'jsonfilter.mime_type' ] = self . mime_type #NEWLINE# if ( environ . get ( 'REQUEST_METHOD' , '' ) == 'POST' ) : #NEWLINE# #INDENT# if ( environ . get ( 'CONTENT_TYPE' , '' ) == self . mime_type ) : #NEWLINE# #INDENT# args = [ _ for _ in [ environ . get ( 'CONTENT_LENGTH' ) ] if _ ] #NEWLINE# data = environ [ 'wsgi.input' ] . read ( * map ( int , args ) ) #NEWLINE# environ [ 'jsonfilter.json' ] = simplejson . loads ( res ) #NEWLINE# #UNINDENT# #UNINDENT# res = simplejson . dumps ( self . app ( environ , json_start_response ) ) #NEWLINE# jsonp = cgi . parse_qs ( environ . get ( 'QUERY_STRING' , '' ) ) . get ( 'jsonp' ) #NEWLINE# if jsonp : #NEWLINE# #INDENT# content_type = 'text/javascript' #NEWLINE# res = '' . join ( ( jsonp + [ '(' , res , ')' ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( 'Opera' in environ . get ( 'HTTP_USER_AGENT' , '' ) ) : #NEWLINE# #INDENT# content_type = 'text/plain' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# content_type = self . mime_type #NEWLINE# #UNINDENT# #UNINDENT# headers = [ ( 'Content-type' , content_type ) , ( 'Content-length' , len ( res ) ) ] #NEWLINE# headers . extend ( response [ 'headers' ] ) #NEWLINE# start_response ( response [ 'status' ] , headers ) #NEWLINE# return [ res ]