From 87c23f25427ed2dfd555225d82a7950243e832d1 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 8 Dec 2020 02:05:25 +0800 Subject: [PATCH] bugfix --- ahserver/baseProcessor.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ahserver/baseProcessor.py b/ahserver/baseProcessor.py index 2af0f1c..060ef91 100644 --- a/ahserver/baseProcessor.py +++ b/ahserver/baseProcessor.py @@ -13,6 +13,10 @@ from appPublic.folderUtils import listFile from .serverenv import ServerEnv +def unicode_escape(s): + x = [ch if ord(ch) < 256 else ch.encode('unicode_escape').decode('utf-8') for ch in s] + return ''.join(x) + class ObjectCache: def __init__(self): self.cache = {} @@ -79,6 +83,10 @@ class BaseProcessor: elif type(self.content) == type([]): self.content = json.dumps(self.content, indent=4) + ret_len1 = len(self.content) + self.content = unicode_escape(self.content) + ret_len2 = len(self.content) + print('hangle(): len1=%d, len2=%d' % (ret_len1,ret_len2)) self.setheaders() return Response(text=self.content,headers=self.headers) @@ -97,8 +105,7 @@ class TemplateProcessor(BaseProcessor): async def datahandle(self,request): path = request.path request2ns = self.run_ns.get('request2ns') - if request2ns: - self.run_ns['params_kw'] = await request2ns() + self.run_ns['params_kw'] = await request2ns() ns = self.run_ns te = self.run_ns['tmpl_engine'] self.content = te.render(path,**ns)