diff configmix/config.py @ 448:b95c12781497

Attribute-style access for jailed configurations
author Franz Glasner <fzglas.hg@dom66.de>
date Sat, 11 Dec 2021 19:56:35 +0100
parents 23941c014130
children 5864977bb44f
line wrap: on
line diff
--- a/configmix/config.py	Fri Dec 10 12:00:24 2021 +0100
+++ b/configmix/config.py	Sat Dec 11 19:56:35 2021 +0100
@@ -847,6 +847,18 @@
         if self._path:
             new_base.getvarl(*self._path)
 
+    def __getattr__(self, name):
+        try:
+            v = self._base.getvarl_s(*(self._path + (name, )))
+        except KeyError:
+            raise AttributeError("%s has no attribute %r" % (type(self), name))
+        else:
+            # Wrap a dict into another dict with attribute access support
+            if isinstance(v, dict):
+                return _AttributeDict(v)
+            else:
+                return v
+
     def __getitem__(self, key):
         """Mapping interface that forwards to :meth:`~.getvarl_s`