#NEWLINE# def code( action , data , mimetype , encoding = 'utf-8' ) : #NEWLINE# #INDENT# if ( ( action == 'dump' ) and hasattr ( data , 'read' ) ) : #NEWLINE# #INDENT# data = data . read ( ) #NEWLINE# #UNINDENT# if ( ( action == 'dump' ) and isinstance ( data , bytes ) ) : #NEWLINE# #INDENT# return getattr ( Binary , action ) ( data , encoding ) #NEWLINE# #UNINDENT# if ( ( action == 'load' ) and ( not data ) ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# if ( ( action == 'load' ) and ( mimetype not in DataHandler . registry ) ) : #NEWLINE# #INDENT# return getattr ( Binary , action ) ( data , encoding ) #NEWLINE# #UNINDENT# if ( ( mimetype in DataHandler . registry ) and getattr ( DataHandler . registry [ mimetype ] , action , None ) ) : #NEWLINE# #INDENT# return getattr ( DataHandler . registry [ mimetype ] , action ) ( data , encoding ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise Exception ( 'Cannot parse MIME type {}' . format ( mimetype ) )