comparison 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
comparison
equal deleted inserted replaced
459:9dc9cef1b9cd 460:d22985d6806e
26 from urllib.parse import urlsplit 26 from urllib.parse import urlsplit
27 except ImportError: 27 except ImportError:
28 from urlparse import urlsplit 28 from urlparse import urlsplit
29 29
30 from .variables import lookup_varns, lookup_filter 30 from .variables import lookup_varns, lookup_filter
31 from .compat import u, uchr, n 31 from .compat import u, uchr, n, PY2
32 from .constants import REF_NAMESPACE, NONE_FILTER, EMPTY_FILTER 32 from .constants import REF_NAMESPACE, NONE_FILTER, EMPTY_FILTER
33 33
34 34
35 _MARKER = object() 35 _MARKER = object()
36 36
941 return self._base.getfirstvar_s(*real_varnames, **kwds) 941 return self._base.getfirstvar_s(*real_varnames, **kwds)
942 942
943 def __iter__(self): 943 def __iter__(self):
944 return iter(self._base.getvarl_s(*self._path)) 944 return iter(self._base.getvarl_s(*self._path))
945 945
946 if PY2:
947
948 def __nonzero__(self):
949 return bool(self._base.getvarl_s(*self._path))
950
951 else:
952
953 def __bool__(self):
954 return bool(self._base.getvarl_s(*self._path))
955
946 def jailed(self, rootpath=None, root=None, bind_root=True): 956 def jailed(self, rootpath=None, root=None, bind_root=True):
947 """Return a "jailed" configuration that effectively is a 957 """Return a "jailed" configuration that effectively is a
948 subjail of the current jail 958 subjail of the current jail
949 959
950 For a more complete description see :meth:`.Configuration.jailed`. 960 For a more complete description see :meth:`.Configuration.jailed`.