#NEWLINE# def _expand_vars( self , cmd ) : #NEWLINE# #INDENT# '\n    Utility method to substitute variables in strings.\n\n    Looks for variables of the form __NAME__ in the string and then replace it\n    with local attributes of the same name (if any).\n    ' #NEWLINE# if ( cmd is None ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# for cstr in re . findall ( '__[^_]*__' , cmd ) : #NEWLINE# #INDENT# attr = cstr . strip ( '__' ) #NEWLINE# if ( hasattr ( self , cmd ) and ( getattr ( self , attr , None ) is not None ) ) : #NEWLINE# #INDENT# cmd = cmd . replace ( cstr , str ( getattr ( self , attr ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# return cmd