Takes a string containing variable references in the form ${FOO}, $(FOO), or $FOO, and returns a string with all variable references in the form ${FOO}.
(str)
| 1815 | |
| 1816 | |
| 1817 | def _NormalizeEnvVarReferences(str): |
| 1818 | """Takes a string containing variable references in the form ${FOO}, $(FOO), |
| 1819 | or $FOO, and returns a string with all variable references in the form ${FOO}. |
| 1820 | """ |
| 1821 | # $FOO -> ${FOO} |
| 1822 | str = re.sub(r"\$([a-zA-Z_][a-zA-Z0-9_]*)", r"${\1}", str) |
| 1823 | |
| 1824 | # $(FOO) -> ${FOO} |
| 1825 | matches = re.findall(r"(\$\(([a-zA-Z0-9\-_]+)\))", str) |
| 1826 | for match in matches: |
| 1827 | to_replace, variable = match |
| 1828 | assert "$(" not in match, "$($(FOO)) variables not supported: " + match |
| 1829 | str = str.replace(to_replace, "${" + variable + "}") |
| 1830 | |
| 1831 | return str |
| 1832 | |
| 1833 | |
| 1834 | def ExpandEnvVars(string, expansions): |
no outgoing calls
no test coverage detected