def TdiExecute(expression,args=None): """Compile and execute a TDI expression. Format: TdiExecute('expression-string')""" from _descriptor import descriptor_xd,descriptor,MdsGetMsg from tree import Tree xd=descriptor_xd() done=False try: Tree.lock() restoreContext() if args is None: status=TdiShr.TdiExecute(pointer(descriptor(expression)),pointer(xd),c_void_p(-1)) else: if isinstance(args,tuple): if len(args) > 0: if isinstance(args[0],tuple): ans = TdiExecute(expression,args[0]) done=True if not done: exp='TdiShr.TdiExecute(pointer(descriptor(expression))' for i in range(len(args)): exp=exp+',pointer(descriptor(args[%d]))' % i exp=exp+',pointer(xd),c_void_p(-1))' status=eval(exp) else: raise TypeError('Arguments must be passed as a tuple') finally: Tree.unlock() if done: return ans if (status & 1 != 0): return xd.value else: raise TdiException(MdsGetMsg(status,"Error compiling expression"))
def TdiEvaluate(value): """Evaluate and functions. Format: TdiEvaluate(data)""" from _descriptor import descriptor_xd,descriptor,MdsGetMsg from tree import Tree xd=descriptor_xd() try: Tree.lock() restoreContext() status=TdiShr.TdiEvaluate(pointer(descriptor(value)),pointer(xd),c_void_p(-1)) finally: Tree.unlock() if (status & 1 != 0): return xd.value else: raise TdiException(MdsGetMsg(status,"Error evaluating value"))
def TdiData(value): """Return primiitive data type. Format: TdiData(value)""" from _descriptor import descriptor_xd,descriptor,MdsGetMsg from tree import Tree xd=descriptor_xd() try: Tree.lock() restoreContext() status=TdiShr.TdiData(pointer(descriptor(value)),pointer(xd),c_void_p(-1)) finally: Tree.unlock() if (status & 1 != 0): return xd.value else: raise TdiException(MdsGetMsg(status,"Error converting value to data"))
def TdiEvaluate(value): """Compile and execute a TDI expression. Format: TdiExecute('expression-string')""" from _descriptor import descriptor_xd,descriptor,MdsGetMsg from tree import Tree xd=descriptor_xd() try: Tree.lock() restoreContext() status=TdiShr.TdiEvaluate(pointer(descriptor(value)),pointer(xd),c_void_p(-1)) finally: Tree.unlock() if (status & 1 != 0): return xd.value else: raise TdiException,MdsGetMsg(status,"Error evaluating value")
def TdiDecompile(value): """Compile and execute a TDI expression. Format: TdiExecute('expression-string')""" from _descriptor import descriptor_xd,descriptor,MdsGetMsg from tree import Tree xd=descriptor_xd() try: Tree.lock() restoreContext() status=TdiShr.TdiDecompile(pointer(descriptor(value)),pointer(xd),c_void_p(-1)) finally: Tree.unlock() if (status & 1 != 0): try: return str(xd.value.value.decode()) except Exception,e: return str(xd.value.value)