Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/config.py @ 493:6a0f761ff35b
Remove default (i.e. all keyword arguments) from .expand_if_reference() because no-one uses it
| author | Franz Glasner <f.glasner@feldmann-mg.com> |
|---|---|
| date | Fri, 17 Dec 2021 18:58:06 +0100 |
| parents | de776953337b |
| children | 3f0c932588fc |
comparison
equal
deleted
inserted
replaced
| 492:a9a291927a4b | 493:6a0f761ff35b |
|---|---|
| 577 :raise KeyError: An unexisting `path` raises a `KeyError` | 577 :raise KeyError: An unexisting `path` raises a `KeyError` |
| 578 | 578 |
| 579 """ | 579 """ |
| 580 if not path: | 580 if not path: |
| 581 return self | 581 return self |
| 582 eiref = self.expand_if_reference | |
| 582 try: | 583 try: |
| 583 v = self.expand_if_reference( | 584 v = eiref(super(Configuration, self).__getitem__(path[0])) |
| 584 super(Configuration, self).__getitem__(path[0])) | |
| 585 for p in path[1:]: | 585 for p in path[1:]: |
| 586 v = self.expand_if_reference(v[p]) | 586 v = eiref(v[p]) |
| 587 except TypeError: | 587 except TypeError: |
| 588 raise KeyError( | 588 raise KeyError( |
| 589 "Configuration variable %r not found" | 589 "Configuration variable %r not found" |
| 590 "(missing intermediate keys?)" % (path,)) | 590 "(missing intermediate keys?)" % (path,)) |
| 591 return v | 591 return v |
| 597 (namespace) prefixes and suffixes | 597 (namespace) prefixes and suffixes |
| 598 | 598 |
| 599 """ | 599 """ |
| 600 return self.expand_ref_uri(key, default=default) | 600 return self.expand_ref_uri(key, default=default) |
| 601 | 601 |
| 602 def expand_if_reference(self, v, default=_MARKER): | 602 def expand_if_reference(self, v): |
| 603 """Check whether `v` is a configuration reference and -- if true -- | 603 """Check whether `v` is a configuration reference and -- if true -- |
| 604 then expand it. | 604 then expand it. |
| 605 | 605 |
| 606 `v` must match the pattern ``{{ref:<REFERENCE>}}`` | 606 `v` must match the pattern ``{{ref:<REFERENCE>}}`` |
| 607 | 607 |
| 608 All non-matching texttypes and all non-texttypes are returned | 608 All non-matching texttypes and all non-texttypes are returned |
| 609 unchanged. | 609 unchanged. |
| 610 | |
| 611 :raise KeyError: If the reverence cannot found | |
| 610 | 612 |
| 611 """ | 613 """ |
| 612 if not isinstance(v, self._TEXTTYPE): | 614 if not isinstance(v, self._TEXTTYPE): |
| 613 return v | 615 return v |
| 614 if v.startswith(self._STARTTOK_REF) and v.endswith(self._ENDTOK_REF): | 616 if v.startswith(self._STARTTOK_REF) and v.endswith(self._ENDTOK_REF): |
| 615 return self.expand_ref_uri( | 617 return self.expand_ref_uri( |
| 616 v[len(self._STARTTOK_REF):-len(self._ENDTOK_REF)], | 618 v[len(self._STARTTOK_REF):-len(self._ENDTOK_REF)]) |
| 617 default=default) | |
| 618 else: | 619 else: |
| 619 return v | 620 return v |
| 620 | 621 |
| 621 def expand_ref_uri(self, uri, default=_MARKER): | 622 def expand_ref_uri(self, uri, default=_MARKER): |
| 622 pu = urlsplit(uri) | 623 pu = urlsplit(uri) |
