Skip to content

configparser can't parse MySQL style config #65528

Open

Description

@dveeden
mannequin
BPO 21329
Nosy @bitdancer, @ambv, @vadmium
Files
  • demo.py: Quick-n-dirty example
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2014-04-22.15:27:33.250>
    labels = ['type-feature', 'library']
    title = "configparser can't parse MySQL style config"
    updated_at = <Date 2014-09-28.02:12:09.576>
    user = 'https://bugs.python.org/dveeden'

    bugs.python.org fields:

    activity = <Date 2014-09-28.02:12:09.576>
    actor = 'martin.panter'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2014-04-22.15:27:33.250>
    creator = 'dveeden'
    dependencies = []
    files = ['35001']
    hgrepos = []
    issue_num = 21329
    keywords = []
    message_count = 3.0
    messages = ['217012', '218473', '227748']
    nosy_count = 4.0
    nosy_names = ['r.david.murray', 'lukasz.langa', 'martin.panter', 'dveeden']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue21329'
    versions = ['Python 3.5']

    Activity

    1. dveeden commented on Apr 22, 2014

      dveedenmannequin
      MannequinAuthor

      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.

    2. added
      stdlib
      on Apr 22, 2014
    3. bitdancer commented on May 13, 2014

      @bitdancer
      Member

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

    4. added
      type-feature
      on May 13, 2014
    5. vadmium commented on Sep 28, 2014

      @vadmium
      Member

      See bpo-12662 for a related earlier proposal. (Although the multimap proposal here sounds better than concatenating the values as proposed there.)

    6. transferred this issue fromon Apr 10, 2022
    7. serhiy-storchaka commented on Jul 30, 2023

      @serhiy-storchaka
      Member

      See also #75709 and #107430.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      stdlibtype-feature

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions