Exemplo n.º 1
0
class AdapterEvaluator(object):
    def __init__(self, job):
        self.job = job
        self.ev = Evaluator()

    def evaluate(self, expr_object, context=None):
        if isinstance(expr_object, dict):
            return self.ev.evaluate(expr_object.get('lang', 'javascript'),
                                    expr_object.get('value'),
                                    self.job.to_dict(), context)
        else:
            return self.ev.evaluate('javascript', expr_object,
                                    self.job.to_dict(), context)

    def resolve(self, val, context=None):
        if not isinstance(val, dict):
            return val
        if 'expr' in val or '$expr' in val:
            v = val.get('expr') or val.get('$expr')
            return self.evaluate(v, context)
        if 'job' in val or '$job' in val:
            v = val.get('job') or val.get('$job')
            return resolve_pointer(self.job.to_dict(), v)
        return val

    def __deepcopy__(self, memo):
        return AdapterEvaluator(copy.deepcopy(self.job, memo))
Exemplo n.º 2
0
class AdapterEvaluator(object):

    def __init__(self, job):
        self.job = job
        self.ev = Evaluator()

    def evaluate(self, expr_object, context=None, job=None):
        if isinstance(expr_object, dict):
            return self.ev.evaluate(
                expr_object.get('lang', 'javascript'),
                expr_object.get('value'),
                job.to_dict() if job else self.job.to_dict(),
                context
            )
        else:
            return self.ev.evaluate('javascript', expr_object,
                                    job.to_dict() if job else
                                    self.job.to_dict(), context)

    def resolve(self, val, context=None, job=None):
        if not isinstance(val, dict):
            return val
        if 'expr' in val or '$expr' in val:
            v = val.get('expr') or val.get('$expr')
            return self.evaluate(v, context, job=job)
        if 'job' in val or '$job' in val:
            v = val.get('job') or val.get('$job')
            return resolve_pointer(self.job.to_dict(), v)
        return val

    def __deepcopy__(self, memo):
        return AdapterEvaluator(copy.deepcopy(self.job, memo))
Exemplo n.º 3
0
 def __init__(self, job):
     self.job = job
     self.ev = Evaluator()
Exemplo n.º 4
0
 def __init__(self, job):
     self.job = job
     self.ev = Evaluator()