comparison sat_frontends/jp/cmd_forums.py @ 2608:0883bac573fd

jp (forums/edit): fixed unicode when dumping in json
author Goffi <goffi@goffi.org>
date Sun, 03 Jun 2018 18:05:01 +0200
parents 26edcf3a30eb
children 56f94936df1e
comparison
equal deleted inserted replaced
2607:4c086cf7af66 2608:0883bac573fd
22 from sat.core.i18n import _ 22 from sat.core.i18n import _
23 from sat_frontends.jp.constants import Const as C 23 from sat_frontends.jp.constants import Const as C
24 from sat_frontends.jp import common 24 from sat_frontends.jp import common
25 from sat.tools.common.ansi import ANSI as A 25 from sat.tools.common.ansi import ANSI as A
26 from functools import partial 26 from functools import partial
27 import codecs
27 import json 28 import json
28 29
29 __commands__ = ["Forums"] 30 __commands__ = ["Forums"]
30 31
31 FORUMS_TMP_DIR = u"forums" 32 FORUMS_TMP_DIR = u"forums"
67 content_file_obj, content_file_path = self.getTmpFile() 68 content_file_obj, content_file_path = self.getTmpFile()
68 forums_json = forums_json.strip() 69 forums_json = forums_json.strip()
69 if forums_json: 70 if forums_json:
70 # we loads and dumps to have pretty printed json 71 # we loads and dumps to have pretty printed json
71 forums = json.loads(forums_json) 72 forums = json.loads(forums_json)
72 json.dump(forums, content_file_obj, ensure_ascii=False, indent=4) 73 # cf. https://stackoverflow.com/a/18337754
74 f = codecs.getwriter('utf-8')(content_file_obj)
75 json.dump(forums, f, ensure_ascii=False, indent=4)
73 content_file_obj.seek(0) 76 content_file_obj.seek(0)
74 self.runEditor("forums_editor_args", content_file_path, content_file_obj) 77 self.runEditor("forums_editor_args", content_file_path, content_file_obj)
75 78
76 def forumsGetEb(self, failure_): 79 def forumsGetEb(self, failure_):
77 # FIXME: error handling with bridge is broken, need to be properly fixed 80 # FIXME: error handling with bridge is broken, need to be properly fixed