def evaluate(expression, variables): names = { **simpleeval.DEFAULT_NAMES, 'data': variables, } def update(x, y): op.setitem(variables, x, y) return '' functions = dict( **simpleeval.DEFAULT_FUNCTIONS, update=update, print=print, choice=random.choice, stop=funcy.raiser(Stop), ) evaluator_class = simpleeval.EvalWithCompoundTypes(names=names, functions=functions) try: res = evaluator_class.eval(expression) # print(res) return res except Exception as e: raise e from None
def template__format(template, context = None, formatResult= True): functions = {'list':list} # context['_CONTEXT'] = context functions.update( simpleeval.DEFAULT_FUNCTIONS) functions.update(context) if context is None: context = pymisca.header.get__frameDict(level=1) ptn = '([^{]?){([^}]+)}' class counter(): i = -1 def count(m): counter.i += 1 return m.expand('\\1{%d}'%counter.i) s = template template = re.sub(ptn,string=s, repl= count) exprs = [x[1] for x in re.findall(ptn,s)] vals = map(simpleeval.EvalWithCompoundTypes( # vals = map(simpleeval.SimpleEval( names=context, functions=functions).eval,exprs) # if vals if len(vals)==1 and not formatResult: res = vals[0] else: res = template.format(*vals) del context return res
def __init_slots__(self): """ Initialize private variables which aren't managed by Pydantic. """ object.__setattr__( self, 'astexpr', simpleeval.ast.parse(self.expr.strip()).body[0].value) object.__setattr__( self, 'simple', simpleeval.EvalWithCompoundTypes(names=Transform.namespaces.copy(), operators=Transform._operators))
def eval(self, condition: str, parent: Mapping, scope: DataResolverScope) -> bool: # avoid infinite recusion if isinstance(parent, LazyDynamicMapping): parent = parent._data eval_locals = self.build_eval_locals(parent, scope) injected = self._inject_config_str(condition, eval_locals) evaluator = simpleeval.EvalWithCompoundTypes(names=eval_locals) result = evaluator.eval(injected) # logging.debug(f'\"{cond}\" evaluated to: {result}') return result
"xlabel":"tempResponsive", "ylabel":"PIF7_Dependent", "title":"Fisher exact test: p={pval}", } }, { "FUNCTION":"!{plotters.venn_diagram}", "OFNAME":"venn-diagram-2.svg", "index1":"!{pyext.readData('/home/feng/static/figures/1126__PIF7__Venn__pif7Resp-AND-pif7SimpleBound/Venn-index.csv',)['ind1']}", "index2":"!{pyext.readData('/home/feng/static/figures/1126__PIF7__Venn__pif7Resp-AND-pif7SimpleBound/Venn-index.csv',)['ind2']}", "axis":{ "xlabel":"pif7_resp", "ylabel":"PIF7_bound", "title":"Fisher exact test: p={pval}", } }, ] ''' pyext.printlines([d],'all-plots.json') d_s = simpleeval.EvalWithCompoundTypes().eval(d) # d_s = d_s[-2:] htmlLines=['<a href="./">Parent_Directory</a><br>', '<a href="all-plots.json">all-plots.json</a>'] if __name__ == '__main__': with (Path(__file__)+'.result').makedirs_p() as d: # res = map(job_process,d_s); htmlLines.extend(res) pyext.printlines(htmlLines,'figure.html') print('[INFO] results created in %s'%d.realpath())
# limitations under the License. """Script to perform one time initialization on a new AWS Account to be use for TheBoss""" import argparse import sys import os import alter_path from lib import aws from lib import configuration from lib import console from pprint import pprint try: import simpleeval eval = simpleeval.EvalWithCompoundTypes(functions={'range': range}).eval except ImportError: console.warning("Library 'simpleeval' not available, using the default python implementation") class SubscriptionList(object): def __init__(self, bosslet_config, topic): self.bosslet_config = bosslet_config self.client = bosslet_config.session.client('sns') self.topic = topic self.arn = self.to_arn(topic) def to_arn(self, topic): return 'arn:aws:sns:{}:{}:{}'.format(self.bosslet_config.REGION, self.bosslet_config.ACCOUNT_ID, topic)
def createEvaluator(self): evaluator = simpleeval.EvalWithCompoundTypes() evaluator.functions = simpleeval.DEFAULT_FUNCTIONS evaluator.functions.update(self.script_functions()) return evaluator