Read a config file. *list_values* set to `True` is the default behavior of ConfigObj. Disabling it causes values to not be parsed for lists, (e.g. 'a,b,c' -> ['a', 'b', 'c']. Additionally, the config values are not unquoted. We are disabling list_values when reading MySQL config fil
(f: str | IO[str], list_values: bool = True)
| 24 | |
| 25 | |
| 26 | def read_config_file(f: str | IO[str], list_values: bool = True) -> ConfigObj | None: |
| 27 | """Read a config file. |
| 28 | |
| 29 | *list_values* set to `True` is the default behavior of ConfigObj. |
| 30 | Disabling it causes values to not be parsed for lists, |
| 31 | (e.g. 'a,b,c' -> ['a', 'b', 'c']. Additionally, the config values are |
| 32 | not unquoted. We are disabling list_values when reading MySQL config files |
| 33 | so we can correctly interpret commas in passwords. |
| 34 | |
| 35 | """ |
| 36 | |
| 37 | if isinstance(f, str): |
| 38 | f = os.path.expanduser(f) |
| 39 | |
| 40 | try: |
| 41 | config = ConfigObj(f, interpolation=False, encoding="utf8", list_values=list_values) |
| 42 | except ConfigObjError as e: |
| 43 | log(logger, logging.WARNING, "Unable to parse line {0} of config file '{1}'.".format(e.line_number, f)) |
| 44 | log(logger, logging.WARNING, "Using successfully parsed config values.") |
| 45 | return e.config |
| 46 | except (IOError, OSError) as e: |
| 47 | log(logger, logging.WARNING, "You don't have permission to read config file '{0}'.".format(e.filename)) |
| 48 | return None |
| 49 | |
| 50 | return config |
| 51 | |
| 52 | |
| 53 | def read_config_files( |