This commit is contained in:
ymq1 2025-06-11 07:57:13 +00:00
parent 5f7580d795
commit b8aeba79e8
5 changed files with 18 additions and 11 deletions

View File

@ -149,7 +149,7 @@ class TemplateProcessor(BaseProcessor):
async def path_call(self, request, params={}): async def path_call(self, request, params={}):
await self.set_run_env(request, params=params) await self.set_run_env(request, params=params)
path = request.path path = params.get('path', request.path)
ns = self.run_ns ns = self.run_ns
te = self.run_ns['tmpl_engine'] te = self.run_ns['tmpl_engine']
return await te.render(path,**ns) return await te.render(path,**ns)
@ -197,7 +197,8 @@ class BricksUIProcessor(TemplateProcessor):
entire_url = self.run_ns.get('entire_url') entire_url = self.run_ns.get('entire_url')
content0 = await self.resource.path_call(request,entire_url('/bricks/header.tmpl')) content0 = await self.resource.path_call(request,entire_url('/bricks/header.tmpl'))
content2 = await self.resource.path_call(request,entire_url('/bricks/footer.tmpl')) content2 = await self.resource.path_call(request,entire_url('/bricks/footer.tmpl'))
self.content = '%s%s%s' % (content0, txt, content2) self.content = f'{content0}{txt}{content2}'
debug(f'{len(txt)=}, {len(content0)=}, {len(content2)=}, {self.content=}')
class PythonScriptProcessor(BaseProcessor): class PythonScriptProcessor(BaseProcessor):
@classmethod @classmethod
@ -218,7 +219,8 @@ class PythonScriptProcessor(BaseProcessor):
await self.set_run_env(request, params=params) await self.set_run_env(request, params=params)
lenv = self.run_ns lenv = self.run_ns
del lenv['request'] del lenv['request']
txt = await self.loadScript(self.real_path) fpath = params.get('fpath', self.real_path)
txt = await self.loadScript(fpath)
# print(self.real_path, "#########", txt) # print(self.real_path, "#########", txt)
exec(txt,lenv,lenv) exec(txt,lenv,lenv)
func = lenv['myfunc'] func = lenv['myfunc']

View File

@ -50,7 +50,7 @@ class DataSourceProcessor(BaseProcessor):
} }
return ret return ret
async def path_call(self, request, path): async def path_call(self, request, path, params={}):
dict_data = {} dict_data = {}
config = getConfig() config = getConfig()
async with aiofiles.open(path,'r',encoding=config.website.coding) as f: async with aiofiles.open(path,'r',encoding=config.website.coding) as f:

View File

@ -16,10 +16,11 @@ class FunctionProcessor(BaseProcessor):
self.config_opts = opts self.config_opts = opts
BaseProcessor.__init__(self,path,resource) BaseProcessor.__init__(self,path,resource)
async def path_call(self, request, path): async def path_call(self, request, params={}):
await self.set_run_env(request) await self.set_run_env(request)
parmas_kw = self.run_ns.get('params_kw') parmas_kw = self.run_ns.get('params_kw')
path1 = request.path[len(self.config_opts['leading']):] path = params.get('path', request.path)
path1 = path[len(self.config_opts['leading']):]
args = [] args = []
if len(path1) > 0: if len(path1) > 0:
if path1[0] == '/': if path1[0] == '/':
@ -34,8 +35,8 @@ class FunctionProcessor(BaseProcessor):
if f is None: if f is None:
error(f'{rfname=} is not registered, {rf.registKW=}') error(f'{rfname=} is not registered, {rf.registKW=}')
return None return None
self.run_ns['request'] = request # self.run_ns['request'] = request
globals().update(self.run_ns) # globals().update(self.run_ns)
debug(f'params_kw={params_kw}, {args=}') debug(f'params_kw={params_kw}, {args=}')
if inspect.iscoroutinefunction(f): if inspect.iscoroutinefunction(f):

View File

@ -463,10 +463,12 @@ class ProcessorResource(StaticResource,Url2File):
async def path_call(self, request, path, params={}): async def path_call(self, request, path, params={}):
url = self.entireUrl(request, path) url = self.entireUrl(request, path)
# print(f'{path=}, after entireUrl(), {url=}') debug(f'{path=}, after entireUrl(), {url=}')
path = self.url2path(url) path = self.url2path(url)
fpath = self.url2file(path) fpath = self.url2file(path)
processor = self.url2processor(request, path, fpath) processor = self.url2processor(request, path, fpath)
# print(f'path_call(), {path=}, {url=}, {fpath=}, {processor=}, {self._prepath}') debug(f'path_call(), {path=}, {url=}, {fpath=}, {processor=}, {self._prepath}')
params['path'] = path
params['fpath'] = fpath
return await processor.be_call(request, params=params) return await processor.be_call(request, params=params)

View File

@ -1,5 +1,6 @@
import aiohttp import aiohttp
from appPublic.log import info, debug, warning, error, critical, exception from appPublic.log import info, debug, warning, error, critical, exception
# from appPublic.streamhttpclient import StreamHttpClient
from aiohttp import web, BasicAuth from aiohttp import web, BasicAuth
from aiohttp import client from aiohttp import client
from .baseProcessor import * from .baseProcessor import *
@ -11,7 +12,7 @@ class ProxyProcessor(BaseProcessor):
async def path_call(self, request, params={}): async def path_call(self, request, params={}):
await self.set_run_env(request) await self.set_run_env(request)
path = self.path path = params.get('path', request.path)
url = self.resource.entireUrl(request, path) url = self.resource.entireUrl(request, path)
ns = self.run_ns ns = self.run_ns
ns.update(params) ns.update(params)
@ -33,6 +34,7 @@ class ProxyProcessor(BaseProcessor):
params = None params = None
if d.get('params'): if d.get('params'):
params = params params = params
async with client.request( async with client.request(
d.get('method', request.method), d.get('method', request.method),
d['url'], d['url'],