This commit is contained in:
yumoqing 2024-12-04 18:49:21 +08:00
parent 6fd89a00ae
commit 2f10073b3b
2 changed files with 22 additions and 5 deletions

View File

@ -1,6 +1,7 @@
# -*- coding:utf8 -*- # -*- coding:utf8 -*-
import re import re
from appPublic.dictObject import DictObject from appPublic.dictObject import DictObject
from appPublic.registerfunction import rfrun
class ConvertException(Exception): class ConvertException(Exception):
pass pass
@ -13,7 +14,8 @@ class ArgsConvert(object):
sl2 = [ u'\\' + c for c in self.subfixString ] sl2 = [ u'\\' + c for c in self.subfixString ]
ps = u''.join(sl1) ps = u''.join(sl1)
ss = u''.join(sl2) ss = u''.join(sl2)
re1 = ps + r"[_a-zA-Z_\u4e00-\u9fa5][a-zA-Z_0-9\u4e00-\u9fa5\,\.\'\{\}\[\]\(\)\-\+\*\/]*" + ss # re1 = ps + r"[_a-zA-Z_\u4e00-\u9fa5][a-zA-Z_0-9\u4e00-\u9fa5\,\.\'\{\}\[\]\(\)\-\+\*\/]*" + ss
re1 = ps + r".*?" + ss
self.re1 = re1 self.re1 = re1
# print( self.re1,len(self.re1),len(re1),type(self.re1)) # print( self.re1,len(self.re1),len(re1),type(self.re1))
@ -43,11 +45,13 @@ class ArgsConvert(object):
return vs[len(self.preString):-len(self.subfixString)] return vs[len(self.preString):-len(self.subfixString)]
def getVarValue(self,var,namespace,default): def getVarValue(self,var,namespace,default):
ns = DictObject(**namespace.copy())
ns.rfrun = rfrun
v = default v = default
try: try:
v = eval(var,namespace) v = eval(var,ns)
except Exception as e: except Exception as e:
v = namespace.get(var, None) v = ns.get(var, None)
if v: if v:
return v return v
if callable(default): if callable(default):

View File

@ -19,6 +19,15 @@ class RegisterFunction:
def get(self,name): def get(self,name):
return self.registKW.get(name,None) return self.registKW.get(name,None)
def run(self, name, *args, **kw):
f = self.get(name)
if iscoroutinefunction(f):
print(f'{name} is a coro')
return None
if f:
return f(*args, **kw)
error(f'{name} not register')
async def exe(self, name, *args, **kw): async def exe(self, name, *args, **kw):
f = self.get(name) f = self.get(name)
if f is None: if f is None:
@ -64,9 +73,13 @@ def registerFunction(name, func):
rf = RegisterFunction() rf = RegisterFunction()
rf.register(name, func) rf.register(name, func)
async def rfexe(rfname, *args): async def rfexe(rfname, *args, **kw):
rf = RegisterFunction() rf = RegisterFunction()
return await rf.exe(rfname, *args) return await rf.exe(rfname, *args, **kw)
def rfrun(rfname, *args, **kw):
rf = RegisterFunction()
return rf.run(rfname, *args, **kw)
async def main(): async def main():
d = {} d = {}