Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/config.py @ 39:8715e5cc59ac
Print a warning if a variable cannot be expanded.
This is to simplify debugging.
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Thu, 07 Apr 2016 23:12:12 +0200 |
| parents | b04a350f894b |
| children | 8d66aef2f7fb |
comparison
equal
deleted
inserted
replaced
| 38:ce2443285000 | 39:8715e5cc59ac |
|---|---|
| 4 | 4 |
| 5 """ | 5 """ |
| 6 | 6 |
| 7 from __future__ import division, absolute_import, print_function | 7 from __future__ import division, absolute_import, print_function |
| 8 | 8 |
| 9 import warnings | |
| 9 try: | 10 try: |
| 10 from collections import OrderedDict as ConfigurationBase | 11 from collections import OrderedDict as ConfigurationBase |
| 11 except ImportError: | 12 except ImportError: |
| 12 try: | 13 try: |
| 13 from ordereddict import OrderedDict as ConfigurationBase | 14 from ordereddict import OrderedDict as ConfigurationBase |
| 191 while start != -1: | 192 while start != -1: |
| 192 end = s.find(self._ENDTOK, start) | 193 end = s.find(self._ENDTOK, start) |
| 193 if end < 0: | 194 if end < 0: |
| 194 return s | 195 return s |
| 195 varname, filters = self._split_filters(s[start+2:end]) | 196 varname, filters = self._split_filters(s[start+2:end]) |
| 196 varvalue = self._apply_filters(filters, self.getvar_s(varname)) | 197 try: |
| 198 varvalue = self._apply_filters(filters, self.getvar_s(varname)) | |
| 199 except KeyError: | |
| 200 warnings.warn("Cannot expand variable %r in string " | |
| 201 "%r" % (varname, s, ), | |
| 202 UserWarning, | |
| 203 stacklevel=1) | |
| 204 raise | |
| 197 if varvalue is None: | 205 if varvalue is None: |
| 198 varvalue = u("") | 206 varvalue = u("") |
| 199 replaced = u(b"{0}{1}").format(s[:start], varvalue) | 207 replaced = u(b"{0}{1}").format(s[:start], varvalue) |
| 200 s = u(b"{0}{1}").format(replaced, s[end+2:]) | 208 s = u(b"{0}{1}").format(replaced, s[end+2:]) |
| 201 # don't re-evaluate because `self.getvar_s()` expands already | 209 # don't re-evaluate because `self.getvar_s()` expands already |
