Mercurial > libervia-backend
comparison sat/tools/common/data_format.py @ 3893:045af0eeda3f
core, CLI (base), tools (common/data_format): typing/core readability
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 21 Sep 2022 22:20:43 +0200 |
parents | be6d91572633 |
children | 524856bd7b19 |
comparison
equal
deleted
inserted
replaced
3892:ba78cc0c8d59 | 3893:045af0eeda3f |
---|---|
17 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
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 | |
23 from typing import Any | |
22 | 24 |
23 from sat.core import exceptions | 25 from sat.core import exceptions |
24 import json | 26 import json |
25 | 27 |
26 | 28 |
131 | 133 |
132 @return(unicode): serialised data, can be transmitted as string to the bridge | 134 @return(unicode): serialised data, can be transmitted as string to the bridge |
133 """ | 135 """ |
134 return json.dumps(data, ensure_ascii=False, default=str) | 136 return json.dumps(data, ensure_ascii=False, default=str) |
135 | 137 |
136 def deserialise(serialised_data, default=None, type_check=dict): | 138 def deserialise(serialised_data: str, default: Any = None, type_check: type = dict): |
137 """Deserialize data from bridge | 139 """Deserialize data from bridge |
138 | 140 |
139 @param serialised_data(unicode): data to deserialise | 141 @param serialised_data(unicode): data to deserialise |
140 @default (object): value to use when serialised data is empty string | 142 @default (object): value to use when serialised data is empty string |
141 @param type_check(type): if not None, the deserialised data must be of this type | 143 @param type_check(type): if not None, the deserialised data must be of this type |