diff --git a/action/config_template.py b/action/config_template.py index c8c7246..74efb9f 100644 --- a/action/config_template.py +++ b/action/config_template.py @@ -213,14 +213,20 @@ class ConfigTemplateParser(ConfigParser.RawConfigParser): if line[0].isspace() and cursect is not None and optname: value = line.strip() if value: - if isinstance(cursect[optname], (tuple, set)): - _temp_item = list(cursect[optname]) - del cursect[optname] - cursect[optname] = _temp_item - elif isinstance(cursect[optname], (str, unicode)): - _temp_item = [cursect[optname]] - del cursect[optname] - cursect[optname] = _temp_item + try: + if isinstance(cursect[optname], (tuple, set)): + _temp_item = list(cursect[optname]) + del cursect[optname] + cursect[optname] = _temp_item + elif isinstance(cursect[optname], (str, unicode)): + _temp_item = [cursect[optname]] + del cursect[optname] + cursect[optname] = _temp_item + except NameError: + if isinstance(cursect[optname], (bytes, str)): + _temp_item = [cursect[optname]] + del cursect[optname] + cursect[optname] = _temp_item cursect[optname].append(value) else: mo = self.SECTCRE.match(line) diff --git a/tests/files/test_extend.yml.expected b/tests/files/test_extend.yml.expected index c132a76..eda6a80 100644 --- a/tests/files/test_extend.yml.expected +++ b/tests/files/test_extend.yml.expected @@ -3,6 +3,7 @@ list_one: - two - three - four + - 4 list_two: - one - two diff --git a/tests/files/test_no_extend.yml.expected b/tests/files/test_no_extend.yml.expected index 4713768..7e79aa7 100644 --- a/tests/files/test_no_extend.yml.expected +++ b/tests/files/test_no_extend.yml.expected @@ -1,5 +1,6 @@ list_one: - four + - 4 list_two: - one - two diff --git a/tests/templates/test_with_comments.ini b/tests/templates/test_with_comments.ini index aa292fb..79d3644 100644 --- a/tests/templates/test_with_comments.ini +++ b/tests/templates/test_with_comments.ini @@ -2,8 +2,14 @@ # broken into multiple lines [DEFAULT] +# This tests the py3 unicode bug #1763422 +test_hosts = + +_unicode + 1 + string + [foo] #This is a comment baz = baz -[bar] \ No newline at end of file +[bar] diff --git a/tests/test.yml b/tests/test.yml index 1dfb17c..54c3269 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -222,17 +222,17 @@ foo: baz: "bar" section1: - key1: "value1" - key2: "value2" - key3: "value3" - key4: "value4" - key5: "value5" - key6: "value6" - key7: "value7" - key8: "value8" - key9: "value9" - key10: "value10" - key11: "value11" + key1: "String1" + key2: "string2" + key3: "string3" + key4: "string4" + key5: "string5" + key6: "string6" + key7: 1 + key8: 2 + key9: 3 + key10: 10 + key11: 11 section2: key1: "value1" section3: @@ -246,15 +246,16 @@ section7: key1: "value1" section8: - key1: "value1" + key1: 1 section9: - key1: "value1" + key1: 1 section10: - key1: "value1" + key1: 1 section11: - key1: "value1" + key1: 1 test_config_yml_overrides: list_one: - four + - 4 test_config_yml_hostvars_overrides: test_hostvar: "{{ ansible_default_ipv4.address }}"