aicode/kdb/variable.md
2026-01-15 17:14:16 +08:00

150 lines
3.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 脚本中可直接使用的变量
脚本是wwwroot目录下的脚本文件包括.ui, .dspy, .xterm后缀的脚本
## request
web服务器的request
### request._run_ns
DictObject实例含所有可用的变量
### request['client_ip']
保存客户端实际的IP 支持最多一层代理多了就不能获得真实的客户ip
## params_kw
DictObjectdict子类, 支持a.b方式获取属性实例接收到客户端传来的数据如果有文件文件都保存在服务器指定的位置params_kw中属性保存的是其相对路径可用FileStorage().realPath(params_kw.myfile)来获得文件在服务器中的实际路径。
### get_user()
来自rbac模块协程函数获得当前登录用户如果用户没有登录返回None
### get_userorgid()
来自rbac模块协程函数获得当前登录用户的机构id如果用户没有登录返回None
### json
python的json模块
### ArgsConvert
### time
python的time模块
### curDateString
函数获得当前日期字符串格式为“yyyy-mm-dd“
### curTimeString
函数获得当前时间字符串格式为”HH:MM:SS“
### datetime
python的datetime模块
### random
python的random模块
### str2Date
函数将字符串格式的日期转换为datetime日期实例
### str2Datetime
函数,将"yyyy-mm-dd HH:MM:SS"字符串转换为datetime日期实例
### timestampstr
函数获得当前时间戳的字符串格式“yyyy-mm-dd HH:MM:SS.xxx"
### monthfirstday
函数,获得日期参数的第一天
### curDatetime
函数获得当前时间的datetime日期实例
### strdate_add
函数,在日期上增加多少天,月,年
### uuid
函数获得一个uuid
### DBPools
### DBFilter
### default_filterjson
### password_encode
函数,信息加密,返回加密后的字符串
### password_decode
函数,信息解密,返回解密后的字符串
### get_config_value
函数返回配置文件中的值
### DictObject
数据类支持a.b操作的字典
### async_sleep
异步睡眠
### quote
url编码
### realpath
函数获得webpath的文件系统路径
```
relp = realpath('/33/55/22/55/abc.doc')
### format_exc
函数,获得当前调用栈字符串
```
e=Exception('TEST exception')
exception(f'{e}{format_exc()}')
```
### stream_response
协程实现流式response给前端
```
async def gen(request):
cnt = 100000
i = 0
while i < cnt:
yield
### webpath
函数返回文件系统路径的webpath必须是配置文件中files目录下的文件
### partial
python的partial函数
### StreamHttpClient
appPublic模块的StreamHttpClient类
```
shc = StreamHttpClient()
x = await shc.get('https://www.baidu.com')
```
### tmpl_engine
支持异步的jinja2引擎, 例子
```
tmpl='hello {{user}}'
d = {'user': 'John'}
s = tmpl_engine.renders(tmpl, d)
```
### downloadfile2url
协程从远端下载文件放到files目录下并构造url可供客户端下载
```
url = 'https://xxx.com/xxx.mp4'
newurl = await downloadfile2url(request, url)
```
### background_reco
函数后台执行协程
```
async def dummy(*args, **kw):
while True:
async_sleep(1)
print('test')
background_reco(dummy)
```
### get_sor_context
异步上下午获得sor上下文用于操作数据库以下两组代码等价
```
async with sor.get_sor_context(env, dbname) as sor:
```
```
db = DBPools()
async with db.sqlorContext(dbname) as sor:
```
### json_response
函数json格式数据构造Response返回Response实例
```
d = {"a":"B"}
return json_response(d)
### Response
aiohttp的Response类
### web_rootpath
函数 获得web应用的root文件系统路径