commit 49f40f1e1fc3e9fd4c61a44160af415692326396
parent c0ee1fd098974aa34230cb73021f2578f0cfe8fc
Author: Antoine A <>
Date: Fri, 21 Feb 2025 18:21:09 +0100
Improve registry parsing
Diffstat:
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/parse_registry.py b/parse_registry.py
@@ -14,27 +14,25 @@ assert len(registry_txt) == 57
def parse_line(prefix):
line = registry_txt.pop(0)
- parts = list(
- map(lambda x: None if x == "" or x == "N/A" else x.strip(), line.split("\t"))
- )
+ parts = [None if x == "" or "N/A" in x else x.strip() for x in line.split("\t")]
first = parts.pop(0)
assert first == prefix, first
return parts
def parse_countries(prefix):
- line = parse_line(prefix)
- return list(map(lambda x: [] if x is None else x.strip('"').split(", "), line))
+ def parse_countries(encoded):
+ return [x.split(' ', 1)[0] for x in encoded.strip('"').split(", ")]
+
+ return [[] if x is None else parse_countries(x) for x in parse_line(prefix)]
def parse_bool_line(prefix):
- line = parse_line(prefix)
- return list(map(lambda x: x == "Yes", line))
+ return [x == "Yes" for x in parse_line(prefix)]
def parse_int_line(prefix):
- line = parse_line(prefix)
- return list(map(lambda x: int(x.split("!")[0]), line))
+ return [int(x.split("!")[0]) for x in parse_line(prefix)]
def parse_pattern(encoded):
@@ -69,7 +67,7 @@ def parse_pattern(encoded):
def parse_range(range):
if range is None:
return None
- (start, end) = list(map(lambda x: int(x), range.split("-", 1)))
+ (start, end) = [int(x) for x in range.split("-", 1)]
return (start - 1, end)