]> git.ipfire.org Git - location/libloc.git/commitdiff
importer: Make translating country codes more extensible
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 4 Mar 2024 09:49:43 +0000 (09:49 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 4 Mar 2024 09:49:43 +0000 (09:49 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/scripts/location-importer.in

index 18cca656272a6a2652574154fa9b9cdbe4fec487..4a487c95f0a5ff4b722ca19adeb61e3139b7418f 100644 (file)
@@ -48,6 +48,11 @@ VALID_ASN_RANGES = (
        (131072, 4199999999),
 )
 
+TRANSLATED_COUNTRIES = {
+       # When people say UK, they mean GB
+       "UK" : "GB",
+}
+
 IGNORED_COUNTRIES = set((
        # Formerly Yugoslavia
        "YU",
@@ -1109,9 +1114,11 @@ class CLI(object):
                                        log.debug("Ignoring country code '%s'" % val)
                                        continue
 
-                               # When people set country codes to "UK", they actually mean "GB"
-                               if val == "UK":
-                                       val = "GB"
+                               # Translate country codes
+                               try:
+                                       val = TRANSLATED_COUNTRIES[val]
+                               except KeyError:
+                                       pass
 
                                inetnum[key].append(val)