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 can't parse MySQL style config
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: dveeden, lukasz.langa, martin.panter, r.david.murray
Priority: normal Keywords:

Created on 2014-04-22 15:27 by dveeden, last changed 2022-04-11 14:58 by admin.

Files
File name Uploaded Description Edit
demo.py dveeden, 2014-04-22 15:27 Quick-n-dirty example
Messages (3)
msg217012 - (view) Author: Daniël van Eeden (dveeden) Date: 2014-04-22 15:27
With Python 2.7 the ConfigParser was enriched with the allow_no_value option which resulted in a much more usable configparser for MySQL configs.

It can now parse configs like this:
[mysqld]
log_bin
innodb_file_per_table
innodb_io_capacity=800

However it can't parse this config:
[mysqld]
log_bin
innodb_file_per_table
innodb_io_capacity=800
replicate-do-db="test1"
replicate-do-db="test2"

A comma separated config might have been better, but that's not the case with many MySQL config (and probably doesn't even work for this option).

From http://dev.mysql.com/doc/refman/5.6/en/replication-options-slave.html#option_mysqld_replicate-do-db
"To specify more than one database, use this option multiple times, once for each database"


The dict/orderedDict which is used by configparser doesn't easlily allow to store a config like this.

The MySQL config file is used as an example in the documentation:
https://docs.python.org/3/library/configparser.html#customizing-parser-behaviour

This could be solved by having a list of values if the key exists more than once.

Python 3 improves this a bit by giving a DuplicateOptionError by default.
msg218473 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-05-13 16:34
The data structure you are asking for bears a resemblance to the data structure used by the email package to record message headers.  Email uses a list with a dict-like API cobbled together on top.  The difference with your suggestion is that email also needs to record the order of the headers, so just having a list-of-values for each key isn't adequate.  Any bets on whether or not we eventually run across a use of .ini format where the exact order of the duplicated keys within the whole list of keys matters? :)

With two use cases that could be served by the same data structure in the stdlib, I wonder if it is worth actually building the abstract data type.  Probably not, but I thought I'd raise the possibility anyway :)
msg227748 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2014-09-28 02:12
See Issue 12662 for a related earlier proposal. (Although the multimap proposal here sounds better than concatenating the values as proposed there.)
History
Date User Action Args
2022-04-11 14:58:02adminsetgithub: 65528
2014-09-28 02:12:09martin.pantersetnosy: + martin.panter
messages: + msg227748
2014-05-13 16:34:33r.david.murraysetversions: + Python 3.5, - Python 3.4
nosy: + r.david.murray

messages: + msg218473

type: enhancement
2014-04-22 17:52:03ned.deilysetnosy: + lukasz.langa
2014-04-22 15:27:33dveedencreate