# HG changeset patch # User Franz Glasner # Date 1637333521 -3600 # Node ID 3c95faa91dad0beca586b494e2f2d3462b07aa1f # Parent dd46257d2b22a7cd6aae36b96dcc9715dac2614c Optimize the creation of a jailed config. Allow to skip the binding of the base in case the caller wants to rebind just after creation anyways. diff -r dd46257d2b22 -r 3c95faa91dad configmix/config.py --- a/configmix/config.py Fri Nov 19 13:37:30 2021 +0100 +++ b/configmix/config.py Fri Nov 19 15:52:01 2021 +0100 @@ -654,7 +654,7 @@ raise ValueError("unknown quote syntax string: {}".format(s)) return ''.join(res) - def jailed(self, rootpath=None, root=None): + def jailed(self, rootpath=None, root=None, bind_root=True): """Return a "jailed" configuration of the current configuration. :param rootpath: a sequence of strings that shall emcompass @@ -663,6 +663,10 @@ :type rootpath: list or tuple :param str root: a string path expression that shall encompass the chroot-like jail of the returned configuration + :param bool bind_root: if you do a :meth:`~.rebind` just after + creation of a jailed config you can set + `bind_root` to `False`; otherwise use + the default :return: a jailed (aka restricted) configuration :rtype: _JailedConfiguration @@ -683,8 +687,10 @@ self.unquote(p) for p in root.split( self._HIER_SEPARATOR) ] - - return _JailedConfiguration(self, *rootpath) + jc = _JailedConfiguration(*rootpath) + if bind_root: + jc.rebind(self) + return jc class _JailedConfiguration(object): @@ -714,7 +720,7 @@ is_jail = True """Flag to show that this is a jail for another configuration""" - def __init__(self, config, *path): + def __init__(self, *path): super(_JailedConfiguration, self).__init__() self._path = path if path: @@ -724,7 +730,6 @@ + Configuration._HIER_SEPARATOR else: self._pathstr = '' - self.rebind(config) @property def base(self):