New submission from metagriffin:

the ConfigParser classes allow option values with interpolation syntax 
violations to be loaded from an INI file, and to be extracted as long as the 
`raw` parameter is set to True in the get*() methods. the following code 
demonstrates this asymmetry:

``` python
import configparser
import io

buf = io.StringIO('[time]\nfmt = %H:%M:%S\n')
cfg = configparser.SafeConfigParser()
cfg.readfp(buf)

# prove that "%H:%M:%S" is valid in a SafeConfigParser:
assert cfg.get('time', 'fmt', raw=True) == '%H:%M:%S'

# but it cannot be set:
cfg.set('time', 'fmt', '%I:%M %p')
# => raises configparser.InterpolationSyntaxError: '%' must be followed by '%' 
or '(', found: '%I:%M %p'
```

the intuitive resolution to this asymmetry is to add a `raw` parameter to 
set(), which would allow:

``` python
cfg.set('time', 'fmt', '%I:%M %p', raw=True)
assert cfg.get('time', 'fmt', raw=True) == '%I:%M %p'
```

note that this is a new problem to python 3, which added the following lines to 
the ConfigParser.set() method:

``` python
if value:
    value = self._interpolation.before_set(self, section, option,
                                            value)
```

----------
components: Library (Lib)
messages: 216554
nosy: metagriffin
priority: normal
severity: normal
status: open
title: ConfigParser allows "get(*, raw=True), but no corresponding "set(*, 
raw=True)"
type: enhancement
versions: Python 3.1, Python 3.2, Python 3.3, Python 3.4

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

Reply via email to