diff options
author | grabner <pjg.github@ubergrabner.net> | 2016-12-14 14:15:23 -0500 |
---|---|---|
committer | grabner <pjg.github@ubergrabner.net> | 2016-12-14 14:15:23 -0500 |
commit | 8f794ca16f1c4b0f4149a6194ea80acba712214c (patch) | |
tree | d0aaf4a4092e0cabd48e4a34b95aec39fdfa87de | |
parent | 17eeaa57156694aaad1e1f536204a1c58920dcb3 (diff) | |
download | iniherit-8f794ca16f1c4b0f4149a6194ea80acba712214c.tar.gz |
added documentation re %(SUPER)s
-rw-r--r-- | README.rst | 58 |
1 files changed, 57 insertions, 1 deletions
@@ -10,7 +10,9 @@ inheritance themselves, then the `iniherit` package is a better alternative. Oh, `iniherit` also adds support for environment variable expansion -via ``%(ENV:VARNAME)s``. +via ``%(ENV:VARNAME)s``. This really shouldn't be here, but since +`iniherit` supports the ``%(SUPER)s`` expansion, it was "just too +easy" to add envvar expansion as well... Project Info @@ -170,6 +172,54 @@ Substitutions The `iniherit` package adds the following additional substitution options: +* ``%(SUPER[:-DEFAULT])s`` + + Evaluates to the inherited value of the current section/key value. + If the inherited INI does not specify a value and no default is + provided, then an `InterpolationMissingSuperError` is raised. The + "inherited value" is evaluated depth-first. Note that "SUPER" must + be all upper case. + + For example, given the following INI files: + + .. code:: ini + + # base.ini + [loggers] + keys = root, app + + + .. code:: ini + + # config.ini + [DEFAULT] + %inherit = base.ini + [loggers] + keys = %(SUPER)s, auth + wdef = %(SUPER:-more)s or less + nada = %(SUPER)s boom! + + + Then the following Python will result: + + .. code:: python + + import iniherit + iniherit.mixin.install_globally() + import ConfigParser + cfg = ConfigParser.SafeConfigParser() + cfg.read('config.ini') + + cfg.get('loggers', 'keys') # ==> 'root, app, auth' + cfg.get('loggers', 'wdef') # ==> 'more or less' + cfg.get('loggers', 'nada') # ==> raises InterpolationMissingSuperError + + + As with standard interpolation errors, the + InterpolationMissingSuperError exception is only raised if/when the + value is requested from the config (with `raw` set to falsy). + + * ``%(ENV:VARNAME[:-DEFAULT])s`` Evaluates to the value of the environment variable name "VARNAME". @@ -187,6 +237,7 @@ options: rdir = %(ENV:RDIR:-/var/run)s nada = %(ENV:RDIR)s + Then the following Python will result: .. code:: python @@ -206,6 +257,11 @@ options: cfg.get('section', 'nada') # ==> raises InterpolationMissingEnvError + As with standard interpolation errors, the + InterpolationMissingEnvError exception is only raised if/when the + value is requested from the config (with `raw` set to falsy). + + Gotchas ======= |