Fix py3 unicode issue
unicode is nolonger a type in py3 - instead the str type is used for unicode, and the bytes type would cover the str type from py2. To avoid having to version the code, we should try to use unicode, except the NameError and continue as though it is py3 if that fails. Additionally, this patch adds a test that will fail if you revert the config_template.py back to it's original in py3. Closes-bug: 1763422 Change-Id: Ifda972caada27ade2d80f77b3df70568406226ff
This commit is contained in:
parent
6b6a9c6f76
commit
fc1c9311a8
@ -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)
|
||||
|
@ -3,6 +3,7 @@ list_one:
|
||||
- two
|
||||
- three
|
||||
- four
|
||||
- 4
|
||||
list_two:
|
||||
- one
|
||||
- two
|
||||
|
@ -1,5 +1,6 @@
|
||||
list_one:
|
||||
- four
|
||||
- 4
|
||||
list_two:
|
||||
- one
|
||||
- two
|
||||
|
@ -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]
|
||||
[bar]
|
||||
|
@ -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 }}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user