From 07c571116583e0fa93c1caef086f225ab3004896 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 5 Dec 2019 06:04:38 +0800 Subject: [PATCH] bugfix --- ahserver/configuredServer.py | 4 ++-- ahserver/myTE.py | 7 +++++-- ahserver/processorResource.py | 6 +++--- ahserver/url2file.py | 20 ++++++++++++++------ 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/ahserver/configuredServer.py b/ahserver/configuredServer.py index 6e32725..962379f 100644 --- a/ahserver/configuredServer.py +++ b/ahserver/configuredServer.py @@ -43,7 +43,7 @@ class ConfiguredServer: for p,prefix in config.website.paths: res = ProcessorResource(prefix,p,show_index=True, follow_symlinks=True, - indexs=configure.website.indexes, - processors=configure.website.processors) + indexes=config.website.indexes, + processors=config.website.processors) self.app.router.register_resource(res) diff --git a/ahserver/myTE.py b/ahserver/myTE.py index 0a3c6ef..66d251d 100644 --- a/ahserver/myTE.py +++ b/ahserver/myTE.py @@ -49,8 +49,11 @@ def setupTemplateEngine(): config = getConfig() subffixes = [ i[0] for i in config.website.processors if i[1] == 'tmpl' ] print(subffixes) - paths = [ os.path.abspath(p) for p,prefix in config.website.paths ] - loader = TmplLoader(paths,config.website.indexes,subffixes,inherit=True) + # paths = [ os.path.abspath(p) for p,prefix in config.website.paths ] + loader = TmplLoader(config.website.paths, + config.website.indexes, + subffixes, + inherit=True) engine = TemplateEngine(loader) g = ServerEnv() g.tmpl_engine = engine diff --git a/ahserver/processorResource.py b/ahserver/processorResource.py index 4edab77..d032910 100644 --- a/ahserver/processorResource.py +++ b/ahserver/processorResource.py @@ -52,7 +52,7 @@ class ProcessorResource(StaticResource,Url2File): show_index: bool=False, follow_symlinks: bool=False, append_version: bool=False, indexes:list=[], - processors:dict={}) None: + processors:dict={}) -> None: StaticResource.__init__(self,prefix, directory, name=name, expect_handler=expect_handler, @@ -67,10 +67,10 @@ class ProcessorResource(StaticResource,Url2File): self._routes.update({'OPTIONS':gr}) self._routes.update({'DELETE':gr}) self._routes.update({'TRACE':gr}) - self.y_processors = [] + self.y_processors = processors self.y_prefix = prefix self.y_directory = directory - self.y_indexes = [] + self.y_indexes = indexes self.y_env = DictObject() def setProcessors(self, processors): diff --git a/ahserver/url2file.py b/ahserver/url2file.py index 56a4e28..dfabf91 100644 --- a/ahserver/url2file.py +++ b/ahserver/url2file.py @@ -27,8 +27,8 @@ class Url2File: real_path = os.path.abspath(rp) if os.path.isdir(real_path): return True - else - return False + return False + def isFile(self,url:str) ->bool: if url.startswith(self.starts): @@ -36,8 +36,7 @@ class Url2File: real_path = os.path.abspath(rp) if os.path.isfile(real_path): return True - else - return False + return False def defaultIndex(self,url: str) -> str: @@ -87,12 +86,21 @@ class Url2File: class TmplUrl2File(Url2File): def __init__(self,paths,indexes, subffixes=['.tmpl'],inherit=False): - Url2File.__init__(self,paths,indexes=indexes,inherit=inherit) + self.paths = paths + self.u2fs = [ Url2File(p,prefix,indexes,inherit=inherit) \ + for p,prefix in paths ] self.subffixes = subffixes + def url2file(self,url): + for u2f in self.u2fs: + fp = u2f.url2file(url) + if fp: + return fp + return None + def list_tmpl(self): ret = [] - for rp in self.paths: + for rp,_ in self.paths: p = os.path.abspath(rp) [ ret.append(i) for i in listFile(p,suffixs=self.subffixes,rescursive=True) ] return sorted(ret)