Use provided mapping object type instead OrderedDict

Better to use the given mapping type from the input data instead of
assuming that the yaml loader has used a particular class type.

This ensures that the code is isolated from any changes made to how the
object type of the input data. Merely needs to know whether it is a
mapping or list type and act accordingly.

Change-Id: If54e7857ca38dc4c9fe7c1f77e8a70f826d39bc8
This commit is contained in:
Darragh Bailey 2016-03-07 13:47:40 +00:00
parent 7782cac60e
commit 82dd7fd4c4
1 changed files with 5 additions and 4 deletions

View File

@ -29,7 +29,6 @@ Example::
- timed: '@daily'
"""
from collections import OrderedDict
import logging
import re
import xml.etree.ElementTree as XML
@ -88,7 +87,9 @@ def gerrit_handle_legacy_configuration(data):
'branchPattern',
])
old_format_events = OrderedDict(
mapping_obj_type = type(data)
old_format_events = mapping_obj_type(
(key, should_register) for key, should_register in six.iteritems(data)
if key.startswith('trigger-on-'))
trigger_on = data.setdefault('trigger-on', [])
@ -109,8 +110,8 @@ def gerrit_handle_legacy_configuration(data):
for idx, event in enumerate(trigger_on):
if event == 'comment-added-event':
trigger_on[idx] = events = OrderedDict()
events['comment-added-event'] = OrderedDict((
trigger_on[idx] = events = mapping_obj_type()
events['comment-added-event'] = mapping_obj_type((
('approval-category', data['trigger-approval-category']),
('approval-value', data['trigger-approval-value'])
))