mirror of
https://github.com/NeoCloud/NeoNetwork
synced 2024-11-22 18:00:41 +08:00
roa.py: sort entities and asns
This commit is contained in:
parent
2957878b87
commit
23ee50e86c
1 changed files with 11 additions and 0 deletions
|
@ -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"))
|
||||||
|
|
Loading…
Reference in a new issue