Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/config.py @ 685:2e7920b0b4d9
Because Configuration.getvarl() expands references internally already extra handling of references in .jailed() is not needed
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 10 Jun 2023 21:38:13 +0200 |
| parents | a9eef98e5038 |
| children | 58dc57bed012 |
comparison
equal
deleted
inserted
replaced
| 684:a9eef98e5038 | 685:2e7920b0b4d9 |
|---|---|
| 1085 raise NameError("Filter %r not found" % (name, )) | 1085 raise NameError("Filter %r not found" % (name, )) |
| 1086 else: | 1086 else: |
| 1087 value = filterfn(self, value) | 1087 value = filterfn(self, value) |
| 1088 return value | 1088 return value |
| 1089 | 1089 |
| 1090 def jailed(self, rootpath=None, root=None, | 1090 def jailed(self, rootpath=None, root=None, bind_root=True): |
| 1091 bind_root=True, resolve_ref=True): | |
| 1092 """Return a "jailed" configuration of the current configuration. | 1091 """Return a "jailed" configuration of the current configuration. |
| 1093 | 1092 |
| 1094 :param rootpath: a sequence of strings (or objects) that shall | 1093 :param rootpath: a sequence of strings (or objects) that shall |
| 1095 emcompass the chroot-like jail of the returned | 1094 emcompass the chroot-like jail of the returned |
| 1096 configuration | 1095 configuration |
| 1099 the chroot-like jail of the returned configuration | 1098 the chroot-like jail of the returned configuration |
| 1100 :param bool bind_root: if you do a :meth:`~.rebind` just after | 1099 :param bool bind_root: if you do a :meth:`~.rebind` just after |
| 1101 creation of a jailed config you can set | 1100 creation of a jailed config you can set |
| 1102 `bind_root` to `False`; otherwise use | 1101 `bind_root` to `False`; otherwise use |
| 1103 the default | 1102 the default |
| 1104 :param bool resolve_ref: If `True` then the jail's root is checked | |
| 1105 whether it is a reference. If it is a | |
| 1106 reference then the jail is effectively rooted | |
| 1107 where the reference points to. This process | |
| 1108 is done recursively. | |
| 1109 :return: a jailed (aka restricted) configuration | 1103 :return: a jailed (aka restricted) configuration |
| 1110 :rtype: _JailedConfiguration | 1104 :rtype: _JailedConfiguration |
| 1111 | 1105 |
| 1112 Exactly one of `rootpath` or `root` must be given. | 1106 Exactly one of `rootpath` or `root` must be given. |
| 1113 | 1107 |
| 1123 varns, varname = _split_ns(root) | 1117 varns, varname = _split_ns(root) |
| 1124 if varns: | 1118 if varns: |
| 1125 raise ValueError( | 1119 raise ValueError( |
| 1126 "jailed configurations do not support namespaces") | 1120 "jailed configurations do not support namespaces") |
| 1127 rootpath = pathstr2path(root) | 1121 rootpath = pathstr2path(root) |
| 1128 if resolve_ref: | 1122 # if resolve_ref: |
| 1129 while True: | 1123 # while True: |
| 1130 target = self.getvarl(*rootpath) | 1124 # target = self.getvarl(*rootpath) |
| 1131 target_uri = self.try_get_reference_uri(target) | 1125 # target_uri = self.try_get_reference_uri(target) |
| 1132 if target_uri is None: | 1126 # if target_uri is None: |
| 1133 break | 1127 # break |
| 1134 rootpath = pathstr2path(target_uri) | 1128 # rootpath = pathstr2path(target_uri) |
| 1135 jc = _JailedConfiguration(*rootpath) | 1129 jc = _JailedConfiguration(*rootpath) |
| 1136 if bind_root: | 1130 if bind_root: |
| 1137 jc.rebind(self) | 1131 jc.rebind(self) |
| 1138 return jc | 1132 return jc |
| 1139 | 1133 |
| 1359 | 1353 |
| 1360 def __bool__(self): | 1354 def __bool__(self): |
| 1361 """Map- and list-style evaluation in boolean context""" | 1355 """Map- and list-style evaluation in boolean context""" |
| 1362 return bool(self._base.getvarl_s(*self._path)) | 1356 return bool(self._base.getvarl_s(*self._path)) |
| 1363 | 1357 |
| 1364 def jailed(self, rootpath=None, root=None, | 1358 def jailed(self, rootpath=None, root=None, bind_root=True): |
| 1365 bind_root=True, resolve_ref=True): | |
| 1366 """Return a "jailed" configuration that effectively is a | 1359 """Return a "jailed" configuration that effectively is a |
| 1367 subjail of the current jail | 1360 subjail of the current jail |
| 1368 | 1361 |
| 1369 For a more complete description see :meth:`.Configuration.jailed`. | 1362 For a more complete description see :meth:`.Configuration.jailed`. |
| 1370 | 1363 |
| 1384 rootpath = pathstr2path(varname) | 1377 rootpath = pathstr2path(varname) |
| 1385 if self._path: | 1378 if self._path: |
| 1386 new_rootpath = self._path + tuple(rootpath) | 1379 new_rootpath = self._path + tuple(rootpath) |
| 1387 else: | 1380 else: |
| 1388 new_rootpath = tuple(rootpath) | 1381 new_rootpath = tuple(rootpath) |
| 1389 if resolve_ref: | 1382 # if resolve_ref: |
| 1390 while True: | 1383 # while True: |
| 1391 target = self._base.getvarl(*new_rootpath) | 1384 # target = self._base.getvarl(*new_rootpath) |
| 1392 target_uri = self._base.try_get_reference_uri(target) | 1385 # target_uri = self._base.try_get_reference_uri(target) |
| 1393 if target_uri is None: | 1386 # if target_uri is None: |
| 1394 break | 1387 # break |
| 1395 new_rootpath = pathstr2path(target_uri) | 1388 # new_rootpath = pathstr2path(target_uri) |
| 1396 sjc = _JailedConfiguration(*new_rootpath) | 1389 sjc = _JailedConfiguration(*new_rootpath) |
| 1397 if bind_root: | 1390 if bind_root: |
| 1398 sjc.rebind(self._base) | 1391 sjc.rebind(self._base) |
| 1399 return sjc | 1392 return sjc |
| 1400 | 1393 |
