#NEWLINE# def msg_ser( inst , sformat , lev = 0 ) : #NEWLINE# #INDENT# if ( sformat in [ 'urlencoded' , 'json' ] ) : #NEWLINE# #INDENT# if ( isinstance ( inst , dict ) or isinstance ( inst , Message ) ) : #NEWLINE# #INDENT# res = inst . serialize ( sformat , lev ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# res = inst #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( sformat == 'dict' ) : #NEWLINE# #INDENT# if isinstance ( inst , Message ) : #NEWLINE# #INDENT# res = inst . serialize ( sformat , lev ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( inst , dict ) : #NEWLINE# #INDENT# res = inst #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( inst , six . string_types ) : #NEWLINE# #INDENT# res = inst #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise MessageException ( ( 'Wrong type: %s' % type ( inst ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise PyoidcError ( 'Unknown sformat' , inst ) #NEWLINE# #UNINDENT# #UNINDENT# return res