Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/config.py @ 762:3eb2c451026b
Implement Configuration.copy_new_config_without()
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 07 Dec 2023 08:43:04 +0100 |
| parents | cabd1046d95f |
| children |
comparison
equal
deleted
inserted
replaced
| 761:72d317c255d4 | 762:3eb2c451026b |
|---|---|
| 1182 return self.jailed(rootpath=rootpath, root=root).iter_jailed() | 1182 return self.jailed(rootpath=rootpath, root=root).iter_jailed() |
| 1183 | 1183 |
| 1184 def extract_new_config(self, *path, **kwds): | 1184 def extract_new_config(self, *path, **kwds): |
| 1185 """Get the value at `path` and make a new :class:`~.Configuration` from it. | 1185 """Get the value at `path` and make a new :class:`~.Configuration` from it. |
| 1186 | 1186 |
| 1187 The new config is a deepcopy and completely independent of the source | 1187 The new configuration is a deepcopy and completely independent |
| 1188 configuration. | 1188 of the source configuration. |
| 1189 | 1189 |
| 1190 """ | 1190 """ |
| 1191 return self.__class__(copy.deepcopy(self.getvarl(*path, **kwds))) | 1191 return self.__class__(copy.deepcopy(self.getvarl(*path, **kwds))) |
| 1192 | |
| 1193 def copy_new_config_without(self, *path): | |
| 1194 """Copy the current configuration but leave out the value at key | |
| 1195 `path`. | |
| 1196 | |
| 1197 The new configuration is a deepcopy and completely independent | |
| 1198 of the source configuration. | |
| 1199 | |
| 1200 .. note:: Currently only a "simple" `path` with length 1 is | |
| 1201 supported. References are not supported. | |
| 1202 | |
| 1203 """ | |
| 1204 # | |
| 1205 # Manual copy: avoid direct and indirect calls to self.__getitem__ | |
| 1206 # because it interpolates. | |
| 1207 # | |
| 1208 if path: | |
| 1209 if len(path) != 1: | |
| 1210 raise ValueError("Only a `path' with length 1 is supported") | |
| 1211 nc = {} | |
| 1212 for i in self: | |
| 1213 if (not path) or (i != path[0]): | |
| 1214 nc[i] = copy.deepcopy(self.getvarl(i)) | |
| 1215 return self.__class__(nc) | |
| 1192 | 1216 |
| 1193 | 1217 |
| 1194 class _JailedConfiguration(CoercingMethodsMixin): | 1218 class _JailedConfiguration(CoercingMethodsMixin): |
| 1195 | 1219 |
| 1196 """A jailed and restricted variant of :class:`Configuration`. | 1220 """A jailed and restricted variant of :class:`Configuration`. |
