Mercurial > libervia-backend
comparison sat/tools/common/data_format.py @ 2656:8cacf7929f3c
tools (common/data_format): added serialise and deserialise methods (using json for now)
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 11 Aug 2018 18:24:55 +0200 |
parents | 56f94936df1e |
children | fcc945537d5f |
comparison
equal
deleted
inserted
replaced
2655:b8600f8130ac | 2656:8cacf7929f3c |
---|---|
19 | 19 |
20 """ tools common to backend and frontends """ | 20 """ tools common to backend and frontends """ |
21 # FIXME: json may be more appropriate than manual serialising like done here | 21 # FIXME: json may be more appropriate than manual serialising like done here |
22 | 22 |
23 from sat.core import exceptions | 23 from sat.core import exceptions |
24 import json | |
24 | 25 |
25 | 26 |
26 def dict2iter(name, dict_, pop=False): | 27 def dict2iter(name, dict_, pop=False): |
27 """iterate into a list serialised in a dict | 28 """iterate into a list serialised in a dict |
28 | 29 |
122 else: | 123 else: |
123 if k[len(name)] != sep: | 124 if k[len(name)] != sep: |
124 continue | 125 continue |
125 else: | 126 else: |
126 yield k[len(name) + 1 :], v | 127 yield k[len(name) + 1 :], v |
128 | |
129 def serialise(data): | |
130 """Serialise data so it can be sent to bridge | |
131 | |
132 @return(unicode): serialised data, can be transmitted as string to the bridge | |
133 """ | |
134 return json.dumps(data, ensure_ascii=False) | |
135 | |
136 def deserialise(serialised_data): | |
137 """Deserialize data from bridge | |
138 | |
139 @param serialised_data(unicode): data to deserialise | |
140 @return(object): deserialised data | |
141 """ | |
142 return json.loads(serialised_data) |