This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ConfigParser allows "get(*, raw=True), but no corresponding "set(*, raw=True)"
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 3.3, Python 3.4
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: lukasz.langa, metagriffin
Priority: normal Keywords: patch

Created on 2014-04-16 19:00 by metagriffin, last changed 2022-04-11 14:58 by admin.

Files
File name Uploaded Description Edit
issue-21265.patch metagriffin, 2014-04-16 19:13 fixes the issue by adding `raw` parameter to *ConfigParser.set() methods
Messages (1)
msg216554 - (view) Author: metagriffin (metagriffin) * Date: 2014-04-16 19:00
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)
```
History
Date User Action Args
2022-04-11 14:58:02adminsetgithub: 65464
2014-04-16 20:32:41ned.deilysetnosy: + lukasz.langa
2014-04-16 19:13:44metagriffinsetfiles: + issue-21265.patch
keywords: + patch
2014-04-16 19:00:24metagriffincreate