1
0
Fork 0
mirror of https://github.com/NeoCloud/NeoNetwork synced 2024-11-22 18:40:41 +08:00

roa.py: sort entities and asns

This commit is contained in:
JerryXiao 2021-06-06 20:18:41 +08:00
parent 2957878b87
commit 23ee50e86c
Signed by: Jerry
GPG key ID: 22618F758B5BE2E5

View file

@ -9,6 +9,7 @@ from io import StringIO
from ipaddress import IPv4Network, IPv6Network, ip_network from ipaddress import IPv4Network, IPv6Network, ip_network
from itertools import combinations from itertools import combinations
from pathlib import Path from pathlib import Path
from functools import wraps
import netaddr import netaddr
import toml import toml
@ -62,11 +63,21 @@ def iter_toml_file(path: str):
yield item, toml.loads(item.read_text()) 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(): def load_entities():
for item, entity in iter_toml_file("entity"): for item, entity in iter_toml_file("entity"):
yield item.stem, entity yield item.stem, entity
@_sort_as_iterator
def load_asn(entities: dict): def load_asn(entities: dict):
for item, entity in iter_toml_file("asn"): for item, entity in iter_toml_file("asn"):
asn = int(item.stem.lstrip("AS")) asn = int(item.stem.lstrip("AS"))