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
logging.configcfg protocol rejects non-alphanumeric names, contrary to the documentation #103384
In logging.config, when using the cfg protocol, names with spaces or non-alphanumeric characters (e.g. cfg://nested[prop with spaces]) raise a ValueError contrary to what is stated in the documentation.
The documentation states that one can use the bracket notation:
The latter form only needs to be used if the key contains spaces or non-alphanumeric characters.
This does not work however:
fromlogging.configimportBaseConfiguratorconfig= {'nested': {'prop': 1, 'prop with spaces': 2}} # Create a simple logging configbc=BaseConfigurator(config)
bc.cfg_convert('nested[prop]') # returns 1 (expected)bc.cfg_convert('nested[prop with spaces]') # Raises ValueErrorTraceback (mostrecentcalllast):
File"<stdin>", line1, in<module>File"/home/tomas/dev/cpython/Lib/logging/config.py", line433, incfg_convertraiseValueError('Unable to convert 'ValueError: Unabletoconvert'nested[prop with spaces]'at'[prop with spaces]'
ValueError is also raised for any non-alphanumeric sequence:
bc.cfg_convert('nested[!?]') # Raises
The culprit is the regex pattern (BaseConfigurator.INDEX_PATTERN) which is used for matching the bracket contents: ^\[\s*(\w+)\s*\]\s*.
This only matches alphanumeric characters. Simply changing this to ^\[([^\[\]]*)\]\s* would give us the behavior described in the docs.
Activity
Merge branch 'pythongh-103384' of https://github.com/dhuadaar/cpython …
Merge branch 'main' into pythongh-103384
Merge branch 'pythongh-103384' of https://github.com/dhuadaar/cpython …
Merge branch 'main' into pythongh-103384
Merge branch 'main' into pythongh-103384
Merge branch 'main' into pythongh-103384
Merge branch 'main' into pythongh-103384
Merge branch 'main' into pythongh-103384
gh-103384: Generalize the regex pattern `BaseConfigurator.INDEX_PATTE…