Author Anaphory
Recipients Anaphory
Date 2017-01-20.11:50:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1484913036.08.0.781257093151.issue29333@psf.upfronthosting.co.za>
In-reply-to
Content
In its current implementation, `ConfigParser` calls its Interpolation's `before_read` method in the very last step of `_read`, when all properties have already been overwritten by their new uninterpolated values.

I am developing a program with modular config files: It is possible to supply several configuration files on the command line, and they are all fed through the `.read` method.

Now it would be amazing to use `read` time interpolation instead of `get` time interpolation to construct things like

outputfilename = %(outputfilename)s_extension_from_this_ini_module

By looking at the `Interpolation` class, it seems that behaviour like this should be supported by supplying a `before_read` as follows.

    def before_read(self, parser, section, option, value):
        L = []
        interpolations = parser[section]
        self._interpolate_some(
            parser, option, L, value, section, interpolations, 1)
        return ''.join(L)

However, this is not possible, because `before_read` is only called *after* all values in the config file have been read and all old values in the ConfigParser object have been overridden.

The attached file contains a subclass of `BasicInterpolation` and a subclass of `ConfigParser` which in concert allow me to write recursive property definitions as given above.

The downside of this change is that (a) interpolation values can't be defined *after* they are used any more, and (b) it is not possible to hack this parser to accept multi-line option names as interpolations. (To me personally, both of these don't sound like useful features to begin with.)
History
Date User Action Args
2017-01-20 11:50:36Anaphorysetrecipients: + Anaphory
2017-01-20 11:50:36Anaphorysetmessageid: <1484913036.08.0.781257093151.issue29333@psf.upfronthosting.co.za>
2017-01-20 11:50:36Anaphorylinkissue29333 messages
2017-01-20 11:50:35Anaphorycreate