diff options
Diffstat (limited to 'cloudinit/mergers/m_list.py')
-rw-r--r-- | cloudinit/mergers/m_list.py | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/cloudinit/mergers/m_list.py b/cloudinit/mergers/m_list.py index 19f32771..9dfae8cd 100644 --- a/cloudinit/mergers/m_list.py +++ b/cloudinit/mergers/m_list.py @@ -4,8 +4,8 @@ # # This file is part of cloud-init. See LICENSE file for license information. -DEF_MERGE_TYPE = 'replace' -MERGE_TYPES = ('append', 'prepend', DEF_MERGE_TYPE, 'no_replace') +DEF_MERGE_TYPE = "replace" +MERGE_TYPES = ("append", "prepend", DEF_MERGE_TYPE, "no_replace") def _has_any(what, *keys): @@ -25,38 +25,44 @@ class Merger(object): self._method = m break # Affect how recursive merging is done on other primitives - self._recurse_str = _has_any(opts, 'recurse_str') - self._recurse_dict = _has_any(opts, 'recurse_dict') - self._recurse_array = _has_any(opts, 'recurse_array', 'recurse_list') + self._recurse_str = _has_any(opts, "recurse_str") + self._recurse_dict = _has_any(opts, "recurse_dict") + self._recurse_array = _has_any(opts, "recurse_array", "recurse_list") def __str__(self): - return ('ListMerger: (method=%s,recurse_str=%s,' - 'recurse_dict=%s,recurse_array=%s)') % (self._method, - self._recurse_str, - self._recurse_dict, - self._recurse_array) + return ( + "ListMerger: (method=%s,recurse_str=%s," + "recurse_dict=%s,recurse_array=%s)" + % ( + self._method, + self._recurse_str, + self._recurse_dict, + self._recurse_array, + ) + ) def _on_tuple(self, value, merge_with): return tuple(self._on_list(list(value), merge_with)) def _on_list(self, value, merge_with): - if (self._method == 'replace' and - not isinstance(merge_with, (tuple, list))): + if self._method == "replace" and not isinstance( + merge_with, (tuple, list) + ): return merge_with # Ok we now know that what we are merging with is a list or tuple. merged_list = [] - if self._method == 'prepend': + if self._method == "prepend": merged_list.extend(merge_with) merged_list.extend(value) return merged_list - elif self._method == 'append': + elif self._method == "append": merged_list.extend(value) merged_list.extend(merge_with) return merged_list def merge_same_index(old_v, new_v): - if self._method == 'no_replace': + if self._method == "no_replace": # Leave it be... return old_v if isinstance(new_v, (list, tuple)) and self._recurse_array: @@ -74,4 +80,5 @@ class Merger(object): merged_list[i] = merge_same_index(merged_list[i], merge_with[i]) return merged_list + # vi: ts=4 expandtab |