#NEWLINE# def to( self , responder , env = None ) : #NEWLINE# #INDENT# env = ( env or { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# status = self . status #NEWLINE# headers = self . headers #NEWLINE# if ( status in defined_status ) : #NEWLINE# #INDENT# status = ( '%d %s' % ( status , defined_status [ status ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( status , int ) : #NEWLINE# #INDENT# status = ( '%d UNKNOWN ERROR' % status ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# status = str ( status ) #NEWLINE# if ( not regex_status . match ( status ) ) : #NEWLINE# #INDENT# status = ( '500 %s' % defined_status [ 500 ] ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# headers . setdefault ( 'Content-Type' , 'text/html; charset=UTF-8' ) #NEWLINE# body = self . body #NEWLINE# if ( status [ : 1 ] == '4' ) : #NEWLINE# #INDENT# if ( not body ) : #NEWLINE# #INDENT# body = status #NEWLINE# #UNINDENT# if isinstance ( body , str ) : #NEWLINE# #INDENT# headers [ 'Content-Length' ] = len ( body ) #NEWLINE# #UNINDENT# #UNINDENT# rheaders = [ ] #NEWLINE# for ( k , v ) in headers . iteritems ( ) : #NEWLINE# #INDENT# if isinstance ( v , list ) : #NEWLINE# #INDENT# rheaders += [ ( k , str ( item ) ) for item in v ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not ( v is None ) ) : #NEWLINE# #INDENT# rheaders . append ( ( k , str ( v ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# responder ( status , rheaders ) #NEWLINE# if ( env . get ( 'request_method' , '' ) == 'HEAD' ) : #NEWLINE# #INDENT# return [ '' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( body , str ) : #NEWLINE# #INDENT# return [ body ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if hasattr ( body , '__iter__' ) : #NEWLINE# #INDENT# return body #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return [ str ( body ) ]