#NEWLINE# def string_value( value , encoding = None ) : #NEWLINE# #INDENT# if ( encoding is None ) : #NEWLINE# #INDENT# encoding = 'utf-8' #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# if ( value is None ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if isinstance ( value , ( date , datetime ) ) : #NEWLINE# #INDENT# return value . isoformat ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( isinstance ( value , float ) and ( not value . is_integer ( ) ) ) : #NEWLINE# #INDENT# return unicode ( value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( value , six . string_types ) : #NEWLINE# #INDENT# if ( not isinstance ( encoding , six . text_type ) ) : #NEWLINE# #INDENT# value = value . decode ( encoding ) #NEWLINE# #UNINDENT# if ( not len ( value . strip ( ) ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# value = unicode ( value ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return value #NEWLINE# #UNINDENT# except Exception as ex : #NEWLINE# #INDENT# log . exception ( ex ) #NEWLINE# return