diff configmix/config.py @ 460:d22985d6806e

Proper boolean context for jailed configurations: __bool__()/__nonzero__()
author Franz Glasner <fzglas.hg@dom66.de>
date Wed, 15 Dec 2021 09:10:01 +0100
parents 9dc9cef1b9cd
children 9fcdc42a0457
line wrap: on
line diff
--- a/configmix/config.py	Wed Dec 15 08:48:37 2021 +0100
+++ b/configmix/config.py	Wed Dec 15 09:10:01 2021 +0100
@@ -28,7 +28,7 @@
     from urlparse import urlsplit
 
 from .variables import lookup_varns, lookup_filter
-from .compat import u, uchr, n
+from .compat import u, uchr, n, PY2
 from .constants import REF_NAMESPACE, NONE_FILTER, EMPTY_FILTER
 
 
@@ -943,6 +943,16 @@
     def __iter__(self):
         return iter(self._base.getvarl_s(*self._path))
 
+    if PY2:
+
+        def __nonzero__(self):
+            return bool(self._base.getvarl_s(*self._path))
+
+    else:
+
+        def __bool__(self):
+            return bool(self._base.getvarl_s(*self._path))
+
     def jailed(self, rootpath=None, root=None, bind_root=True):
         """Return a "jailed" configuration that effectively is a
         subjail of the current jail