def __evaluate__(self, container_holder):
     final = True
     value = StringIO()
     for e in self.string_expressions:
         e, final = evaluate(e, final, container_holder)
         if e is not None:
             value.write(unicode(e))
     value = value.getvalue() or u''
     return Evaluation(value, final)
    def __evaluate__(self, container_holder):
        final = True
        string_with_tokens, final = evaluate(self.string_with_tokens, final, container_holder)
        string_of_token_chars, final = evaluate(self.string_of_token_chars, final, container_holder)

        if string_of_token_chars:
            regex = '[' + ''.join(re.escape(c) for c in string_of_token_chars) + ']'
            split = re.split(regex, string_with_tokens)
            if self.substring_index < len(split):
                return Evaluation(split[self.substring_index], final)

        raise CannotEvaluateFunctionException()
def get_modelable_entity_parameter(modelable_entity, parameters,
                                   nested_parameter_name_or_index):
    if not parameters:
        return Evaluation(None, True)

    found = True
    final = True
    value = parameters

    for name_or_index in nested_parameter_name_or_index:
        if (isinstance(value, dict) and (name_or_index in value)) \
            or ((isinstance(value, list) and (name_or_index < len(value)))):
            value = value[name_or_index]  # Parameter
            # We are not using Parameter.value, but rather Parameter._value, because we want to make
            # sure to get "final" (it is swallowed by Parameter.value)
            value, final = evaluate(value._value, final, value)
        else:
            found = False
            break

    return Evaluation(value, final) if found else None
    def __evaluate__(self, container_holder):
        service = container_holder.service
        if service is None:
            raise CannotEvaluateFunctionException()

        value = service.inputs.get(self.input_property_name)
        if value is not None:
            value = value.value
            return Evaluation(value, False) # We never return final evaluations!

        raise InvalidValueError(
            'function "get_input" argument is not a valid input name: {0}'
            .format(safe_repr(self.input_property_name)),
            locator=self.locator)
Beispiel #5
0
 def __evaluate__(self, container):
     return Evaluation(None)