Skip to content

Commit 585a3ce

Browse files
committed
replace values at the end of the loop instead of updating inside
1 parent c4b5a98 commit 585a3ce

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

netjsonconfig/backends/airos/airos.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,20 @@ def intermediate_to_list(configuration):
126126
elif isinstance(element, tuple):
127127
(index, config) = element
128128
# update the keys to prefix the index
129+
temp = {}
129130
for k, v in config.items():
130131
# write the new key
131-
config['{i}.{key}'.format(i=index + 1, key=k)] = v
132-
# delete the old
133-
del config[k]
132+
temp['{i}.{key}'.format(i=index + 1, key=k)] = v
133+
134+
config = temp
134135
# now the keys are updated with the index
135136
# reduce to atoms the new config
136137
# by recursively calling yourself
137138
# on a list containing the new atom
138139
result = result + intermediate_to_list([config])
139140

140-
elif isinstance(element, dict):
141+
elif isinstance(element, dict):
142+
temp = {}
141143
for k, v in element.items():
142144
if isinstance(v, string_types) or isinstance(v, int):
143145
pass
@@ -149,13 +151,10 @@ def intermediate_to_list(configuration):
149151

150152
for sk, sv in son.items():
151153
nested_key = '{key}.{subkey}'.format(key=k, subkey=sk)
152-
element[nested_key] = sv
153-
154-
# remove the nested object
155-
del element[k]
154+
temp[nested_key] = sv
156155

157156
# now it is atomic, append it to
158-
result.append(element)
157+
result.append(temp)
159158

160159
else:
161160
raise Exception('malformed intermediate representation')

0 commit comments

Comments
 (0)