#NEWLINE# def to_str( s , encoding = None ) : #NEWLINE# #INDENT# '\n    Given str, bytes, bytearray, or unicode (py2), return str\n    ' #NEWLINE# if isinstance ( s , str ) : #NEWLINE# #INDENT# return s #NEWLINE# #UNINDENT# if six . PY3 : #NEWLINE# #INDENT# if isinstance ( s , ( bytes , bytearray ) ) : #NEWLINE# #INDENT# return s . decode ( ( encoding or __salt_system_encoding__ ) ) #NEWLINE# #UNINDENT# raise TypeError ( 'expected str, bytes, or bytearray' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( s , bytearray ) : #NEWLINE# #INDENT# return str ( s ) #NEWLINE# #UNINDENT# if isinstance ( s , unicode ) : #NEWLINE# #INDENT# return s . encode ( ( encoding or __salt_system_encoding__ ) ) #NEWLINE# #UNINDENT# raise TypeError ( 'expected str, bytearray, or unicode' )