Closed raratiru closed 4 years ago
I'm not sure how to replicate this. Could you provide the input, the script to create the output, and the expected output? I tried, but I wasn't sure how you got from your JSON root logger to your ini config file, and what you wanted ConfigObj to do.
Sorry, I was rather sloppy.
This is the code that reproduces the issue.
With Python-3.8.2 and configobj-5.0.6:
conf.ini
from configobj import ConfigObj
config = ConfigObj() config.filename = "conf.ini" config.indent_type = " " config.interpolation = False
config["LOGGING"] = { "version": 1, "disable_existing_loggers": False, "formatters": {}, "filters": {}, "handlers": {}, "loggers": { "": {}, # The root logger "django": {}, "celery": {}, }, }
config.write()
* Inspect `conf.ini` (as expected):
```bash
$ cat conf.ini
[LOGGING]
version = 1
disable_existing_loggers = False
[[formatters]]
[[filters]]
[[handlers]]
[[loggers]]
[[[""]]] # Line 8
[[[django]]]
[[[celery]]]
conf.ini
:
from configobj import ConfigObj
load_config = ConfigObj("conf.ini")
Traceback (most recent call last):
File "/home/.virtualenvs/pod/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3331, in run_code exec(code_obj, self.user_global_ns, self.user_ns)
File "
File "/home/.virtualenvs/pod/lib/python3.8/site-packages/configobj.py", line 1229, in init self._load(infile, configspec)
File "/home/.virtualenvs/pod/lib/python3.8/site-packages/configobj.py", line 1318, in _load raise error
File "
Issue
-------
* I expected `ConfigObj` to load the `conf.ini` file that has the correct contents, created by `ConfigObj`, but instead it raises this error.
I don't think the two issues are related. Tracing the issue, I think it comes from the parsing section. See the _sectionmarker
regex in __init__.py
(line 1062):
_sectionmarker = re.compile(r'''^
(\s*) # 1: indentation
((?:\[\s*)+) # 2: section marker open
( # 3: section name open
(?:"\s*\S.*?\s*")| # at least one non-space with double quotes
(?:'\s*\S.*?\s*')| # at least one non-space with single quotes
(?:[^'"\s].*?) # at least one non-space unquoted
) # section name close
((?:\s*\])+) # 4: section marker close
(\s*(?:\#.*)?)? # 5: optional comment
To be marked a section, a section heading must contain at least a non-space character, either surrounded by double quotes, single quotes, or unquoted. You could try adding a case in the section name
portion of the regex that fits your needs (two double quotes). Make sure it goes well with the rest of the parsing though.
Thank you!
Since this is an intended behavior, I can programmatically cope with it when initializing the config object.
In my Django configuration I define a root logger:
When I :
the result is like that:
When I
ConfigObj('conf.ini')
I get the error:Is it a bug? If not, how can I define the root logger?