#NEWLINE# def extract_header( msg_or_header ) : #NEWLINE# #INDENT# 'Given a message or header, return the header.' #NEWLINE# if ( not h ) : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# h = msg_or_header [ 'header' ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# h = msg_or_header [ 'msg_id' ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# h = msg_or_header #NEWLINE# #UNINDENT# #UNINDENT# if ( not isinstance ( h , dict ) ) : #NEWLINE# #INDENT# h = dict ( h ) #NEWLINE# #UNINDENT# return h