From 86e9f5cf518097a85b969b6014db4c2206df0174 Mon Sep 17 00:00:00 2001 From: Erik Reid <erik.reid@geant.org> Date: Thu, 16 Jan 2020 11:34:18 +0100 Subject: [PATCH] renamed local utility method --- inventory_provider/routes/classifier.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/inventory_provider/routes/classifier.py b/inventory_provider/routes/classifier.py index a64a662d..7ae881e1 100644 --- a/inventory_provider/routes/classifier.py +++ b/inventory_provider/routes/classifier.py @@ -21,7 +21,13 @@ def _LOCATION(equipment, name, abbreviation): } -def _unique_dicts_from_list(l): +def _remove_duplicates_from_list(l): + """ + removes duplicates from the input list + the list items must be encodable as json + :param l: + :return: a new list with unique elements + """ tmp_dict = dict([(json.dumps(item, sort_keys=True), item) for item in l]) return list(tmp_dict.values()) @@ -194,7 +200,7 @@ def get_juniper_link_info(source_equipment, interface): if not result['locations']: result['locations'] = [_location_from_router(source_equipment)] - result['locations'] = _unique_dicts_from_list(result['locations']) + result['locations'] = _remove_duplicates_from_list(result['locations']) result = json.dumps(result) # cache this data for the next call r.set(cache_key, result.encode('utf-8')) @@ -344,7 +350,7 @@ def peer_info(address): result['locations'] += [ _location_from_service_dict(s) for s in i['services']] - result['locations'] = _unique_dicts_from_list(result['locations']) + result['locations'] = _remove_duplicates_from_list(result['locations']) result = json.dumps(result) # cache this data for the next call r.set(cache_key, result.encode('utf-8')) -- GitLab