Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/config.py @ 525:be6ef72c55d5
Change Configuration.expand_variable() to Configuration.interpolate_variables()
| author | Franz Glasner <f.glasner@feldmann-mg.com> |
|---|---|
| date | Mon, 20 Dec 2021 12:43:17 +0100 |
| parents | 09b8e28b7a44 |
| children | 48990863b905 |
comparison
equal
deleted
inserted
replaced
| 524:09b8e28b7a44 | 525:be6ef72c55d5 |
|---|---|
| 751 def substitute_variables_in_obj(self, obj): | 751 def substitute_variables_in_obj(self, obj): |
| 752 """Recursively expand variables in the object tree `obj`.""" | 752 """Recursively expand variables in the object tree `obj`.""" |
| 753 ty = type(obj) | 753 ty = type(obj) |
| 754 if issubclass(ty, _TEXTTYPE): | 754 if issubclass(ty, _TEXTTYPE): |
| 755 # a string - really replace the value | 755 # a string - really replace the value |
| 756 return self.expand_variable(obj) | 756 return self.interpolate_variables(obj) |
| 757 elif issubclass(ty, dict): | 757 elif issubclass(ty, dict): |
| 758 newdict = ty() | 758 newdict = ty() |
| 759 for k, v in obj.items(): | 759 for k, v in obj.items(): |
| 760 newdict[k] = self.substitute_variables_in_obj(v) | 760 newdict[k] = self.substitute_variables_in_obj(v) |
| 761 return newdict | 761 return newdict |
| 768 for i in obj: | 768 for i in obj: |
| 769 newset.add(self.substitute_variables_in_obj(i)) | 769 newset.add(self.substitute_variables_in_obj(i)) |
| 770 else: | 770 else: |
| 771 return obj | 771 return obj |
| 772 | 772 |
| 773 def expand_variable(self, s): | 773 def interpolate_variables(self, s): |
| 774 """Expand variables in the single string `s`""" | 774 """Expand all variables in the single string `s`""" |
| 775 start = s.find(_STARTTOK, 0) | 775 start = s.find(_STARTTOK, 0) |
| 776 if start < 0: | 776 if start < 0: |
| 777 return s | 777 return s |
| 778 len_s = len(s) | 778 len_s = len(s) |
| 779 res = [] | 779 res = [] |
