OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 """ | 3 """ |
4 Copyright 2013 Google Inc. | 4 Copyright 2013 Google Inc. |
5 | 5 |
6 Use of this source code is governed by a BSD-style license that can be | 6 Use of this source code is governed by a BSD-style license that can be |
7 found in the LICENSE file. | 7 found in the LICENSE file. |
8 | 8 |
9 Repackage expected/actual GM results as needed by our HTML rebaseline viewer. | 9 Repackage expected/actual GM results as needed by our HTML rebaseline viewer. |
10 """ | 10 """ |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 """ | 296 """ |
297 output_dict = {} | 297 output_dict = {} |
298 for subdict in input_dict.values(): | 298 for subdict in input_dict.values(): |
299 for subdict_key, subdict_value in subdict.iteritems(): | 299 for subdict_key, subdict_value in subdict.iteritems(): |
300 if subdict_key in output_dict: | 300 if subdict_key in output_dict: |
301 raise Exception('duplicate key %s in combine_subdicts' % subdict_key) | 301 raise Exception('duplicate key %s in combine_subdicts' % subdict_key) |
302 output_dict[subdict_key] = subdict_value | 302 output_dict[subdict_key] = subdict_value |
303 return output_dict | 303 return output_dict |
304 | 304 |
305 @staticmethod | 305 @staticmethod |
306 def get_multilevel(input_dict, *keys): | 306 def get_default(input_dict, default_value, *keys): |
307 """ Returns input_dict[key1][key2][...], or None if any key is not found. | 307 """Returns input_dict[key1][key2][...], or default_value. |
| 308 |
| 309 If input_dict is None, or any key is missing along the way, this returns |
| 310 default_value. |
| 311 |
| 312 Args: |
| 313 input_dict: dictionary to look within |
| 314 key: key indicating which value to return from input_dict |
| 315 default_value: value to return if input_dict is None or any key cannot |
| 316 be found along the way |
308 """ | 317 """ |
| 318 if input_dict == None: |
| 319 return default_value |
309 for key in keys: | 320 for key in keys: |
| 321 input_dict = input_dict.get(key, None) |
310 if input_dict == None: | 322 if input_dict == None: |
311 return None | 323 return default_value |
312 input_dict = input_dict.get(key, None) | |
313 return input_dict | 324 return input_dict |
OLD | NEW |