chore(bird): Improve code readability

This commit is contained in:
v-lafeychine 2024-04-01 00:20:41 +02:00
parent 54d227232b
commit 9aaa619173
Signed by: v-lafeychine
GPG key ID: F46CAAD27C7AB0D5

View file

@ -89,7 +89,7 @@ class IPv4orIPv6(BaseModel):
ipv6: list[int] = Field(ge=0, min_items=2, max_items=2) ipv6: list[int] = Field(ge=0, min_items=2, max_items=2)
class IPFlag(str): class IPFlag:
@classmethod @classmethod
def __get_validators__(cls): def __get_validators__(cls):
yield cls.validate yield cls.validate
@ -236,14 +236,8 @@ def str_of_condition(condition: Condition, ctx: bool) -> str:
return f"{min_v6} <= net.len && net.len <= {max_v6}" return f"{min_v6} <= net.len && net.len <= {max_v6}"
case NetMatch(matches=matches): case NetMatch(matches=matches):
if ctx.ipv4: networkType = IPv4Network if ctx.ipv4 else IPv6Network
networks = [ networks = [m for m in matches if isinstance(m[0], networkType)]
m for m in matches if isinstance(m[0], IPv4Network)
]
else:
networks = [
m for m in matches if isinstance(m[0], IPv6Network)
]
return f"net ~ [ {', '.join([f'{network}{flag}' for (network, flag) in networks])} ]" return f"net ~ [ {', '.join([f'{network}{flag}' for (network, flag) in networks])} ]"