Example #1
0
 def equation_simple_expression(self, t):
     """
     equation_simple_expression : IDENTIFIER 
                                 | BOOL
     """
     if isinstance(t[1], str) or isinstance(t[1], unicode):
         t[0] = IdentifierExpression(t[1])
     else:
         t[0] = BooleanExpression(t[1])
Example #2
0
 def build_expression_call_routing_next(self, token):
     """
     expression_call_function : ROUTING_NEXT LPARAN IDENTIFIER COMMA expression_call_routing_next_argument RPARAN
                                         | ROUTING_NEXT LPARAN IDENTIFIER COMMA expression_call_routing_next_argument COMMA expression_call_routing_next_argument RPARAN
     """
     arguments = [IdentifierExpression(token[3]), token[5]]
     if len(token) == 9:
         arguments.append(token[7])
     return CallFunctionExpression(token[1], arguments)
Example #3
0
def _predefined_routing_next_function__populate(call_function_expression,
                                                host,
                                                populator,
                                                context=None):

    topology_name = call_function_expression.arguments[0].identifier

    receiver_function_id_expression = populator.populate(
        call_function_expression.arguments[1], host)
    receiver_function_id_expression = _predefined_id_function__populate(
        receiver_function_id_expression, host, populator)
    receiver_name = getattr(receiver_function_id_expression, '_host_name')

    receiver = None
    for h in context.hosts:
        if h.name == receiver_name:
            receiver = h
            break

    sender = host
    sender_name = sender.name
    if len(call_function_expression.arguments) > 2:
        sender_function_id_expression = populator.populate(
            call_function_expression.arguments[2], host)
        sender_function_id_expression = _predefined_id_function__populate(
            sender_function_id_expression, host, populator)
        sender_name = getattr(sender_function_id_expression, '_host_name')
        if sender_name != sender.name:
            sender = None
            for h in context.hosts:
                if h.name == sender_name:
                    sender = h
                    break

    if sender is None:
        raise RuntimeException("Host '%s' undefined." % sender_name)
    if receiver is None:
        raise RuntimeException("Host '%s' undefined." % receiver_name)

    if sender == receiver:
        next_host = receiver
    else:
        next_host = context.channels_manager.get_router().get_next_hop_host(
            topology_name, sender, receiver)
        if next_host is None:
            raise RuntimeException(
                "The route from host '%s' to host '%s' cannot be found." %
                (sender_name, receiver_name))
    # DEBUG
    # print host.name, ': ', unicode(call_function_expression), ' -> ', next_host.name
    # DEBUG

    id_function = CallFunctionExpression(
        'id', arguments=[IdentifierExpression(next_host.name)])
    setattr(id_function, '_host_name', next_host.name)
    return id_function
Example #4
0
 def build_expression_call_id_function(self, token):
     """
     expression_call_function : ID LPARAN RPARAN
                             | ID LPARAN IDENTIFIER RPARAN
                             | ID LPARAN QUALIFIED_IDENTIFIER RPARAN
     """
     arguments = []
     if len(token) == 5:
         arguments.append(IdentifierExpression(token[3]))
     return CallFunctionExpression(token[1], arguments)
Example #5
0
 def expression_call_routing_next_argument(self, t):
     """
     expression_call_routing_next_argument : expression_call_function
                                         | expression_tuple_element
                                         | IDENTIFIER
     """
     if isinstance(t[1], str) or isinstance(t[1], unicode):
         t[0] = IdentifierExpression(t[1])
     else:
         t[0] = t[1]
Example #6
0
 def instruction_in_filter(self, t):
     """
     instruction_in_filter : STAR
                     | expression_call_function
                     | IDENTIFIER
     """
     if (t[1] == '*') or isinstance(t[1], CallFunctionExpression):
         t[0] = t[1]
     else:
         t[0] = IdentifierExpression(t[1])
Example #7
0
 def expression_simple(self, t):
     """
     expression_simple : expression_call_function
                     | expression_tuple_element
                     | expression_tuple
                     | IDENTIFIER
                     | BOOL
     """
     if isinstance(t[1], bool):
         t[0] = BooleanExpression(t[1])
     elif isinstance(t[1], str) or isinstance(t[1], unicode):
         t[0] = IdentifierExpression(t[1])
     else:
         t[0] = t[1]