Mercurial > hgrepos > Python > libs > ConfigMix
comparison docs/introduction.rst @ 426:84d4f82ffe59
Docs: more on jails and sub-jails
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Tue, 07 Dec 2021 09:38:33 +0100 |
| parents | 88d8de9310af |
| children | 6102b767fc69 |
comparison
equal
deleted
inserted
replaced
| 425:88d8de9310af | 426:84d4f82ffe59 |
|---|---|
| 562 Usage example:: | 562 Usage example:: |
| 563 | 563 |
| 564 import configmix | 564 import configmix |
| 565 | 565 |
| 566 config = configmix.load("conf10.py") | 566 config = configmix.load("conf10.py") |
| 567 assert not config.is_jail | |
| 567 value = config.getvar_s("tree1.tree2.key4") | 568 value = config.getvar_s("tree1.tree2.key4") |
| 568 | 569 |
| 569 jailed_config1 = config.jailed(rootpath="tree1.tree2") | 570 jailed_config1 = config.jailed(rootpath="tree1.tree2") |
| 571 assert jailed_config1.is_jail | |
| 572 assert jailed_config1.base is config | |
| 570 jvalue1 = jailed_config1.getvar_s("key4") | 573 jvalue1 = jailed_config1.getvar_s("key4") |
| 571 | 574 |
| 572 jailed_config2 = config.jailed(root=("tree1", "tree2")) | 575 jailed_config2 = config.jailed(root=("tree1", "tree2")) |
| 576 assert jailed_config2.is_jail | |
| 577 assert jailed_config2.base is config | |
| 573 jvalue2 = jailed_config.getvarl_s("key4") | 578 jvalue2 = jailed_config.getvarl_s("key4") |
| 574 | 579 |
| 575 assert value == jvalue1 == jvalue2 == "get this as `tree1.tree2.key4'" | 580 assert value == jvalue1 == jvalue2 == "get this as `tree1.tree2.key4'" |
| 576 | 581 |
| 577 `jvalue1` and `jvalue2` (and `value`) yield the very same value | 582 `jvalue1` and `jvalue2` (and `value`) yield the very same value |
| 580 All access methods in a jailed configuration automatically prepend the | 585 All access methods in a jailed configuration automatically prepend the |
| 581 given `root path` in order to get the effective key into the base | 586 given `root path` in order to get the effective key into the base |
| 582 configuration. | 587 configuration. |
| 583 | 588 |
| 584 It is possible to get a jailed configuration from an already jailed | 589 It is possible to get a jailed configuration from an already jailed |
| 585 configuration:: | 590 configuration. This sub-jail inherits the unjailed base configuration from |
| 591 the jailed configuration by default. | |
| 592 | |
| 593 :: | |
| 586 | 594 |
| 587 import configmix | 595 import configmix |
| 588 | 596 |
| 589 config = configmix.load("conf10.py") | 597 config = configmix.load("conf10.py") |
| 598 assert not config.is_jail | |
| 590 value = config.getvar_s("tree1.tree2.key4") | 599 value = config.getvar_s("tree1.tree2.key4") |
| 591 | 600 |
| 592 jailed_config1 = config.jailed(rootpath="tree1") | 601 jailed_config1 = config.jailed(rootpath="tree1") |
| 602 assert jailed_config1.is_jail | |
| 603 assert jailed_config2.base is config | |
| 593 | 604 |
| 594 jailed_config2 = jailed_config2.jailed(rootpath="tree2") | 605 jailed_config2 = jailed_config2.jailed(rootpath="tree2") |
| 606 assert jailed_config2.is_jail | |
| 607 assert jailed_config2.base is config | |
| 595 jvalue2 = jailed_config.getvarl_s("key4") | 608 jvalue2 = jailed_config.getvarl_s("key4") |
| 596 | 609 |
| 597 assert value == jvalue2 == "get this as `tree1.tree2.key4'" | 610 assert value == jvalue2 == "get this as `tree1.tree2.key4'" |
| 598 | 611 |
| 599 .. note:: A jailed configuration holds a strong reference to the unjailed | 612 .. note:: A jailed configuration holds a strong reference to the unjailed |
