Skip to content

Commit

Permalink
fixed #95 multiple values of the same attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
GIC-de committed Oct 19, 2019
1 parent 75f7aa5 commit abdc122
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
10 changes: 5 additions & 5 deletions pyrad/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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), {})
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit abdc122

Please sign in to comment.