#NEWLINE# def encode( data , mime_type = '' , charset = 'utf-8' , base64 = True ) : #NEWLINE# #INDENT# '\n    Encode data to DataURL\n    ' #NEWLINE# if isinstance ( data , six . text_type ) : #NEWLINE# #INDENT# data = data . encode ( charset ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# charset = None #NEWLINE# #UNINDENT# if base64 : #NEWLINE# #INDENT# data = utils . text ( b64encode ( data ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# data = utils . text ( quote ( data ) ) #NEWLINE# #UNINDENT# result = [ 'data:' ] #NEWLINE# if mime_type : #NEWLINE# #INDENT# result . append ( mime_type ) #NEWLINE# #UNINDENT# if charset : #NEWLINE# #INDENT# result . append ( ';charset=' ) #NEWLINE# result . append ( charset ) #NEWLINE# #UNINDENT# if base64 : #NEWLINE# #INDENT# result . append ( ';base64' ) #NEWLINE# #UNINDENT# result . append ( ',' ) #NEWLINE# result . append ( data ) #NEWLINE# return '' . join ( result )