This commit is contained in:
yumoqing 2020-12-18 14:25:46 +08:00
parent 175a497493
commit 1028c20c08
2 changed files with 9 additions and 11 deletions

View File

@ -1,5 +1,6 @@
import os import os
import re import re
import codecs
from traceback import print_exc from traceback import print_exc
import asyncio import asyncio
@ -238,7 +239,7 @@ class ProcessorResource(StaticResource,Url2File):
filepath = self.url2file(str(request.url)) filepath = self.url2file(str(request.url))
print('filepath=',filepath,str(request.url)) print('filepath=',filepath,str(request.url))
if filepath and self.isHtml(filepath): 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..') print(f'path={path} handler by StaticResource..')
if self.isFolder(path): if self.isFolder(path):
@ -247,7 +248,7 @@ class ProcessorResource(StaticResource,Url2File):
raise HTTPNotFound raise HTTPNotFound
return await super()._handle(request) 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: with codecs.open(filepath,'r', 'utf-8') as f:
b = f.read() b = f.read()
b = unicode_escape(b) b = unicode_escape(b)
@ -265,7 +266,7 @@ class ProcessorResource(StaticResource,Url2File):
b = f.read() b = f.read()
if b.startswith('<html>'): if b.startswith('<html>'):
return True return True
if b.stratswith('<!doctype html>'): if b.startswith('<!doctype html>'):
return True return True
except Exception as e: except Exception as e:
print_exc() print_exc()

View File

@ -51,14 +51,12 @@ class Url2File:
if url[-1] == '/': if url[-1] == '/':
url = url[:-1] url = url[:-1]
print('url2file.py:self.starts=',self.starts) paths = url.split('/')[3:]
if url.startswith(self.starts): f = os.path.join(self.path,*paths)
f = self.path + url[len(self.starts):] real_path = os.path.abspath(f)
real_path = os.path.abspath(f)
if os.path.isdir(real_path): if os.path.isdir(real_path):
for f in self.indexes: for idx in self.indexes:
p = os.path.join(real_path,'f) p = os.path.join(real_path,idx)
if os.path.isfile(p): if os.path.isfile(p):
return p return p
@ -66,7 +64,6 @@ class Url2File:
return real_path return real_path
if not self.inherit: if not self.inherit:
print('url2file.py:real_path=',real_path)
return None return None
items = url.split('/') items = url.split('/')
if len(items) > 2: if len(items) > 2: