Skip to content

Commit

Permalink
[Typing] Initial typing of aruba.py (aerleon#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankenyr authored Mar 10, 2023
1 parent acf2d0b commit 4232b5a
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions aerleon/lib/aruba.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@

"""Aruba generator."""

from typing import List, Tuple
from typing import Dict, List, Set, Tuple

from absl import logging

from aerleon.lib import aclgenerator
from aerleon.lib.policy import Policy

_COMMENT_MARKER = '#'
_TERMINATOR_MARKER = '!'
Expand Down Expand Up @@ -68,14 +69,14 @@ class Term(aclgenerator.Term):
'esp': 50,
}

def __init__(self, term, filter_type, verbose=True):
def __init__(self, term, filter_type, verbose=True) -> None:
super().__init__(term)
self.term = term
self.filter_type = filter_type
self.netdestinations = []
self.verbose = verbose

def __str__(self):
def __str__(self) -> str:
netdestinations = []
ret_str = []
term_af = self.AF_MAP.get(self.filter_type)
Expand Down Expand Up @@ -156,7 +157,7 @@ def __str__(self):

return '\n'.join(t for t in ret_str if t)

def _GenerateNetdest(self, addr_netdestid, addresses, af):
def _GenerateNetdest(self, addr_netdestid, addresses, af) -> str:
"""Generates the netdestinations text block.
Args:
Expand All @@ -180,7 +181,7 @@ def _GenerateNetdest(self, addr_netdestid, addresses, af):

return '\n'.join(t for t in ret_str if t)

def _GenerateNetworkOrHostTokens(self, address):
def _GenerateNetworkOrHostTokens(self, address) -> str:
"""Generates the text block host or network identifier for netdestinations.
Args:
Expand All @@ -197,7 +198,7 @@ def _GenerateNetworkOrHostTokens(self, address):

return '%s %s %s' % (self._NETWORK_STRING, address.network_address, address.netmask)

def _GeneratePortTokens(self, protocols: List[str], ports: List[Tuple[int, int]]):
def _GeneratePortTokens(self, protocols: List[str], ports: List[Tuple[int, int]]) -> List[str]:
"""Generates string tokens for ports.
Args:
Expand Down Expand Up @@ -233,7 +234,7 @@ class Aruba(aclgenerator.ACLGenerator):

_ACL_LINE_HEADER = 'ip access-list session'

def _BuildTokens(self):
def _BuildTokens(self) -> Tuple[Set[str], Dict[str, Set[str]]]:
"""Build supported tokens for platform.
Returns:
Expand Down Expand Up @@ -266,7 +267,7 @@ def _BuildTokens(self):

return supported_tokens, supported_sub_tokens

def _TranslatePolicy(self, pol, exp_info):
def _TranslatePolicy(self, pol: Policy, exp_info: int) -> None:
self.aruba_policies = []

for header, terms in pol.filters:
Expand All @@ -287,7 +288,7 @@ def _TranslatePolicy(self, pol, exp_info):

self.aruba_policies.append((filter_name, new_terms, filter_type))

def __str__(self):
def __str__(self) -> str:
target = []

target.extend(aclgenerator.AddRepositoryTags('%s ' % _COMMENT_MARKER))
Expand Down

0 comments on commit 4232b5a

Please sign in to comment.