From 8ad75cbe80345ac57bd7c2dfde1ae786dfd5c282 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sun, 25 May 2025 14:39:38 +0800 Subject: [PATCH] bugfix --- ahserver/baseProcessor.py | 8 ++++---- ahserver/filestorage.py | 2 +- ahserver/globalEnv.py | 2 +- ahserver/llm_client.py | 10 +++++----- ahserver/sqldsProcessor.py | 2 +- ahserver/websocketProcessor.py | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ahserver/baseProcessor.py b/ahserver/baseProcessor.py index 8a716d8..327d92c 100644 --- a/ahserver/baseProcessor.py +++ b/ahserver/baseProcessor.py @@ -102,16 +102,16 @@ class BaseProcessor: elif isinstance(self.content, StreamResponse): return self.content elif isinstance(self.content, DictObject): - self.content = json.dumps(self.content, indent=4) + self.content = json.dumps(self.content, indent=4, ensure_ascii=False) jsonflg = True elif isinstance(self.content, dict): - self.content = json.dumps(self.content, indent=4) + self.content = json.dumps(self.content, indent=4, ensure_ascii=False) jsonflg = True elif isinstance(self.content, list): - self.content = json.dumps(self.content, indent=4) + self.content = json.dumps(self.content, indent=4, ensure_ascii=False) jsonflg = True elif isinstance(self.content, tuple): - self.content = json.dumps(self.content, indent=4) + self.content = json.dumps(self.content, indent=4, ensure_ascii=False) jsonflg = True elif isinstance(self.content, bytes): self.headers['Access-Control-Expose-Headers'] = 'Set-Cookie' diff --git a/ahserver/filestorage.py b/ahserver/filestorage.py index b2854df..966859a 100644 --- a/ahserver/filestorage.py +++ b/ahserver/filestorage.py @@ -38,7 +38,7 @@ class TmpFileRecord: if not self.change_flg: return async with aiofiles.open(self.filename, 'bw') as f: - s = json.dumps(self.filetime) + s = json.dumps(self.filetime, indent=4, ensure_ascii=False) b = s.encode('utf-8') await f.write(b) await f.flush() diff --git a/ahserver/globalEnv.py b/ahserver/globalEnv.py index 6cbfa46..d5ae194 100644 --- a/ahserver/globalEnv.py +++ b/ahserver/globalEnv.py @@ -60,7 +60,7 @@ async def stream_response(request, async_data_generator, content_type='text/html elif isinstance(d, str): await res.write(d.encode('utf-8')) else: - d = json.dumps(d) + d = json.dumps(d, indent=4, ensure_ascii=False) await res.write(d.encode('utf-8')) await res.drain() await res.write_eof() diff --git a/ahserver/llm_client.py b/ahserver/llm_client.py index 3dffd0c..5d78371 100644 --- a/ahserver/llm_client.py +++ b/ahserver/llm_client.py @@ -58,7 +58,7 @@ class StreamLlmProxy: if f and f(v,v1): j[self.api.chunk_filter.field] = '' - jstr = json.dumps(j) + '\n' + jstr = json.dumps(j, indent=4, ensure_ascii=False) + '\n' bin = jstr.encode('utf-8') await self.resp.write(bin) await self.resp.drain() @@ -114,7 +114,7 @@ class StreamLlmProxy: hc = HttpClient() resp_data = await hc.request(url, method, response_type=RESPONSE_JSON, params=_params, - data=None if _data == {} else json.dumps(_data), + data=None if _data == {} else json.dumps(_data, indent=4, ensure_ascii=False), headers=_headers) resp_data = DictObject(**resp_data) for sd in d.set_data: @@ -171,7 +171,7 @@ class StreamLlmProxy: debug(f'{url=},{method=},{_params=},{_data=},{_headers=}') resp_data = await hc.request(url, method, response_type=response_type, params=_params, - data=None if _data == {} else json.dumps(_data), + data=None if _data == {} else json.dumps(_data, indent=4, ensure_ascii=False), stream_func=self.stream_handle, headers=_headers) if self.remain_str != '': @@ -215,7 +215,7 @@ class SyncLlmProxy(StreamLlmProxy): debug(f'{url=},{method=},{_params=},{_data=},{_headers=}') resp_data = await hc.request(url, method, response_type=response_type, params=_params, - data=None if _data == {} else json.dumps(_data), + data=None if _data == {} else json.dumps(_data, indent=4, ensure_ascii=False), headers=_headers) debug(f'{resp_data=}') if resp_data is None: @@ -270,7 +270,7 @@ class AsyncLlmProxy(StreamLlmProxy): debug(f'{url=},{method=},{_params=},{_data=},{_headers=}') resp_data = await hc.request(url, method, response_type=response_type, params=_params, - data=None if _data == {} else json.dumps(_data), + data=None if _data == {} else json.dumps(_data, indent=4, ensure_ascii=False), headers=_headers) if self.remain_str != '': await self.write_chunk(self.remain_str) diff --git a/ahserver/sqldsProcessor.py b/ahserver/sqldsProcessor.py index 1cf3b77..0233af6 100644 --- a/ahserver/sqldsProcessor.py +++ b/ahserver/sqldsProcessor.py @@ -49,7 +49,7 @@ class SQLDataSourceProcessor(DataSourceProcessor): rec = [ r for r in sql(sqldesc['db'],ns) if r['name']!='_row_id' ] dict_data['datadesc'] = rec f = codecs.open(self.src_file,'w',self.config.website.coding) - b = json.dumps(dict_data,indent=4) + b = json.dumps(dict_data, indent=4, ensure_ascii=False) f.write(b) f.close() return rec diff --git a/ahserver/websocketProcessor.py b/ahserver/websocketProcessor.py index eed49c6..ea30ff4 100644 --- a/ahserver/websocketProcessor.py +++ b/ahserver/websocketProcessor.py @@ -90,7 +90,7 @@ class XtermProcessor(PythonScriptProcessor): "type":1, "data":s } - await ws.send_str(json.dumps(data)) + await ws.send_str(json.dumps(data, indent=4, ensure_ascii=False)) def close_process(self): self.sshnode.close() @@ -102,7 +102,7 @@ async def ws_send(ws:web.WebSocketResponse, data): "type":1, "data":data } - d = json.dumps(d) + d = json.dumps(d, indent=4, ensure_ascii=False) try: return await ws.send_str(d) except Exception as e: