From 5487ee0d92af71f7c26c0856d3912c8877e0f5d4 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 4 Mar 2024 09:52:38 +0000 Subject: [PATCH] importer: When storing country codes, make the code more straight-forward Signed-off-by: Michael Tremer --- src/scripts/location-importer.in | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/scripts/location-importer.in b/src/scripts/location-importer.in index 9b83f3f..7a811e9 100644 --- a/src/scripts/location-importer.in +++ b/src/scripts/location-importer.in @@ -1099,28 +1099,23 @@ class CLI(object): inetnum[key] = [ipaddress.ip_network(val, strict=False)] elif key == "country": - val = val.upper() - - # Catch RIR data objects with more than one country code... - if not key in inetnum: - inetnum[key] = [] - else: - if val in inetnum.get("country"): - # ... but keep this list distinct... - continue + cc = val.upper() # Ignore certain country codes - if val in IGNORED_COUNTRIES: - log.debug("Ignoring country code '%s'" % val) + if cc in IGNORED_COUNTRIES: + log.debug("Ignoring country code '%s'" % cc) continue # Translate country codes try: - val = TRANSLATED_COUNTRIES[val] + cc = TRANSLATED_COUNTRIES[cc] except KeyError: pass - inetnum[key].append(val) + try: + inetnum[key].append(cc) + except KeyError: + inetnum[key] = [cc] # Parse the geofeed attribute elif key == "geofeed": -- 2.47.3