Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/config.py @ 526:48990863b905
Rename internal cache from __cache to __lookup_cache
| author | Franz Glasner <f.glasner@feldmann-mg.com> |
|---|---|
| date | Mon, 20 Dec 2021 12:45:48 +0100 |
| parents | be6ef72c55d5 |
| children | 08924499db3c |
comparison
equal
deleted
inserted
replaced
| 525:be6ef72c55d5 | 526:48990863b905 |
|---|---|
| 332 | 332 |
| 333 def __init__(self, *args, **kwds): | 333 def __init__(self, *args, **kwds): |
| 334 # | 334 # |
| 335 # PY2.7 compat: must be set before calling the superclass' __init__ | 335 # PY2.7 compat: must be set before calling the superclass' __init__ |
| 336 # | 336 # |
| 337 self.__cache = {} | 337 self.__lookup_cache = {} |
| 338 super(Configuration, self).__init__(*args, **kwds) | 338 super(Configuration, self).__init__(*args, **kwds) |
| 339 | 339 |
| 340 def clear_cache(self): | 340 def clear_cache(self): |
| 341 """Clear the internal lookup cache""" | 341 """Clear the internal lookup cache""" |
| 342 self.__cache.clear() | 342 self.__lookup_cache.clear() |
| 343 | 343 |
| 344 def __getitem__(self, key): | 344 def __getitem__(self, key): |
| 345 """Mapping and list interface that forwards to :meth:`~.getvarl_s` | 345 """Mapping and list interface that forwards to :meth:`~.getvarl_s` |
| 346 | 346 |
| 347 """ | 347 """ |
| 676 :raise KeyError: An unexisting `path` raises a `KeyError` | 676 :raise KeyError: An unexisting `path` raises a `KeyError` |
| 677 | 677 |
| 678 """ | 678 """ |
| 679 if not path: | 679 if not path: |
| 680 return self | 680 return self |
| 681 v = self.__cache.get(path, _MARKER) | 681 v = self.__lookup_cache.get(path, _MARKER) |
| 682 if v is not _MARKER: | 682 if v is not _MARKER: |
| 683 if v is _MISSING: | 683 if v is _MISSING: |
| 684 raise KeyError( | 684 raise KeyError( |
| 685 "Configuration variable %r not found" | 685 "Configuration variable %r not found" |
| 686 " (negative internal cache value)" % (path,)) | 686 " (negative internal cache value)" % (path,)) |
| 690 try: | 690 try: |
| 691 v = eiref(super(Configuration, self).__getitem__(path[0])) | 691 v = eiref(super(Configuration, self).__getitem__(path[0])) |
| 692 for p in path[1:]: | 692 for p in path[1:]: |
| 693 v = eiref(v[p]) | 693 v = eiref(v[p]) |
| 694 except TypeError: | 694 except TypeError: |
| 695 self.__cache[path] = _MISSING | 695 self.__lookup_cache[path] = _MISSING |
| 696 raise KeyError( | 696 raise KeyError( |
| 697 "Configuration variable %r not found" | 697 "Configuration variable %r not found" |
| 698 "(missing intermediate keys?)" % (path,)) | 698 "(missing intermediate keys?)" % (path,)) |
| 699 except KeyError: | 699 except KeyError: |
| 700 self.__cache[path] = _MISSING | 700 self.__lookup_cache[path] = _MISSING |
| 701 raise | 701 raise |
| 702 self.__cache[path] = v | 702 self.__lookup_cache[path] = v |
| 703 return v | 703 return v |
| 704 | 704 |
| 705 def _lookupref(self, key): | 705 def _lookupref(self, key): |
| 706 """ | 706 """ |
| 707 | 707 |
