checkifchange
This commit is contained in:
parent
df7e6351f9
commit
816173be58
@ -58,7 +58,14 @@ class BaseProcessor:
|
||||
|
||||
|
||||
async def handle(self,request):
|
||||
config = getConfig()
|
||||
g = ServerEnv()
|
||||
self.run_ns = DictObject()
|
||||
self.run_ns.update(g)
|
||||
self.run_ns.update(self.resource.y_env)
|
||||
self.run_ns.request = request
|
||||
self.run_ns.ref_real_path = self.path
|
||||
ns = self.resource.y_env.request2ns()
|
||||
self.run_ns.update(ns)
|
||||
await self.datahandle(request)
|
||||
if self.retResponse is not None:
|
||||
return self.retResponse
|
||||
@ -71,7 +78,7 @@ class BaseProcessor:
|
||||
self.setheaders()
|
||||
return Response(text=self.content,headers=self.headers)
|
||||
|
||||
async def datahandle(self,txt,request):
|
||||
async def datahandle(self,request):
|
||||
print('*******Error*************')
|
||||
self.content=''
|
||||
|
||||
@ -85,12 +92,7 @@ class TemplateProcessor(BaseProcessor):
|
||||
|
||||
async def datahandle(self,request):
|
||||
path = request.path
|
||||
g = ServerEnv()
|
||||
ns = DictObject()
|
||||
ns.update(g)
|
||||
ns.update(self.resource.y_env)
|
||||
ns.request = request
|
||||
ns.ref_real_path = self.path
|
||||
ns = self.run_ns
|
||||
te = g.tmpl_engine
|
||||
self.content = te.render(path,**ns)
|
||||
#self.content = await te.render_async(path,**ns)
|
||||
@ -122,9 +124,7 @@ class PythonScriptProcessor(BaseProcessor):
|
||||
|
||||
async def datahandle(self,request):
|
||||
g = ServerEnv()
|
||||
lenv = {}
|
||||
lenv.update(g)
|
||||
lenv.update(self.resource.y_env)
|
||||
lenv = self.run_ns
|
||||
if not g.get('dspy_cache',False):
|
||||
g.dspy_cache = ObjectCache()
|
||||
func = g.dspy_cache.get(self.path)
|
||||
|
@ -55,11 +55,7 @@ class DataSourceProcessor(BaseProcessor):
|
||||
with codecs.open(self.path,'r',config.website.coding) as f:
|
||||
b = f.read()
|
||||
dict_data = json.loads(b)
|
||||
ns = DictObject()
|
||||
g = ServerEnv()
|
||||
ns.update(g)
|
||||
ns.update(self.resource.y_env)
|
||||
ns.update(self.resource.getGetArgs(request))
|
||||
ns = self.run_ns
|
||||
act = ns.get('action','getdata')
|
||||
action = self.actions.get(act)
|
||||
self.content = action(dict_data,ns,request)
|
||||
|
@ -1,35 +0,0 @@
|
||||
from PIL import Image
|
||||
from io import BytesIO
|
||||
|
||||
def imageThumb(imgfilepath,width=None,height=None):
|
||||
im = Image.open(imgfilepath)
|
||||
mode = im.mode
|
||||
if mode not in ('L', 'RGB'):
|
||||
if mode == 'RGBA':
|
||||
alpha = im.split()[3]
|
||||
bgmask = alpha.point(lambda x: 255-x)
|
||||
im = im.convert('RGB')
|
||||
# paste(color, box, mask)
|
||||
im.paste((255,255,255), None, bgmask)
|
||||
else:
|
||||
im = im.convert('RGB')
|
||||
|
||||
w, h = im.size
|
||||
if not width and not height:
|
||||
width = 256
|
||||
if width:
|
||||
height = int(float(width) * float(h) / float(w))
|
||||
else:
|
||||
width = int(float(height) * float(w) / float(h))
|
||||
thumb = im.resize((width,height),Image.ANTIALIAS)
|
||||
f = BytesIO()
|
||||
thumb.save(f,format='jpeg',quality=60)
|
||||
im.close()
|
||||
v = f.getvalue()
|
||||
with open('thumb.jpg','wb') as x:
|
||||
x.write(v)
|
||||
return v
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
imageThumb("/home/ymq/media/pictures/2019-08/IMG_20190804_113014.jpg", width=256)
|
@ -6,11 +6,11 @@ from aiohttp.web_urldispatcher import Optional, _ExpectHandler
|
||||
from aiohttp.web_urldispatcher import Path
|
||||
from aiohttp.web_response import Response, StreamResponse
|
||||
from aiohttp.web_exceptions import (
|
||||
HTTPException,
|
||||
HTTPExpectationFailed,
|
||||
HTTPForbidden,
|
||||
HTTPMethodNotAllowed,
|
||||
HTTPNotFound,
|
||||
HTTPException,
|
||||
HTTPExpectationFailed,
|
||||
HTTPForbidden,
|
||||
HTTPMethodNotAllowed,
|
||||
HTTPNotFound,
|
||||
)
|
||||
from aiohttp.web_fileresponse import FileResponse
|
||||
from aiohttp.web_request import Request
|
||||
@ -24,6 +24,7 @@ from appPublic.dictObject import DictObject, multiDict2Dict
|
||||
from .baseProcessor import getProcessor
|
||||
from .xlsxdsProcessor import XLSXDataSourceProcessor
|
||||
from .sqldsProcessor import SQLDataSourceProcessor
|
||||
from .functionProcessor import FunctionProcessor
|
||||
from .serverenv import ServerEnv
|
||||
from .url2file import Url2File
|
||||
from .filestorage import FileStorage
|
||||
@ -45,18 +46,18 @@ def i18nDICT(request):
|
||||
|
||||
class ProcessorResource(StaticResource):
|
||||
def __init__(self, prefix: str, directory: PathLike,
|
||||
*, name: Optional[str]=None,
|
||||
expect_handler: Optional[_ExpectHandler]=None,
|
||||
chunk_size: int=256 * 1024,
|
||||
show_index: bool=False, follow_symlinks: bool=False,
|
||||
append_version: bool=False)-> None:
|
||||
*, name: Optional[str]=None,
|
||||
expect_handler: Optional[_ExpectHandler]=None,
|
||||
chunk_size: int=256 * 1024,
|
||||
show_index: bool=False, follow_symlinks: bool=False,
|
||||
append_version: bool=False)-> None:
|
||||
super().__init__(prefix, directory,
|
||||
name=name,
|
||||
expect_handler=expect_handler,
|
||||
chunk_size=chunk_size,
|
||||
show_index=show_index,
|
||||
name=name,
|
||||
expect_handler=expect_handler,
|
||||
chunk_size=chunk_size,
|
||||
show_index=show_index,
|
||||
follow_symlinks=follow_symlinks,
|
||||
append_version=append_version)
|
||||
append_version=append_version)
|
||||
gr = self._routes.get('GET')
|
||||
self._routes.update({'POST':gr})
|
||||
self._routes.update({'PUT':gr})
|
||||
@ -181,9 +182,14 @@ class ProcessorResource(StaticResource):
|
||||
raise HTTPNotFound
|
||||
dp = '/'.join(pp)
|
||||
path = path_decode(dp)
|
||||
print('path=',path)
|
||||
return await file_download(request, path)
|
||||
|
||||
if config.website.startswiths:
|
||||
for a in config.website.startswiths:
|
||||
if path.startswith(a.leading):
|
||||
processor = FunctionProcessor(self.abspath(path),self,a)
|
||||
return await processor.handle(request)
|
||||
|
||||
for word, handlername in self.y_processors:
|
||||
if path.endswith(word):
|
||||
Klass = getProcessor(handlername)
|
||||
|
@ -63,7 +63,16 @@
|
||||
[".tmpl","tmpl"],
|
||||
[".dspy","dspy"],
|
||||
[".md","md"]
|
||||
]
|
||||
],
|
||||
"startswith":{
|
||||
"/thumb":{
|
||||
"registerfunction":"makeThumb",
|
||||
"options":{
|
||||
"width":256,
|
||||
"keep_ratio":1
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"langMapping":{
|
||||
"zh-Hans-CN":"zh-cn",
|
||||
|
Loading…
Reference in New Issue
Block a user