diff --git a/ahserver/baseProcessor.py b/ahserver/baseProcessor.py index 327d92c..3d34873 100644 --- a/ahserver/baseProcessor.py +++ b/ahserver/baseProcessor.py @@ -149,7 +149,7 @@ class TemplateProcessor(BaseProcessor): async def path_call(self, request, params={}): await self.set_run_env(request, params=params) - path = request.path + path = params.get('path', request.path) ns = self.run_ns te = self.run_ns['tmpl_engine'] return await te.render(path,**ns) @@ -197,7 +197,8 @@ class BricksUIProcessor(TemplateProcessor): entire_url = self.run_ns.get('entire_url') content0 = await self.resource.path_call(request,entire_url('/bricks/header.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): @classmethod @@ -218,7 +219,8 @@ class PythonScriptProcessor(BaseProcessor): await self.set_run_env(request, params=params) lenv = self.run_ns 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) exec(txt,lenv,lenv) func = lenv['myfunc'] diff --git a/ahserver/dsProcessor.py b/ahserver/dsProcessor.py index 02e97da..ea725a4 100644 --- a/ahserver/dsProcessor.py +++ b/ahserver/dsProcessor.py @@ -50,7 +50,7 @@ class DataSourceProcessor(BaseProcessor): } return ret - async def path_call(self, request, path): + async def path_call(self, request, path, params={}): dict_data = {} config = getConfig() async with aiofiles.open(path,'r',encoding=config.website.coding) as f: diff --git a/ahserver/filedownload.py b/ahserver/filedownload.py index 64d55f3..0e4b16b 100644 --- a/ahserver/filedownload.py +++ b/ahserver/filedownload.py @@ -38,10 +38,10 @@ async def file_handle(request, filepath, download=False): async def file_download(request, filepath): return await file_handle(request, filepath, download=True) -async def path_download(request, kw, *params): - path = kw.get('path') +async def path_download(request, params_kw, *params, **kw): + path = params_kw.get('path') download = False - if kw.get('download'): + if params_kw.get('download'): download = True fs = FileStorage() fp = fs.realPath(path) diff --git a/ahserver/functionProcessor.py b/ahserver/functionProcessor.py index 41d1355..7323e4e 100644 --- a/ahserver/functionProcessor.py +++ b/ahserver/functionProcessor.py @@ -16,10 +16,11 @@ class FunctionProcessor(BaseProcessor): self.config_opts = opts 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) 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 = [] if len(path1) > 0: if path1[0] == '/': @@ -34,8 +35,8 @@ class FunctionProcessor(BaseProcessor): if f is None: error(f'{rfname=} is not registered, {rf.registKW=}') return None - self.run_ns['request'] = request - globals().update(self.run_ns) + # self.run_ns['request'] = request + # globals().update(self.run_ns) debug(f'params_kw={params_kw}, {args=}') if inspect.iscoroutinefunction(f): diff --git a/ahserver/processorResource.py b/ahserver/processorResource.py index fedf3c7..5f31a73 100644 --- a/ahserver/processorResource.py +++ b/ahserver/processorResource.py @@ -463,11 +463,12 @@ class ProcessorResource(StaticResource,Url2File): async def path_call(self, request, path, params={}): url = self.entireUrl(request, path) - # print(f'{path=}, after entireUrl(), {url=}') + debug(f'{path=}, after entireUrl(), {url=}') path = self.url2path(url) fpath = self.url2file(path) processor = self.url2processor(request, path, fpath) - # print(f'path_call(), {path=}, {url=}, {fpath=}, {processor=}, {self._prepath}') - new_request = request.clone(rel_url=path) - return await processor.be_call(new_request, params=params) + debug(f'path_call(), {path=}, {url=}, {fpath=}, {processor=}, {self._prepath}') + params['path'] = path + params['fpath'] = fpath + return await processor.be_call(request, params=params) diff --git a/ahserver/proxyProcessor.py b/ahserver/proxyProcessor.py index 2e7dd26..a09e2f2 100644 --- a/ahserver/proxyProcessor.py +++ b/ahserver/proxyProcessor.py @@ -1,5 +1,6 @@ import aiohttp from appPublic.log import info, debug, warning, error, critical, exception +# from appPublic.streamhttpclient import StreamHttpClient from aiohttp import web, BasicAuth from aiohttp import client from .baseProcessor import * @@ -11,7 +12,7 @@ class ProxyProcessor(BaseProcessor): async def path_call(self, request, params={}): await self.set_run_env(request) - path = self.path + path = params.get('path', request.path) url = self.resource.entireUrl(request, path) ns = self.run_ns ns.update(params) @@ -33,6 +34,7 @@ class ProxyProcessor(BaseProcessor): params = None if d.get('params'): params = params + async with client.request( d.get('method', request.method), d['url'], diff --git a/ahserver/webapp.py b/ahserver/webapp.py index 12aef42..7a8f625 100644 --- a/ahserver/webapp.py +++ b/ahserver/webapp.py @@ -14,9 +14,9 @@ def webapp(init_func): args = parser.parse_args() workdir = args.workdir or os.getcwd() port = args.port - server(init_func, workdir, port) + webserver(init_func, workdir, port) -def server(init_func, workdir, port=None): +def webserver(init_func, workdir, port=None): p = ProgramPath() config = getConfig(workdir, NS={'workdir':workdir, 'ProgramPath':p}) if config.logger: