diff --git a/ahserver/processorResource.py b/ahserver/processorResource.py index f8a4d35..d272b41 100644 --- a/ahserver/processorResource.py +++ b/ahserver/processorResource.py @@ -1,5 +1,6 @@ import os import re +import codecs from traceback import print_exc import asyncio @@ -238,7 +239,7 @@ class ProcessorResource(StaticResource,Url2File): filepath = self.url2file(str(request.url)) print('filepath=',filepath,str(request.url)) if filepath and self.isHtml(filepath): - return await html_handle(request, filepath) + return await self.html_handle(request, filepath) print(f'path={path} handler by StaticResource..') if self.isFolder(path): @@ -247,7 +248,7 @@ class ProcessorResource(StaticResource,Url2File): raise HTTPNotFound return await super()._handle(request) - def html_handle(self,request,filepath): + async def html_handle(self,request,filepath): with codecs.open(filepath,'r', 'utf-8') as f: b = f.read() b = unicode_escape(b) @@ -265,7 +266,7 @@ class ProcessorResource(StaticResource,Url2File): b = f.read() if b.startswith(''): return True - if b.stratswith(''): + if b.startswith(''): return True except Exception as e: print_exc() diff --git a/ahserver/url2file.py b/ahserver/url2file.py index 5576f96..6bc03b5 100644 --- a/ahserver/url2file.py +++ b/ahserver/url2file.py @@ -51,14 +51,12 @@ class Url2File: if url[-1] == '/': url = url[:-1] - print('url2file.py:self.starts=',self.starts) - if url.startswith(self.starts): - f = self.path + url[len(self.starts):] - real_path = os.path.abspath(f) - + paths = url.split('/')[3:] + f = os.path.join(self.path,*paths) + real_path = os.path.abspath(f) if os.path.isdir(real_path): - for f in self.indexes: - p = os.path.join(real_path,'f) + for idx in self.indexes: + p = os.path.join(real_path,idx) if os.path.isfile(p): return p @@ -66,7 +64,6 @@ class Url2File: return real_path if not self.inherit: - print('url2file.py:real_path=',real_path) return None items = url.split('/') if len(items) > 2: