This commit is contained in:
yumoqing 2025-06-14 21:38:24 +08:00
parent e4b2796f17
commit 1c22efd7a0
2 changed files with 17 additions and 9 deletions

View File

@ -39,9 +39,11 @@ class FunctionProcessor(BaseProcessor):
# globals().update(self.run_ns)
debug(f'params_kw={params_kw}, {args=}')
env = {k:v for k,v in self.run_ns.items() if k not in ['params_kw', 'request'] }
debug(f'{env=}')
if inspect.iscoroutinefunction(f):
return await f(request, params_kw, *args, **self.run_ns)
return f(request, params_kw, *args, **self.run_ns)
return await f(request, params_kw, *args, **env)
return f(request, params_kw, *args, **env)
async def datahandle(self,request):
x = await self.path_call(request)

View File

@ -31,6 +31,7 @@ from appPublic.Singleton import SingletonDecorator
from appPublic.rc4 import password, unpassword
from appPublic.registerfunction import RegisterFunction
from appPublic.httpclient import HttpClient
from appPublic.log import debug, exception
from sqlor.dbpools import DBPools,runSQL,runSQLPaging
from sqlor.filter import DBFilter, default_filterjson
@ -56,13 +57,18 @@ async def stream_response(request, async_data_generator, content_type='text/html
res.content_type = content_type
await res.prepare(request)
async for d in async_data_generator():
if isinstance(d, bytes):
await res.write(d)
elif isinstance(d, str):
await res.write(d.encode('utf-8'))
else:
d = json.dumps(d, ensure_ascii=False)
await res.write(d.encode('utf-8'))
try:
if isinstance(d, bytes):
await res.write(d)
elif isinstance(d, str):
await res.write(d.encode('utf-8'))
else:
d = json.dumps(d, ensure_ascii=False)
await res.write(d.encode('utf-8'))
except Exception as e:
e = Exception(f'write error{e=}, {d=}')
exception(f'{e}\n{format_exc()}')
raise e
await res.drain()
await res.write_eof()
return res