From 9d5d420bfc9b4bf9b356e97f0ea297653701f753 Mon Sep 17 00:00:00 2001 From: Peeyush Aggarwal Date: Sun, 9 Apr 2023 10:50:14 +0530 Subject: [PATCH 01/14] fix regex for INDEX_PATTERN in BaseConfigurator --- Lib/logging/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/logging/config.py b/Lib/logging/config.py index 7cd16c643e9dad..cb7b495867b89c 100644 --- a/Lib/logging/config.py +++ b/Lib/logging/config.py @@ -361,7 +361,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 = { From bdba91e643ae6641374f83591403cf51e3cdb1d4 Mon Sep 17 00:00:00 2001 From: Peeyush Aggarwal Date: Sun, 9 Apr 2023 10:50:23 +0530 Subject: [PATCH 02/14] add tests --- Lib/test/test_logging.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index c6de34e9dbdc8f..f15741e58e1c82 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -3520,7 +3520,7 @@ def test_baseconfig(self): d = { 'atuple': (1, 2, 3), 'alist': ['a', 'b', 'c'], - 'adict': {'d': 'e', 'f': 3 }, + 'adict': {'d': 'e', 'f': 3 , 'alpha nummeric 1 with spaces' : 5}, 'nest1': ('g', ('h', 'i'), 'j'), 'nest2': ['k', ['l', 'm'], 'n'], 'nest3': ['o', 'cfg://alist', 'p'], @@ -3532,6 +3532,7 @@ 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 nummeric 1 with spaces]'), 5) v = bc.convert('cfg://nest3') self.assertEqual(v.pop(1), ['a', 'b', 'c']) self.assertRaises(KeyError, bc.convert, 'cfg://nosuch') From 8c956ca0e75f9036cc16ad49ab8e44515ed54bab Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sun, 9 Apr 2023 05:30:42 +0000 Subject: [PATCH 03/14] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2023-04-09-05-30-41.gh-issue-103384.zAV7iB.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2023-04-09-05-30-41.gh-issue-103384.zAV7iB.rst diff --git a/Misc/NEWS.d/next/Library/2023-04-09-05-30-41.gh-issue-103384.zAV7iB.rst b/Misc/NEWS.d/next/Library/2023-04-09-05-30-41.gh-issue-103384.zAV7iB.rst new file mode 100644 index 00000000000000..79ca9f18a22b82 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-04-09-05-30-41.gh-issue-103384.zAV7iB.rst @@ -0,0 +1 @@ +Fix regex pattern for BaseConfigurator.INDEX_PATTERN From ca9f0c342d68d1715584407f40029c3601c8df3f Mon Sep 17 00:00:00 2001 From: Peeyush Aggarwal Date: Sun, 9 Apr 2023 15:09:02 +0530 Subject: [PATCH 04/14] update tests --- Lib/test/test_logging.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index f15741e58e1c82..de7d24d9712d2c 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -3520,7 +3520,7 @@ def test_baseconfig(self): d = { 'atuple': (1, 2, 3), 'alist': ['a', 'b', 'c'], - 'adict': {'d': 'e', 'f': 3 , 'alpha nummeric 1 with spaces' : 5}, + 'adict': {'d': 'e', 'f': 3 , 'alpha numeric 1 with spaces' : 5, 'aplha numeric 1 %( - © ©ß¯' : 9}, 'nest1': ('g', ('h', 'i'), 'j'), 'nest2': ['k', ['l', 'm'], 'n'], 'nest3': ['o', 'cfg://alist', 'p'], @@ -3532,7 +3532,8 @@ 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 nummeric 1 with spaces]'), 5) + self.assertEqual(bc.convert('cfg://adict[alpha nmmeric 1 with spaces]'), 5) + self.assertEqual(bc.convert('cfg://adict[alpha nmmeric 1 with spaces]'), 9) v = bc.convert('cfg://nest3') self.assertEqual(v.pop(1), ['a', 'b', 'c']) self.assertRaises(KeyError, bc.convert, 'cfg://nosuch') From 785fb1db92c9a94d19f10bdfc06fdd9dac870c64 Mon Sep 17 00:00:00 2001 From: Peeyush Aggarwal Date: Sun, 9 Apr 2023 15:27:03 +0530 Subject: [PATCH 05/14] fix tests --- Lib/test/test_logging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index de7d24d9712d2c..57b3583356a9d1 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -3533,7 +3533,7 @@ def test_baseconfig(self): self.assertEqual(bc.convert('cfg://adict.d'), 'e') self.assertEqual(bc.convert('cfg://adict[f]'), 3) self.assertEqual(bc.convert('cfg://adict[alpha nmmeric 1 with spaces]'), 5) - self.assertEqual(bc.convert('cfg://adict[alpha nmmeric 1 with spaces]'), 9) + self.assertEqual(bc.convert('cfg://adict[aplha numeric 1 %( - © ©ß¯]'), 9) v = bc.convert('cfg://nest3') self.assertEqual(v.pop(1), ['a', 'b', 'c']) self.assertRaises(KeyError, bc.convert, 'cfg://nosuch') From 96c00636cfe21aab6da3402199e47ece0fbabced Mon Sep 17 00:00:00 2001 From: Peeyush Aggarwal Date: Sun, 9 Apr 2023 16:10:25 +0530 Subject: [PATCH 06/14] improve test cases for BaseConfigurator --- Lib/test/test_logging.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index 57b3583356a9d1..442963d308f3bb 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -3520,7 +3520,19 @@ def test_baseconfig(self): d = { 'atuple': (1, 2, 3), 'alist': ['a', 'b', 'c'], - 'adict': {'d': 'e', 'f': 3 , 'alpha numeric 1 with spaces' : 5, 'aplha numeric 1 %( - © ©ß¯' : 9}, + 'adict': { + 'd': 'e', 'f': 3 , + 'alpha numeric 1 with spaces' : 5, + 'aplha numeric 1 %( - © ©ß¯' : 9, + '' : 10, + 'nest4' : { + 'd': 'e', 'f': 3 , + 'alpha numeric 1 with spaces' : 5, + 'aplha numeric 1 %( - © ©ß¯' : 9, + '' : 10, + } + }, + 'nest1': ('g', ('h', 'i'), 'j'), 'nest2': ['k', ['l', 'm'], 'n'], 'nest3': ['o', 'cfg://alist', 'p'], @@ -3532,8 +3544,16 @@ 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 nmmeric 1 with spaces]'), 5) + 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) v = bc.convert('cfg://nest3') self.assertEqual(v.pop(1), ['a', 'b', 'c']) self.assertRaises(KeyError, bc.convert, 'cfg://nosuch') From 9fe33ddb05efb6b1d2c110961421cf9a88c914d2 Mon Sep 17 00:00:00 2001 From: Peeyush Aggarwal Date: Sun, 9 Apr 2023 16:27:58 +0530 Subject: [PATCH 07/14] add tests for nested dict - BaseConfigurator --- Lib/test/test_logging.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index 442963d308f3bb..42c3fd6610c700 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -3530,9 +3530,14 @@ def test_baseconfig(self): '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'], @@ -3554,6 +3559,18 @@ def test_baseconfig(self): 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') From e5075e57bae5280cd4e5eeac35a58c4cf0edeec9 Mon Sep 17 00:00:00 2001 From: Peeyush Aggarwal Date: Sun, 9 Apr 2023 17:00:02 +0530 Subject: [PATCH 08/14] fix whitespaces in test_logging.py --- Lib/test/test_logging.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index 42c3fd6610c700..86f5523b0f514a 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -3521,13 +3521,13 @@ def test_baseconfig(self): 'atuple': (1, 2, 3), 'alist': ['a', 'b', 'c'], 'adict': { - 'd': 'e', 'f': 3 , - 'alpha numeric 1 with spaces' : 5, + 'd': 'e', 'f': 3 , + 'alpha numeric 1 with spaces' : 5, 'aplha numeric 1 %( - © ©ß¯' : 9, '' : 10, 'nest4' : { - 'd': 'e', 'f': 3 , - 'alpha numeric 1 with spaces' : 5, + 'd': 'e', 'f': 3 , + 'alpha numeric 1 with spaces' : 5, 'aplha numeric 1 %( - © ©ß¯' : 9, '' : 10, 'somelist' : ('g', ('h', 'i'), 'j'), From 77d486e20aece084408066f27a0fc66a299f76b4 Mon Sep 17 00:00:00 2001 From: Peeyush Aggarwal Date: Thu, 13 Apr 2023 17:34:14 +0530 Subject: [PATCH 09/14] Update Misc/NEWS.d/next/Library/2023-04-09-05-30-41.gh-issue-103384.zAV7iB.rst Co-authored-by: Vinay Sajip --- .../next/Library/2023-04-09-05-30-41.gh-issue-103384.zAV7iB.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2023-04-09-05-30-41.gh-issue-103384.zAV7iB.rst b/Misc/NEWS.d/next/Library/2023-04-09-05-30-41.gh-issue-103384.zAV7iB.rst index 79ca9f18a22b82..48ffb0f422bba5 100644 --- a/Misc/NEWS.d/next/Library/2023-04-09-05-30-41.gh-issue-103384.zAV7iB.rst +++ b/Misc/NEWS.d/next/Library/2023-04-09-05-30-41.gh-issue-103384.zAV7iB.rst @@ -1 +1 @@ -Fix regex pattern for BaseConfigurator.INDEX_PATTERN +Generalize the regex pattern `BaseConfigurator.INDEX_PATTERN` to allow spaces and non-alphanumeric characters in keys. From d22e94141a3355356d805964a2416c0b445a2c91 Mon Sep 17 00:00:00 2001 From: Peeyush Aggarwal Date: Thu, 13 Apr 2023 23:25:14 +0530 Subject: [PATCH 10/14] fix regex for INDEX_PATTERN in BaseConfigurator --- Lib/logging/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/logging/config.py b/Lib/logging/config.py index cb7b495867b89c..677b1cf075d055 100644 --- a/Lib/logging/config.py +++ b/Lib/logging/config.py @@ -361,7 +361,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*') + INDEX_PATTERN = re.compile(r'^\[([^\[\]]*)\]\s*') DIGIT_PATTERN = re.compile(r'^\d+$') value_converters = { From 92af5472f48cff92ec253ef166a8713384f5c8ef Mon Sep 17 00:00:00 2001 From: Peeyush Aggarwal Date: Thu, 13 Apr 2023 23:25:32 +0530 Subject: [PATCH 11/14] add tests --- Lib/test/test_logging.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index 86f5523b0f514a..12570ad9ea08e9 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -3524,6 +3524,10 @@ def test_baseconfig(self): '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 , @@ -3576,6 +3580,10 @@ def test_baseconfig(self): 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 From a5a2fc71dcf0b125faec01c210e7339198ae4806 Mon Sep 17 00:00:00 2001 From: Peeyush Aggarwal Date: Thu, 13 Apr 2023 23:36:39 +0530 Subject: [PATCH 12/14] fix NEWS.d entry for the commit as compliant with sphinx check --- .../next/Library/2023-04-09-05-30-41.gh-issue-103384.zAV7iB.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2023-04-09-05-30-41.gh-issue-103384.zAV7iB.rst b/Misc/NEWS.d/next/Library/2023-04-09-05-30-41.gh-issue-103384.zAV7iB.rst index 48ffb0f422bba5..3e9d3cf9ae92b6 100644 --- a/Misc/NEWS.d/next/Library/2023-04-09-05-30-41.gh-issue-103384.zAV7iB.rst +++ b/Misc/NEWS.d/next/Library/2023-04-09-05-30-41.gh-issue-103384.zAV7iB.rst @@ -1 +1 @@ -Generalize the regex pattern `BaseConfigurator.INDEX_PATTERN` to allow spaces and non-alphanumeric characters in keys. +Generalize the regex pattern ``BaseConfigurator.INDEX_PATTERN`` to allow spaces and non-alphanumeric characters in keys. From 1553667eb66f4a89dcacb49d23eb24202d8c1108 Mon Sep 17 00:00:00 2001 From: Peeyush Aggarwal Date: Thu, 13 Apr 2023 23:44:45 +0530 Subject: [PATCH 13/14] Add details about cfg_convert into logging.config docs. and are not allowed in keys. --- Doc/library/logging.config.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/library/logging.config.rst b/Doc/library/logging.config.rst index 2daf2422ebd5b4..5a942e566837d5 100644 --- a/Doc/library/logging.config.rst +++ b/Doc/library/logging.config.rst @@ -676,7 +676,8 @@ resolve to ``'dev_team@domain.tld'`` and the string ``'support_team@domain.tld'``. 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. From 3fffaa42ad7f9121b5cd6f9e2fdb35440615af4c Mon Sep 17 00:00:00 2001 From: Peeyush Aggarwal Date: Fri, 14 Apr 2023 00:08:53 +0530 Subject: [PATCH 14/14] fix whitespace in test_logging.py --- Lib/test/test_logging.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index 12570ad9ea08e9..e62f540bdd8086 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -3583,7 +3583,6 @@ def test_baseconfig(self): 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