Skip to content
Snippets Groups Projects
Commit 86e9f5cf authored by Erik Reid's avatar Erik Reid
Browse files

renamed local utility method

parent fcfce474
No related branches found
No related tags found
No related merge requests found
......@@ -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'))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment