Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9d5d420
fix regex for INDEX_PATTERN in BaseConfigurator
dhuadaar Apr 9, 2023
bdba91e
add tests
dhuadaar Apr 9, 2023
8c956ca
📜🤖 Added by blurb_it.
blurb-it[bot] Apr 9, 2023
ca9f0c3
update tests
dhuadaar Apr 9, 2023
fba5e08
Merge branch 'gh-103384' of https://github.com/dhuadaar/cpython into …
dhuadaar Apr 9, 2023
f5ce47c
Merge branch 'main' into gh-103384
dhuadaar Apr 9, 2023
785fb1d
fix tests
dhuadaar Apr 9, 2023
4f84c91
Merge branch 'gh-103384' of https://github.com/dhuadaar/cpython into …
dhuadaar Apr 9, 2023
96c0063
improve test cases for BaseConfigurator
dhuadaar Apr 9, 2023
9fe33dd
add tests for nested dict - BaseConfigurator
dhuadaar Apr 9, 2023
e5075e5
fix whitespaces in test_logging.py
dhuadaar Apr 9, 2023
77d486e
Update Misc/NEWS.d/next/Library/2023-04-09-05-30-41.gh-issue-103384.z…
dhuadaar Apr 13, 2023
d22e941
fix regex for INDEX_PATTERN in BaseConfigurator
dhuadaar Apr 13, 2023
92af547
add tests
dhuadaar Apr 13, 2023
a5a2fc7
fix NEWS.d entry for the commit as compliant with sphinx check
dhuadaar Apr 13, 2023
1553667
Add details about cfg_convert into logging.config docs. and are not…
dhuadaar Apr 13, 2023
3fffaa4
fix whitespace in test_logging.py
dhuadaar Apr 13, 2023
66893dc
Merge branch 'main' into gh-103384
dhuadaar Apr 13, 2023
b9af982
Merge branch 'main' into gh-103384
dhuadaar Apr 16, 2023
5cd95c4
Merge branch 'main' into gh-103384
AlexWaygood May 2, 2023
d80d9cf
Merge branch 'main' into gh-103384
erlend-aasland Aug 4, 2023
a16f2eb
Merge branch 'main' into gh-103384
dhuadaar Aug 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Doc/library/logging.config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,8 @@ resolve to ``'[email protected]'`` and the string
``'[email protected]'``. The ``subject`` value could be accessed
using either ``'cfg://handlers.email.subject'`` or, equivalently,
``'cfg://handlers.email[subject]'``. The latter form only needs to be
used if the key contains spaces or non-alphanumeric characters. If an
used if the key contains spaces or non-alphanumeric characters. Please note
that the characters ``[`` and ``]`` are not allowed in the keys. If an
index value consists only of decimal digits, access will be attempted
using the corresponding integer value, falling back to the string
value if needed.
Expand Down
2 changes: 1 addition & 1 deletion Lib/logging/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ class BaseConfigurator(object):

WORD_PATTERN = re.compile(r'^\s*(\w+)\s*')
DOT_PATTERN = re.compile(r'^\.\s*(\w+)\s*')
INDEX_PATTERN = re.compile(r'^\[\s*(\w+)\s*\]\s*')
INDEX_PATTERN = re.compile(r'^\[([^\[\]]*)\]\s*')
DIGIT_PATTERN = re.compile(r'^\d+$')

value_converters = {
Expand Down
48 changes: 47 additions & 1 deletion Lib/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -3662,7 +3662,28 @@ def test_baseconfig(self):
d = {
'atuple': (1, 2, 3),
'alist': ['a', 'b', 'c'],
'adict': {'d': 'e', 'f': 3 },
'adict': {
'd': 'e', 'f': 3 ,
'alpha numeric 1 with spaces' : 5,
'aplha numeric 1 %( - © ©ß¯' : 9,
'alpha numeric ] 1 with spaces' : 15,
'aplha ]] numeric 1 %( - © ©ß¯]' : 19,
' aplha [ numeric 1 %( - © ©ß¯] ' : 11,
' aplha ' : 32,
'' : 10,
'nest4' : {
'd': 'e', 'f': 3 ,
'alpha numeric 1 with spaces' : 5,
'aplha numeric 1 %( - © ©ß¯' : 9,
'' : 10,
'somelist' : ('g', ('h', 'i'), 'j'),
'somedict' : {
'a' : 1,
'a with 1 and space' : 3,
'a with ( and space' : 4,
}
}
},
'nest1': ('g', ('h', 'i'), 'j'),
'nest2': ['k', ['l', 'm'], 'n'],
'nest3': ['o', 'cfg://alist', 'p'],
Expand All @@ -3674,11 +3695,36 @@ def test_baseconfig(self):
self.assertEqual(bc.convert('cfg://nest2[1][1]'), 'm')
self.assertEqual(bc.convert('cfg://adict.d'), 'e')
self.assertEqual(bc.convert('cfg://adict[f]'), 3)
self.assertEqual(bc.convert('cfg://adict[alpha numeric 1 with spaces]'), 5)
self.assertEqual(bc.convert('cfg://adict[aplha numeric 1 %( - © ©ß¯]'), 9)
self.assertEqual(bc.convert('cfg://adict[]'), 10)
self.assertEqual(bc.convert('cfg://adict.nest4.d'), 'e')
self.assertEqual(bc.convert('cfg://adict.nest4[d]'), 'e')
self.assertEqual(bc.convert('cfg://adict[nest4].d'), 'e')
self.assertEqual(bc.convert('cfg://adict[nest4][f]'), 3)
self.assertEqual(bc.convert('cfg://adict[nest4][alpha numeric 1 with spaces]'), 5)
self.assertEqual(bc.convert('cfg://adict[nest4][aplha numeric 1 %( - © ©ß¯]'), 9)
self.assertEqual(bc.convert('cfg://adict[nest4][]'), 10)
self.assertEqual(bc.convert('cfg://adict[nest4][somelist][0]'), 'g')
self.assertEqual(bc.convert('cfg://adict[nest4][somelist][1][0]'), 'h')
self.assertEqual(bc.convert('cfg://adict[nest4][somelist][1][1]'), 'i')
self.assertEqual(bc.convert('cfg://adict[nest4][somelist][2]'), 'j')
self.assertEqual(bc.convert('cfg://adict[nest4].somedict.a'), 1)
self.assertEqual(bc.convert('cfg://adict[nest4].somedict[a]'), 1)
self.assertEqual(bc.convert('cfg://adict[nest4].somedict[a with 1 and space]'), 3)
self.assertEqual(bc.convert('cfg://adict[nest4].somedict[a with ( and space]'), 4)
self.assertEqual(bc.convert('cfg://adict.nest4.somelist[1][1]'), 'i')
self.assertEqual(bc.convert('cfg://adict.nest4.somelist[2]'), 'j')
self.assertEqual(bc.convert('cfg://adict.nest4.somedict.a'), 1)
self.assertEqual(bc.convert('cfg://adict.nest4.somedict[a]'), 1)
v = bc.convert('cfg://nest3')
self.assertEqual(v.pop(1), ['a', 'b', 'c'])
self.assertRaises(KeyError, bc.convert, 'cfg://nosuch')
self.assertRaises(ValueError, bc.convert, 'cfg://!')
self.assertRaises(KeyError, bc.convert, 'cfg://adict[2]')
self.assertRaises(KeyError, bc.convert, 'cfg://adict[alpha numeric ] 1 with spaces]')
self.assertRaises(ValueError, bc.convert, 'cfg://adict[ aplha ]] numeric 1 %( - © ©ß¯] ]')
self.assertRaises(ValueError, bc.convert, 'cfg://adict[ aplha [ numeric 1 %( - © ©ß¯] ]')

def test_namedtuple(self):
# see bpo-39142
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Generalize the regex pattern ``BaseConfigurator.INDEX_PATTERN`` to allow spaces and non-alphanumeric characters in keys.