diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2017-01-14 11:42:04 +0100 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2017-01-14 11:42:04 +0100 |
| commit | 7d6b8b43ad0aa752e6b718c18857c59a0df8b33b (patch) | |
| tree | 63ed64ff9539e6939f69741d6f25b87f31fd73f7 /gamelocker/janus.py | |
| parent | 3958aaf9c7675e2ec4657bd27c91fc72a41dc969 (diff) | |
| download | python-gamelocker-7d6b8b43ad0aa752e6b718c18857c59a0df8b33b.tar.gz python-gamelocker-7d6b8b43ad0aa752e6b718c18857c59a0df8b33b.zip | |
janus: support lists in from_message
Diffstat (limited to 'gamelocker/janus.py')
| -rw-r--r-- | gamelocker/janus.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/gamelocker/janus.py b/gamelocker/janus.py index 3902850..c239339 100644 --- a/gamelocker/janus.py +++ b/gamelocker/janus.py @@ -751,6 +751,7 @@ class DataMessage(object): #JSON API Data Object see: http://jsonapi.org/format/ """ Used to get a DataMessage (an object derived from DataMessage) with values in its Attribute members loaded from a jsonapi request object (raw string request) according to Attribute objects mapping. + If the jsonapi request object is a list a list of message objects is returned. msg_class => the class (derived from DataMessage) which should be used as message class. (This class will be initialized and returned) """ json_message = json.loads(raw_message) #parse raw_message to json @@ -765,9 +766,18 @@ class DataMessage(object): #JSON API Data Object see: http://jsonapi.org/format/ else: raise Exception("Message is missing data.") - msg = msg_class() - msg.map_message(data) - return msg + if isinstance(data, (list, tuple)): + messages = [] + for d in data: + msg = msg_class() + msg.map_message(d) + messages.append(msg) + + return messages + else: + msg = msg_class() + msg.map_message(data) + return msg def update_object(self,obj): """ |
