This commit is contained in:
yumoqing 2025-08-22 13:44:10 +08:00
parent 449dbb17ac
commit e5d6fb4d15
2 changed files with 25 additions and 0 deletions

View File

@ -448,3 +448,20 @@ else it will raise HTTPException exception
#### request['run_ns'] #### 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 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
```

View File

@ -25,6 +25,7 @@ from aiohttp.web import (
) )
from traceback import format_exc from traceback import format_exc
from functools import partial from functools import partial
from aiohttp_session import get_session
import random import random
import time import time
@ -81,6 +82,12 @@ def server_error(errcode):
E = exceptions.get(errcode, HTTPException) E = exceptions.get(errcode, HTTPException)
raise E() 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): def basic_auth_headers(user, passwd):
ba = BasicAuth(login=user, password=passwd) ba = BasicAuth(login=user, password=passwd)
return { return {
@ -311,6 +318,7 @@ def initEnv():
g.partial = partial g.partial = partial
g.StreamHttpClient = StreamHttpClient g.StreamHttpClient = StreamHttpClient
g.server_error = server_error g.server_error = server_error
g.MySession = MySession
def set_builtins(): def set_builtins():
all_builtins = [ i for i in dir(builtins) if not i.startswith('_')] all_builtins = [ i for i in dir(builtins) if not i.startswith('_')]