bugfix
This commit is contained in:
parent
7ec7e69f4e
commit
2d7c413ed9
@ -2,6 +2,7 @@ import os
|
||||
import re
|
||||
import json
|
||||
import codecs
|
||||
import aiofiles
|
||||
from aiohttp.web_request import Request
|
||||
from aiohttp.web_response import Response, StreamResponse
|
||||
|
||||
@ -168,10 +169,10 @@ class PythonScriptProcessor(BaseProcessor):
|
||||
def isMe(self,name):
|
||||
return name=='dspy'
|
||||
|
||||
def loadScript(self, path):
|
||||
async def loadScript(self, path):
|
||||
data = ''
|
||||
with codecs.open(path,'rb','utf-8') as f:
|
||||
data = f.read()
|
||||
async with aiofiles.open(path,'r', encoding='utf-8') as f:
|
||||
data = await f.read()
|
||||
b= ''.join(data.split('\r'))
|
||||
lines = b.split('\n')
|
||||
lines = ['\t' + l for l in lines ]
|
||||
@ -182,7 +183,7 @@ class PythonScriptProcessor(BaseProcessor):
|
||||
await self.set_run_env(request, params=params)
|
||||
lenv = self.run_ns
|
||||
del lenv['request']
|
||||
txt = self.loadScript(self.real_path)
|
||||
txt = await self.loadScript(self.real_path)
|
||||
# print(self.real_path, "#########", txt)
|
||||
exec(txt,lenv,lenv)
|
||||
func = lenv['myfunc']
|
||||
@ -198,8 +199,8 @@ class MarkdownProcessor(BaseProcessor):
|
||||
|
||||
async def datahandle(self,request:Request):
|
||||
data = ''
|
||||
with codecs.open(self.real_path,'rb','utf-8') as f:
|
||||
data = f.read()
|
||||
async with aiofiles.open(self.real_path,'r',encoding='utf-8') as f:
|
||||
data = await f.read()
|
||||
self.content = self.urlreplace(data, request)
|
||||
|
||||
def urlreplace(self,mdtxt,request):
|
||||
|
@ -1,5 +1,6 @@
|
||||
import codecs
|
||||
import json
|
||||
import aiofiles
|
||||
from appPublic.jsonConfig import getConfig
|
||||
from appPublic.dictObject import DictObject
|
||||
from .baseProcessor import BaseProcessor
|
||||
@ -52,8 +53,8 @@ class DataSourceProcessor(BaseProcessor):
|
||||
async def path_call(self, request, path):
|
||||
dict_data = {}
|
||||
config = getConfig()
|
||||
with codecs.open(path,'r',config.website.coding) as f:
|
||||
b = f.read()
|
||||
async with aiofiles.open(path,'r',encoding=config.website.coding) as f:
|
||||
b = await f.read()
|
||||
dict_data = json.loads(b)
|
||||
ns = self.run_ns
|
||||
act = ns.get('action','getdata')
|
||||
|
@ -1,6 +1,7 @@
|
||||
import os
|
||||
import re
|
||||
import codecs
|
||||
import aiofiles
|
||||
from traceback import print_exc
|
||||
# from showcallstack import showcallstack
|
||||
|
||||
@ -303,7 +304,7 @@ class ProcessorResource(AppLogger, StaticResource,Url2File):
|
||||
if processor:
|
||||
return await processor.handle(request)
|
||||
|
||||
if self.request_filename and self.isHtml(self.request_filename):
|
||||
if self.request_filename and await self.isHtml(self.request_filename):
|
||||
return await self.html_handle(request, self.request_filename)
|
||||
|
||||
if self.request_filename and os.path.isdir(self.request_filename):
|
||||
@ -324,10 +325,8 @@ class ProcessorResource(AppLogger, StaticResource,Url2File):
|
||||
return '/'.join(str(request.url).split('/')[:3])
|
||||
|
||||
async def html_handle(self,request,filepath):
|
||||
with open(filepath,'rb') as f:
|
||||
b = f.read()
|
||||
utxt = b.decode('unicode_escape')
|
||||
txt = b.decode('utf-8')
|
||||
async with aiofiles.open(filepath,'r', encoding='utf-8') as f:
|
||||
txt = await f.read()
|
||||
headers = {
|
||||
'Content-Type': 'text/html; utf-8',
|
||||
'Accept-Ranges': 'bytes',
|
||||
@ -336,10 +335,10 @@ class ProcessorResource(AppLogger, StaticResource,Url2File):
|
||||
resp = Response(text=txt,headers=headers)
|
||||
return resp
|
||||
|
||||
def isHtml(self,fn):
|
||||
async def isHtml(self,fn):
|
||||
try:
|
||||
with codecs.open(fn,'r','utf-8') as f:
|
||||
b = f.read()
|
||||
async with aiofiles.open(fn,'r',encoding='utf-8') as f:
|
||||
b = await f.read()
|
||||
while b[0] in ['\n',' ','\t']:
|
||||
b = b[1:]
|
||||
if b.lower().startswith('<html>'):
|
||||
|
@ -1,5 +1,6 @@
|
||||
import asyncio
|
||||
import aiohttp
|
||||
import aiofiles
|
||||
import json
|
||||
import codecs
|
||||
from aiohttp import web
|
||||
@ -43,14 +44,15 @@ class XtermProcessor(BaseProcessor):
|
||||
self.retResponse = ws
|
||||
return ws
|
||||
|
||||
def get_login_info(self):
|
||||
with codecs.open(self.real_path, 'r', 'utf-8') as f:
|
||||
self.login_info = json.load(f)
|
||||
async def get_login_info(self):
|
||||
async with aiofiles.open(self.real_path, 'r', encoding='utf-8') as f:
|
||||
txt = await f.read()
|
||||
self.login_info = json.loads(txt)
|
||||
print(f'{self.login_info=}')
|
||||
|
||||
async def create_process(self):
|
||||
# id = lenv['params_kw'].get('termid')
|
||||
self.get_login_info()
|
||||
await self.get_login_info()
|
||||
host = self.login_info['host']
|
||||
port = self.login_info.get('port', 22)
|
||||
username = self.login_info.get('username', 'root')
|
||||
|
@ -5,6 +5,7 @@ cchardet
|
||||
aiohttp
|
||||
aiohttp_session
|
||||
aiohttp_auth_autz
|
||||
aiohttp-cors
|
||||
aiomysql
|
||||
aioredis
|
||||
psycopg2-binary
|
||||
|
Loading…
Reference in New Issue
Block a user