trival simplification + explicit variable typing
This commit is contained in:
@@ -385,9 +385,8 @@ class Dictionary:
|
||||
# else:
|
||||
# pass
|
||||
|
||||
base_datatype = datatype.split("[")[0].replace("-", "")
|
||||
try:
|
||||
attribute_type = Datatype[base_datatype.upper()]
|
||||
attribute_type = Datatype[datatype.split("[")[0].replace("-", "").upper()]
|
||||
except KeyError as exc:
|
||||
raise ParseError(filename, f"Illegal type: {datatype}", line_num) from exc
|
||||
|
||||
@@ -401,18 +400,15 @@ class Dictionary:
|
||||
len(codes) > 1,
|
||||
)
|
||||
|
||||
attrcode: Union[int, Tuple[int, ...]] = (
|
||||
codes[0] if len(codes) == 1 else tuple(codes)
|
||||
)
|
||||
self.cur_vendor.attrs[attrcode] = attribute
|
||||
|
||||
if datatype == "evs":
|
||||
if not isinstance(attrcode, tuple):
|
||||
if not len(codes) > 1:
|
||||
raise ParseError(filename, "evs must be a tlv", line_num)
|
||||
self.evs[name.upper()] = list(attrcode)
|
||||
self.evs[name.upper()] = codes
|
||||
|
||||
if self.cur_vendor != self.rfc_vendor and len(evs) == 0:
|
||||
codes = [26, self.cur_vendor.code] + codes
|
||||
self.cur_vendor.attrs[tuple(codes)] = attribute
|
||||
|
||||
LOG.info(
|
||||
"Register Attribute %s for Vendor %s",
|
||||
attribute.name,
|
||||
@@ -420,11 +416,11 @@ class Dictionary:
|
||||
)
|
||||
else:
|
||||
LOG.info("Register Attribute %s", attribute.name)
|
||||
|
||||
attrcode: Union[int, Tuple[int, ...]] = (
|
||||
codes[0] if len(codes) == 1 else tuple(codes)
|
||||
)
|
||||
self.attrindex[attrcode] = attribute
|
||||
self.attrindex[name] = attribute
|
||||
self.attrindex[attrcode] = self.attrindex[name] = attribute
|
||||
|
||||
def _parse_value(self, tokens: Sequence[str], line_num: int):
|
||||
"""Parse an ATTRIBUTE line of (Free)RADIUS dictionaries."""
|
||||
|
||||
@@ -144,8 +144,9 @@ def pre_decode_attributes( # pylint: disable=too-many-branches
|
||||
# TODO: deal with tagged tlvs
|
||||
attributes.extend(decode_tlv(rad_dict, list(key), value, offset))
|
||||
elif adef.datatype == Datatype.EVS:
|
||||
assert isinstance(key, tuple)
|
||||
attributes.append(decode_evs(key, value))
|
||||
# EVS must be a Tuple[int, int]
|
||||
k: Tuple[int, int] = key
|
||||
attributes.append(decode_evs(k, value))
|
||||
else:
|
||||
raise ValueError
|
||||
except (ValueError, KeyError):
|
||||
|
||||
Reference in New Issue
Block a user