[issue29333] ConfigParser calls Interpolation.before_read after reading

2017-01-25 Thread Gereon Kaiping

Changes by Gereon Kaiping <gereon.kaiping+pyt...@gmail.com>:


--
components: +Library (Lib)
type:  -> behavior
versions: +Python 3.5, Python 3.6

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29333>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29333] ConfigParser calls Interpolation.before_read after reading

2017-01-20 Thread Gereon Kaiping

New submission from Gereon Kaiping:

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.)

--
files: earlyinterpolation.py
messages: 285902
nosy: Anaphory
priority: normal
severity: normal
status: open
title: ConfigParser calls Interpolation.before_read after reading
Added file: http://bugs.python.org/file46355/earlyinterpolation.py

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29333>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26537] ConfigParser has optoinxform, but not sectionxform

2016-03-10 Thread Gereon Kaiping

New submission from Gereon Kaiping:

configparser.ConfigParser (resp. ConfigParser.RawConfigParser for python2) has 
a optionxform function which converts the option names in a section to lower 
case by default.

A similar function for section titles would be expected (cf. 
https://github.com/lmaurits/BEASTling/issues/46#issuecomment-195131900), but it 
does not exist.

If ConfigParser called such a function (reasonably named sectionxform), which 
would default to None (or the identity function) for backward compatibility, 
that would be nice and consistent.

--
components: Library (Lib)
messages: 261543
nosy: Anaphory
priority: normal
severity: normal
status: open
title: ConfigParser has optoinxform, but not sectionxform
versions: Python 2.7, Python 3.5, Python 3.6

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26537>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com