From 36f809a6c35dc201581a7814148d54f4e64de2e3 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 28 Jul 2025 12:13:17 +0800 Subject: [PATCH 01/11] bugfix --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index ba2d167..8ff17f0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,7 @@ # setup.cfg [metadata] name = ahserver -version = 1.0.6 +version = 1.0.7 description = A application server base on aiohttp author = yu moqing author_email = yumoqing@gmail.com From d1eaafa42baeda437100066d5bec124d64716354 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 18 Aug 2025 13:13:58 +0800 Subject: [PATCH 02/11] bugfix --- ahserver/xtermProcessor.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ahserver/xtermProcessor.py b/ahserver/xtermProcessor.py index daa4bac..4cce857 100644 --- a/ahserver/xtermProcessor.py +++ b/ahserver/xtermProcessor.py @@ -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) @@ -49,6 +49,7 @@ class XtermProcessor(PythonScriptProcessor): try: while self.running: x = await self.p_obj.stdout.read(1024) + debug(f'{x=}') await self.ws_send_data(ws, x) await asyncio.sleep(0) finally: @@ -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 = { From 8d1bafcd6afa97b631a2f86831ca20362a763fdc Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 18 Aug 2025 17:24:45 +0800 Subject: [PATCH 03/11] bugfix --- ahserver/xtermProcessor.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ahserver/xtermProcessor.py b/ahserver/xtermProcessor.py index 4cce857..531c0cf 100644 --- a/ahserver/xtermProcessor.py +++ b/ahserver/xtermProcessor.py @@ -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()}') From 0b68a3d06b084adf8972d4a461af064a9be47278 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 20 Aug 2025 14:17:27 +0800 Subject: [PATCH 04/11] bugfix --- ahserver/baseProcessor.py | 1 + ahserver/globalEnv.py | 36 ++++++++++++++++++++++++++++++++++++ setup.cfg | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/ahserver/baseProcessor.py b/ahserver/baseProcessor.py index 3d34873..9b1d133 100644 --- a/ahserver/baseProcessor.py +++ b/ahserver/baseProcessor.py @@ -80,6 +80,7 @@ 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 async def execute(self,request): await self.set_run_env(request) diff --git a/ahserver/globalEnv.py b/ahserver/globalEnv.py index 6567ff0..738640b 100644 --- a/ahserver/globalEnv.py +++ b/ahserver/globalEnv.py @@ -7,6 +7,22 @@ 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 @@ -46,6 +62,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 +310,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('_')] diff --git a/setup.cfg b/setup.cfg index 8ff17f0..efddaa3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,7 @@ # setup.cfg [metadata] name = ahserver -version = 1.0.7 +version = 1.0.8 description = A application server base on aiohttp author = yu moqing author_email = yumoqing@gmail.com From b5d8ab9829b7dc716bf18a1c204122c5e80ea396 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 20 Aug 2025 14:24:37 +0800 Subject: [PATCH 05/11] bugfix --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 77805e4..675b4af 100755 --- a/README.md +++ b/README.md @@ -424,3 +424,26 @@ 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 + From 449dbb17acd13db408ce05dd6110772134058a79 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 20 Aug 2025 14:27:07 +0800 Subject: [PATCH 06/11] bugfix --- README.md | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 675b4af..84914c8 100755 --- a/README.md +++ b/README.md @@ -430,19 +430,20 @@ async with db.sqlorContext('dbname') as sor: ### 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 服务不可用 +* 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 From e5d6fb4d15721bc9698341cfa528613fe089d566 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 22 Aug 2025 13:44:10 +0800 Subject: [PATCH 07/11] bugfix --- README.md | 17 +++++++++++++++++ ahserver/globalEnv.py | 8 ++++++++ 2 files changed, 25 insertions(+) diff --git a/README.md b/README.md index 84914c8..e2c6b7d 100755 --- a/README.md +++ b/README.md @@ -448,3 +448,20 @@ 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 +### 1.0.9 + +#### MySession class +add MySession class for script to get or set data to session + +usage + +``` +s = MySession(request) +messages = s.messages +if not messages: + messages = [] +messages.append("ergegrtgh") +s.messages = messages +``` + + diff --git a/ahserver/globalEnv.py b/ahserver/globalEnv.py index 738640b..fff22d5 100644 --- a/ahserver/globalEnv.py +++ b/ahserver/globalEnv.py @@ -25,6 +25,7 @@ from aiohttp.web import ( ) from traceback import format_exc from functools import partial +from aiohttp_session import get_session import random import time @@ -81,6 +82,12 @@ def server_error(errcode): E = exceptions.get(errcode, HTTPException) raise E() +class MySession(DictObject): + def __init__(self, request, **kw): + super().__init__(**kw) + self.request = request + self.update(get_session(request)) + def basic_auth_headers(user, passwd): ba = BasicAuth(login=user, password=passwd) return { @@ -311,6 +318,7 @@ def initEnv(): g.partial = partial g.StreamHttpClient = StreamHttpClient g.server_error = server_error + g.MySession = MySession def set_builtins(): all_builtins = [ i for i in dir(builtins) if not i.startswith('_')] From a4602f21751c0670a7db0bcf088439c5a89db282 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 22 Aug 2025 15:57:35 +0800 Subject: [PATCH 08/11] bugfix --- README.md | 17 ----------------- ahserver/globalEnv.py | 7 ------- 2 files changed, 24 deletions(-) diff --git a/README.md b/README.md index e2c6b7d..84914c8 100755 --- a/README.md +++ b/README.md @@ -448,20 +448,3 @@ 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 -### 1.0.9 - -#### MySession class -add MySession class for script to get or set data to session - -usage - -``` -s = MySession(request) -messages = s.messages -if not messages: - messages = [] -messages.append("ergegrtgh") -s.messages = messages -``` - - diff --git a/ahserver/globalEnv.py b/ahserver/globalEnv.py index fff22d5..07b1904 100644 --- a/ahserver/globalEnv.py +++ b/ahserver/globalEnv.py @@ -82,12 +82,6 @@ def server_error(errcode): E = exceptions.get(errcode, HTTPException) raise E() -class MySession(DictObject): - def __init__(self, request, **kw): - super().__init__(**kw) - self.request = request - self.update(get_session(request)) - def basic_auth_headers(user, passwd): ba = BasicAuth(login=user, password=passwd) return { @@ -318,7 +312,6 @@ def initEnv(): g.partial = partial g.StreamHttpClient = StreamHttpClient g.server_error = server_error - g.MySession = MySession def set_builtins(): all_builtins = [ i for i in dir(builtins) if not i.startswith('_')] From e76f66878a26fac3483f8a704617e25fd0bd8903 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sun, 24 Aug 2025 10:53:35 +0800 Subject: [PATCH 09/11] bugfix --- ahserver/baseProcessor.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ahserver/baseProcessor.py b/ahserver/baseProcessor.py index 9b1d133..b9ffe9b 100644 --- a/ahserver/baseProcessor.py +++ b/ahserver/baseProcessor.py @@ -81,6 +81,7 @@ class BaseProcessor: 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) From 45791520825e4672a2df287b8cb33a6a61e7bff1 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 25 Aug 2025 10:54:07 +0800 Subject: [PATCH 10/11] bugfix --- README.md | 4 ++-- setup.cfg | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 84914c8..4efae97 100755 --- a/README.md +++ b/README.md @@ -445,6 +445,6 @@ add a new global function named "server_error(errcode)", it will raise a HTTPExc * 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 +#### 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 diff --git a/setup.cfg b/setup.cfg index efddaa3..06e3d25 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,7 @@ # setup.cfg [metadata] name = ahserver -version = 1.0.8 +version = 1.0.9 description = A application server base on aiohttp author = yu moqing author_email = yumoqing@gmail.com From 6f5d19b08f62c3c3a00dc94d4dce3f85d2063110 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 27 Aug 2025 11:24:37 +0800 Subject: [PATCH 11/11] bugfix --- ahserver/xtermProcessor.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ahserver/xtermProcessor.py b/ahserver/xtermProcessor.py index 531c0cf..d62d627 100644 --- a/ahserver/xtermProcessor.py +++ b/ahserver/xtermProcessor.py @@ -50,7 +50,6 @@ class XtermProcessor(PythonScriptProcessor): try: while self.running: x = await self.p_obj.stdout.read(1024) - debug(f'{x=}') await self.ws_send_data(ws, x) await asyncio.sleep(0) finally: