Skip to content

Commit 779f4ab

Browse files
committed
Use strict=False for same config parsing on py2 and py3
1 parent 83036de commit 779f4ab

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

supervisor/options.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,12 @@ def __init__(self, *args, **kwargs):
17221722
if (not PY2) and ('inline_comment_prefixes' not in kwargs):
17231723
kwargs['inline_comment_prefixes'] = (';', '#')
17241724

1725+
# strict was added in Python 3 but its default makes RawConfigParser
1726+
# behave differently than it did on Python 2. This makes it behave
1727+
# the same by default on Python 2 and 3.
1728+
if not PY2:
1729+
kwargs['strict'] = False
1730+
17251731
ConfigParser.RawConfigParser.__init__(self, *args, **kwargs)
17261732

17271733
self.section_to_file = {}

supervisor/tests/test_options.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,19 @@ def test_options_ignores_inline_comments(self):
316316
options = instance.configroot.supervisorctl
317317
self.assertEqual(options.serverurl, 'http://localhost:9001')
318318

319+
def test_options_parsers_as_nonstrict_for_py2_py3_compat(self):
320+
text = lstrip("""
321+
[supervisorctl]
322+
serverurl=http://localhost:9001 ;duplicate
323+
324+
[supervisorctl]
325+
serverurl=http://localhost:9001 ;duplicate
326+
""")
327+
instance = self._makeOne()
328+
instance.configfile = StringIO(text)
329+
instance.realize(args=[])
330+
# should not raise configparser.DuplicateSectionError on py3
331+
319332
def test_options_with_environment_expansions(self):
320333
s = lstrip("""[supervisorctl]
321334
serverurl=http://localhost:%(ENV_SERVER_PORT)s
@@ -690,6 +703,21 @@ def test_options_ignores_inline_comments(self):
690703
options = instance.configroot.supervisord
691704
self.assertEqual(options.identifier, 'foo')
692705

706+
def test_options_parsers_as_nonstrict_for_py2_py3_compat(self):
707+
text = lstrip("""
708+
[supervisord]
709+
710+
[program:duplicate]
711+
command=/bin/cat
712+
713+
[program:duplicate]
714+
command=/bin/cat
715+
""")
716+
instance = self._makeOne()
717+
instance.configfile = StringIO(text)
718+
instance.realize(args=[])
719+
# should not raise configparser.DuplicateSectionError on py3
720+
693721
def test_reload(self):
694722
text = lstrip("""\
695723
[supervisord]

0 commit comments

Comments
 (0)