Merge branch 'master' of git.kaiyuancloud.cn:yumoqing/apppublic
This commit is contained in:
commit
88fc36d7e3
@ -270,8 +270,10 @@ class JsonHttpAPI:
|
||||
jd = json.loads(a)
|
||||
await self.user_stream_func(jd)
|
||||
|
||||
async def chunk_handle(self, chunk, chunk_lead, chunk_end):
|
||||
return chunk
|
||||
|
||||
async def __call__(self, url, method='GET', ns={},
|
||||
stream=False,
|
||||
headerstmpl=None,
|
||||
paramstmpl=None,
|
||||
datatmpl=None,
|
||||
@ -279,6 +281,7 @@ class JsonHttpAPI:
|
||||
chunk_end="[done]",
|
||||
resptmpl=None):
|
||||
headers = None
|
||||
self.chunk_buffer = ''
|
||||
ns1 = self.env.copy()
|
||||
ns1.update(ns)
|
||||
if headerstmpl:
|
||||
@ -288,16 +291,11 @@ class JsonHttpAPI:
|
||||
if paramstmpl:
|
||||
params = json.loads(self.te.renders(paramstmpl, ns1))
|
||||
data = None
|
||||
stream = False
|
||||
if datatmpl:
|
||||
datadic = json.loads(self.te.renders(datatmpl, ns1))
|
||||
stream = atadic.get('stream', False)
|
||||
data = json.dumps(datadic, ensure_ascii=False)
|
||||
"""
|
||||
data = FormData()
|
||||
for k,v in datadic.items():
|
||||
data.add_field(k, v)
|
||||
headers['Content-Type'] = 'multipart/form-data'
|
||||
"""
|
||||
info(f'{data=},{ns=}, {headers=}')
|
||||
hc = HttpClient()
|
||||
async for d in self.hc(url, method=method,
|
||||
stream=stream,
|
||||
@ -306,11 +304,11 @@ class JsonHttpAPI:
|
||||
data=data):
|
||||
if stream:
|
||||
d = self.chunk_handle(d, chunk_leading, chunk_end)
|
||||
if isinstance(d, dict) and resptmpl:
|
||||
ds = self.te.renders(resptmpl, d)
|
||||
yield json.loads(ds)
|
||||
else:
|
||||
yield d
|
||||
if resptmpl:
|
||||
dic = json.loads(d)
|
||||
ns1.update(dic)
|
||||
d = self.te.renders(resptmpl, ns1)
|
||||
yield d
|
||||
|
||||
async def call(self, url, method='GET', ns={},
|
||||
stream_func=None,
|
||||
|
Loading…
Reference in New Issue
Block a user