def breakup_expression(expression, entry): inputs = [p.name for p in raw_encode_params.get_params(entry) if p.direction == p.IN] constant, components = solve_expression(expression, expression, entry, raw_decode_params, inputs) try: constant = constant.evaluate({}) except UndecodedReferenceError: pass return constant, components
def _solve(result_expr, sequence, param_name, expression_params): constant, components = solve_expression(result_expr, sequence.value, sequence, expression_params.expression_params, []) if len(components) == 1: reference, expression, inverted = components[0] if reference.name == param_name: return inverted.evaluate({}) else: logging.warning("Expected to solve reference to '%s', but " "found '%s'! Skipping constraint." % (param_name, reference.name)) else: logging.warning("Found multiple unknowns when solving '%s'! Skipping constraint." % sequence.value)
def _are_expression_inputs_available(expr, entry): """Check to see if all of the inputs to an expression are available.""" names = [p.name for p in encode_params.get_params(entry) if p.direction == p.IN] result = ReferenceExpression('result') inputs = [p.name for p in encode_params.get_params(entry) if p.direction == p.IN] constant, components = solve_expression(result, expr, entry, raw_decode_params, inputs) for ref, expr, inverted in components: if variable(ref.name) not in names: # The expression references an item that isn't being passed in. return False return True
def _is_length_known(entry): inputs = [p.name for p in raw_encode_params.get_params(entry) if p.direction == p.IN] constant, components = solve_expression(entry.length, entry.length, entry, raw_decode_params, inputs) return len(components) == 0