diff --git a/appPublic/argsConvert.py b/appPublic/argsConvert.py index d459260..352f862 100755 --- a/appPublic/argsConvert.py +++ b/appPublic/argsConvert.py @@ -1,6 +1,7 @@ # -*- coding:utf8 -*- import re from appPublic.dictObject import DictObject +from appPublic.registerfunction import rfrun class ConvertException(Exception): pass @@ -13,7 +14,8 @@ class ArgsConvert(object): sl2 = [ u'\\' + c for c in self.subfixString ] ps = u''.join(sl1) 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 # 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)] def getVarValue(self,var,namespace,default): + ns = DictObject(**namespace.copy()) + ns.rfrun = rfrun v = default try: - v = eval(var,namespace) + v = eval(var,ns) except Exception as e: - v = namespace.get(var, None) + v = ns.get(var, None) if v: return v if callable(default): diff --git a/appPublic/registerfunction.py b/appPublic/registerfunction.py index 4fb1a5a..7c1ad8e 100755 --- a/appPublic/registerfunction.py +++ b/appPublic/registerfunction.py @@ -19,6 +19,15 @@ class RegisterFunction: def get(self,name): 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): f = self.get(name) if f is None: @@ -64,9 +73,13 @@ def registerFunction(name, func): rf = RegisterFunction() rf.register(name, func) -async def rfexe(rfname, *args): +async def rfexe(rfname, *args, **kw): 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(): d = {}