#NEWLINE# def zulip_finish( self , response , request , apply_markdown ) : #NEWLINE# #INDENT# if ( ( response [ 'result' ] == 'success' ) and ( 'messages' in response ) and request ) : #NEWLINE# #INDENT# for msg in response [ 'messages' ] : #NEWLINE# #INDENT# if ( msg [ 'content_type' ] != 'text/html' ) : #NEWLINE# #INDENT# self . set_status ( 500 ) #NEWLINE# return self . finish ( 'Internal error: bad message format' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( response [ 'result' ] == 'error' ) : #NEWLINE# #INDENT# self . set_status ( 400 ) #NEWLINE# #UNINDENT# django_response = json_response ( res_type = response [ 'result' ] , data = response , status = self . get_status ( ) ) #NEWLINE# django_response = self . apply_response_middleware ( request , django_response , request . _resolver ) #NEWLINE# self . set_header ( 'Content-Type' , django_response [ 'Content-Type' ] ) #NEWLINE# return self . finish ( django_response . content )