diff --git a/CHANGES.rst b/CHANGES.rst index 5ec3079..3417457 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,8 @@ Changelog ========= +* Add support for multiple values of the same attribute (#95) + * Add experimental async client and server implementation for python >=3.5. * Add IPv6 bind support for client and server. diff --git a/pyrad/packet.py b/pyrad/packet.py index aa8c5c8..456cdd6 100644 --- a/pyrad/packet.py +++ b/pyrad/packet.py @@ -131,6 +131,9 @@ def _EncodeValue(self, attr, value): def _EncodeKeyValues(self, key, values): if not isinstance(key, str): return (key, values) + + if not isinstance(values, (list, tuple)): + values = [values] key, _, tag = key.partition(":") attr = self.dict.attributes[key] @@ -172,10 +175,7 @@ def AddAttribute(self, key, value): """ attr = self.dict.attributes[key] - if isinstance(value, list): - (key, value) = self._EncodeKeyValues(key, value) - else: - (key, value) = self._EncodeKeyValues(key, [value]) + (key, value) = self._EncodeKeyValues(key, value) if attr.is_sub_attribute: tlv = self.setdefault(self._EncodeKey(attr.parent.name), {}) @@ -218,7 +218,7 @@ def __delitem__(self, key): def __setitem__(self, key, item): if isinstance(key, six.string_types): - (key, item) = self._EncodeKeyValues(key, [item]) + (key, item) = self._EncodeKeyValues(key, item) dict.__setitem__(self, key, item) else: assert isinstance(item, list)