You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
configparser can't parse MySQL style config #65528
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 :)
Activity
dveeden commentedon Apr 22, 2014
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.
bitdancer commentedon May 13, 2014
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 :)
vadmium commentedon Sep 28, 2014
See bpo-12662 for a related earlier proposal. (Although the multimap proposal here sounds better than concatenating the values as proposed there.)
serhiy-storchaka commentedon Jul 30, 2023
See also #75709 and #107430.