#NEWLINE# def finalize( self ) : #NEWLINE# #INDENT# 'Transform headers (and cookies) into self.header_list. (Core)' #NEWLINE# try : #NEWLINE# #INDENT# ( code , reason , _ ) = httputil . valid_status ( self . status ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise cherrypy . HTTPError ( 500 , sys . exc_info ( ) [ 1 ] . args [ 0 ] ) #NEWLINE# #UNINDENT# headers = self . headers #NEWLINE# self . status = ( '%s %s' % ( code , reason ) ) #NEWLINE# self . output_status = ( ( ntob ( str ( code ) , 'ascii' ) + ntob ( ' ' ) ) + headers . encode ( reason ) ) #NEWLINE# if self . stream : #NEWLINE# #INDENT# if ( dict . get ( headers , 'Content-Length' ) is None ) : #NEWLINE# #INDENT# dict . pop ( headers , 'Content-Length' , None ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( code < 200 ) or ( code in ( 204 , 205 , 304 ) ) ) : #NEWLINE# #INDENT# dict . pop ( headers , 'Content-Length' , None ) #NEWLINE# self . body = ntob ( '' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( dict . get ( headers , 'Content-Length' ) is None ) : #NEWLINE# #INDENT# content = self . collapse_body ( ) #NEWLINE# dict . __setitem__ ( headers , 'Content-Length' , len ( content ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# self . header_list = h = headers . output ( ) #NEWLINE# cookie = self . cookie . output ( ) #NEWLINE# if cookie : #NEWLINE# #INDENT# for line in cookie . split ( '\n' ) : #NEWLINE# #INDENT# if line . endswith ( '\r' ) : #NEWLINE# #INDENT# line = line [ : ( - 1 ) ] #NEWLINE# #UNINDENT# ( name , value ) = line . split ( ': ' , 1 ) #NEWLINE# if isinstance ( name , unicodestr ) : #NEWLINE# #INDENT# name = name . encode ( 'ISO-8859-1' ) #NEWLINE# #UNINDENT# if isinstance ( value , unicodestr ) : #NEWLINE# #INDENT# value = headers . encode ( value ) #NEWLINE# #UNINDENT# h . append ( ( name , value ) )