def _NormalizeEnvVarReferences(str):
 str = re.sub('\\$([a-zA-Z_][a-zA-Z0-9_]*)', '${\\1}', str)
 matches = re.findall('(\\$\\(([a-zA-Z0-9\\-_]+)\\))', str)
 for match in matches:
  (to_replace, variable) = match
  assert ('$(' not in match), ('$($(FOO)) variables not supported: ' + match)
  str = str.replace(to_replace, (('${' + variable) + '}'))
 return str

def _NormalizeEnvVarReferences ( str ) : str = re . sub ( '\\$([a-zA-Z_][a-zA-Z0-9_]*)' , '${\\1}' , str ) matches = re . findall ( '(\\$\\(([a-zA-Z0-9\\-_]+)\\))' , str ) for match in matches : ( to_replace , variable ) = match assert ( '$(' not in match ) , ( '$($(FOO)) variables not supported: ' + match ) str = str . replace ( to_replace , ( ( '${' + variable ) + '}' ) ) return str
takes a string containing variable references in the form ${foo} .