Skip to content

Commit

Permalink
Allow pyluos to receive multiple Json at once. It will be merged into…
Browse files Browse the repository at this point in the history
… one.
  • Loading branch information
nicolas-rabault committed Mar 25, 2024
1 parent cfe01b5 commit 0776b18
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 12 additions & 1 deletion pyluos/io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import logging
from mergedeep import merge, Strategy


class IOHandler(object):
Expand All @@ -16,7 +17,17 @@ def is_ready(self):
def read(self, trials=5):
try:
data = self.recv()
return self.loads(data)
if data is None:
return None
table = data.splitlines()
if len(table) > 1:
# load the Json of each substring
jsn = [self.loads(sub_data) for sub_data in table]
# merge all the Json data
result = merge({}, *jsn, strategy=Strategy.ADDITIVE)
return result
else:
return self.loads(data)
except Exception as e:
logging.getLogger(__name__).debug('Msg read failed: {}'.format(str(e)))
if trials == 0:
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
'crc8',
'ipython',
'requests',
'simple_websocket_server==0.4.2'
'simple_websocket_server==0.4.2',
'mergedeep'
],
extras_require={
'tests': ['pytest', 'flake8'],
Expand Down

0 comments on commit 0776b18

Please sign in to comment.