Merge branch 'main' of git.opencomputing.cn:yumoqing/ahserver
This commit is contained in:
commit
acc717968c
24
README.md
24
README.md
@ -424,3 +424,27 @@ async with db.sqlorContext('dbname') as sor:
|
||||
|
||||
### classes
|
||||
* ArgsConvert
|
||||
|
||||
## Change logs
|
||||
|
||||
### 1.0.8
|
||||
#### server_error(errcode)
|
||||
add a new global function named "server_error(errcode)", it will raise a HTTPException, errcode should be one of:
|
||||
* 400 aiohttp.web.HTTPBadRequest 错误请求
|
||||
* 401 aiohttp.web.HTTPUnauthorized 未认证
|
||||
* 403 aiohttp.web.HTTPForbidden 禁止访问
|
||||
* 404 aiohttp.web.HTTPNotFound 未找到
|
||||
* 405 aiohttp.web.HTTPMethodNotAllowed 方法不允许
|
||||
* 408 aiohttp.web.HTTPRequestTimeout 请求超时
|
||||
* 409 aiohttp.web.HTTPConflict 冲突
|
||||
* 410 aiohttp.web.HTTPGone 已删除
|
||||
* 415 aiohttp.web.HTTPUnsupportedMediaType 不支持的媒体类型
|
||||
* 429 aiohttp.web.HTTPTooManyRequests 请求过多
|
||||
* 500 aiohttp.web.HTTPInternalServerError 服务器错误
|
||||
* 502 aiohttp.web.HTTPBadGateway 错误网关
|
||||
* 503 aiohttp.web.HTTPServiceUnavailable 服务不可用
|
||||
|
||||
else it will raise HTTPException exception
|
||||
#### request._run_ns
|
||||
global environment now can access from request._run_ns, it contains all the globals variable in ServerEnv and related variables of request
|
||||
|
||||
|
||||
@ -80,6 +80,8 @@ class BaseProcessor:
|
||||
self.run_ns['ref_real_path'] = self.real_path
|
||||
self.run_ns['processor'] = self
|
||||
self.env_set = True
|
||||
request['run_ns'] = self.run_ns
|
||||
request._run_ns = self.run_ns
|
||||
|
||||
async def execute(self,request):
|
||||
await self.set_run_env(request)
|
||||
|
||||
@ -7,8 +7,25 @@ from urllib.parse import quote
|
||||
import json
|
||||
import asyncio
|
||||
from aiohttp import BasicAuth
|
||||
from aiohttp.web import (
|
||||
HTTPException,
|
||||
HTTPBadRequest,
|
||||
HTTPUnauthorized,
|
||||
HTTPForbidden,
|
||||
HTTPNotFound,
|
||||
HTTPMethodNotAllowed,
|
||||
HTTPRequestTimeout,
|
||||
HTTPConflict,
|
||||
HTTPGone,
|
||||
HTTPUnsupportedMediaType,
|
||||
HTTPTooManyRequests,
|
||||
HTTPInternalServerError,
|
||||
HTTPBadGateway,
|
||||
HTTPServiceUnavailable
|
||||
)
|
||||
from traceback import format_exc
|
||||
from functools import partial
|
||||
from aiohttp_session import get_session
|
||||
|
||||
import random
|
||||
import time
|
||||
@ -46,6 +63,25 @@ from .filedownload import path_download, file_download
|
||||
from .filestorage import FileStorage
|
||||
from .serverenv import ServerEnv
|
||||
|
||||
def server_error(errcode):
|
||||
exceptions = {
|
||||
400: HTTPBadRequest,
|
||||
401: HTTPUnauthorized,
|
||||
403: HTTPForbidden,
|
||||
404: HTTPNotFound,
|
||||
405: HTTPMethodNotAllowed,
|
||||
408: HTTPRequestTimeout,
|
||||
409: HTTPConflict,
|
||||
410: HTTPGone,
|
||||
415: HTTPUnsupportedMediaType,
|
||||
429: HTTPTooManyRequests,
|
||||
500: HTTPInternalServerError,
|
||||
502: HTTPBadGateway,
|
||||
503: HTTPServiceUnavailable
|
||||
}
|
||||
E = exceptions.get(errcode, HTTPException)
|
||||
raise E()
|
||||
|
||||
def basic_auth_headers(user, passwd):
|
||||
ba = BasicAuth(login=user, password=passwd)
|
||||
return {
|
||||
@ -275,6 +311,7 @@ def initEnv():
|
||||
g.path_download = path_download
|
||||
g.partial = partial
|
||||
g.StreamHttpClient = StreamHttpClient
|
||||
g.server_error = server_error
|
||||
|
||||
def set_builtins():
|
||||
all_builtins = [ i for i in dir(builtins) if not i.startswith('_')]
|
||||
|
||||
@ -24,7 +24,7 @@ class XtermProcessor(PythonScriptProcessor):
|
||||
async def ws_2_process(self, ws):
|
||||
async for msg in ws:
|
||||
if msg.type == aiohttp.WSMsgType.TEXT:
|
||||
# debug(f'recv from ws:{msg}.................')
|
||||
debug(f'recv from ws:{msg}.................')
|
||||
data = DictObject(**json.loads(msg.data))
|
||||
if data.type == 'input':
|
||||
self.p_obj.stdin.write(data.data)
|
||||
@ -34,7 +34,8 @@ class XtermProcessor(PythonScriptProcessor):
|
||||
try:
|
||||
debug(f'{data=}')
|
||||
#self.p_obj._chan.change_terminal_size(data.rows, data.cols, data.width, data.height)
|
||||
self.p_obj._chan.change_terminal_size(data.rows, data.cols)
|
||||
# self.p_obj._chan.change_terminal_size(data.rows, data.cols)
|
||||
self.p_obj._chan.change_terminal_size(data.cols, data.rows)
|
||||
except Exception as e:
|
||||
exception(f'{data=}, {e=}, {format_exc()}')
|
||||
|
||||
@ -84,6 +85,7 @@ class XtermProcessor(PythonScriptProcessor):
|
||||
r1 = self.ws_2_process(ws)
|
||||
r2 = self.process_2_ws(ws)
|
||||
await asyncio.gather(r1,r2)
|
||||
debug(f'run_xterm() ended')
|
||||
|
||||
async def ws_send_heartbeat(self, ws):
|
||||
dic = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user