From 23ee50e86c5aedc5fbf4fbbc628d6fb3d30cba34 Mon Sep 17 00:00:00 2001 From: Jerry Date: Sun, 6 Jun 2021 20:18:41 +0800 Subject: [PATCH] roa.py: sort entities and asns --- scripts/roa.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/roa.py b/scripts/roa.py index 69b6e92..65abd0e 100755 --- a/scripts/roa.py +++ b/scripts/roa.py @@ -9,6 +9,7 @@ from io import StringIO from ipaddress import IPv4Network, IPv6Network, ip_network from itertools import combinations from pathlib import Path +from functools import wraps import netaddr import toml @@ -62,11 +63,21 @@ def iter_toml_file(path: str): yield item, toml.loads(item.read_text()) +def _sort_as_iterator(func): + @wraps(func) + def wrapped(*args, **kwargs): + for item in sorted(list(func(*args, **kwargs)), key=lambda x: x[0], reverse=False): + yield item + return wrapped + + +@_sort_as_iterator def load_entities(): for item, entity in iter_toml_file("entity"): yield item.stem, entity +@_sort_as_iterator def load_asn(entities: dict): for item, entity in iter_toml_file("asn"): asn = int(item.stem.lstrip("AS"))