This commit is contained in:
yumoqing 2024-12-19 13:09:24 +08:00
parent 30150a2ea8
commit d063063364

View File

@ -33,8 +33,7 @@ from appPublic.httpclient import HttpClient
from sqlor.dbpools import DBPools,runSQL,runSQLPaging from sqlor.dbpools import DBPools,runSQL,runSQLPaging
from sqlor.filter import DBFilter, default_filterjson from sqlor.filter import DBFilter, default_filterjson
from sqlor.crud import CRUD from aiohttp.web import StreamResponse
from .xlsxData import XLSXData from .xlsxData import XLSXData
from .uriop import URIOp from .uriop import URIOp
@ -49,6 +48,22 @@ def basic_auth_headers(user, passwd):
"Authorization":ba.encode() "Authorization":ba.encode()
} }
async def stream_response(request, async_data_generator, content_type='text/html'):
res = StreamResponse()
res.content_type = content_type
res.set_status(200)
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)
await res.write(d.encode('utf-8'))
await res.write_eof()
return res
def data2xlsx(rows,headers=None): def data2xlsx(rows,headers=None):
wb = Workbook() wb = Workbook()
ws = wb.active ws = wb.active
@ -206,7 +221,6 @@ def initEnv():
g.data2xlsx = data2xlsx g.data2xlsx = data2xlsx
g.xlsxdata = XLSXData g.xlsxdata = XLSXData
g.openfile = openfile g.openfile = openfile
g.CRUD = CRUD
g.DBPools = DBPools g.DBPools = DBPools
g.DBFilter = DBFilter g.DBFilter = DBFilter
g.default_filterjson = default_filterjson g.default_filterjson = default_filterjson
@ -227,6 +241,7 @@ def initEnv():
g.basic_auth_headers = basic_auth_headers g.basic_auth_headers = basic_auth_headers
g.HttpClient = HttpClient g.HttpClient = HttpClient
g.rfexe = RegisterFunction().exe g.rfexe = RegisterFunction().exe
g.stream_response = stream_response
def set_builtins(): def set_builtins():
all_builtins = [ i for i in dir(builtins) if not i.startswith('_')] all_builtins = [ i for i in dir(builtins) if not i.startswith('_')]