Mercurial > hgrepos > Python > libs > ConfigMix
changeset 411:3c95faa91dad
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.
| author | Franz Glasner <f.glasner@feldmann-mg.com> |
|---|---|
| date | Fri, 19 Nov 2021 15:52:01 +0100 |
| parents | dd46257d2b22 |
| children | 816327e178b0 |
| files | configmix/config.py |
| diffstat | 1 files changed, 10 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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):
