1 # Copyright (c) 2016 Cable Television Laboratories, Inc. ("CableLabs")
2 # and others. All rights reserved.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 from neutronclient.v2_0.client import _DictWithMeta
17 __author__ = 'spisarski'
20 def objects_equivalent(obj1, obj2):
22 Returns true if both objects are equivalent
27 if obj1 is None and obj2 is None:
29 if type(obj1) is dict or type(obj1) is _DictWithMeta:
30 return dicts_equivalent(obj1, obj2)
31 elif type(obj1) is list:
32 return lists_equivalent(obj1, obj2)
37 def dicts_equivalent(dict1, dict2):
39 Returns true when each key/value pair is equal
44 if (type(dict1) is dict or type(dict1) is _DictWithMeta) and (type(dict2) is dict or type(dict2) is _DictWithMeta):
45 for key, value1 in dict1.iteritems():
46 if not objects_equivalent(value1, dict2.get(key)):
52 def lists_equivalent(list1, list2):
54 Returns true when an item in list1 is also contained in list2
59 if len(list1) == len(list2) and type(list1) is list and type(list2) is list:
61 has_equivalent = False
63 has_equivalent = objects_equivalent(item1, item2)
66 if not has_equivalent: