Exemplo n.º 1
0
 def __init__(self, *arguments):
     """
     
     :raises booleano.exc.BadCallError: If :meth:`check_arguments` finds 
         that the ``arguments`` are invalid, or if few arguments are passed,
         or if too much arguments are passed.
     
     """
     super(Function, self).__init__()
     # Checking the amount of arguments received:
     argn = len(arguments)
     if argn < len(self.required_arguments):
         raise BadCallError("Too few arguments")
     if argn > self.arity:
         raise BadCallError("Too many arguments")
     # Checking that all the arguments are operands:
     for argument in arguments:
         if not isinstance(argument, Operand):
             raise BadCallError('Argument "%s" is not an operand' %
                                argument)
     # Storing their values:
     self.arguments = self.optional_arguments.copy()
     for arg_pos in range(len(arguments)):
         arg_name = self.all_args[arg_pos]
         self.arguments[arg_name] = arguments[arg_pos]
     # Finally, check that all the parameters are correct:
     self.check_arguments()
Exemplo n.º 2
0
 def __init__(self, function_name, namespace_parts=None, *arguments):
     """
     
     :param function_name: The name of the function to be represented.
     :type function_name: basestring
     :param namespace_parts: The identifiers in the namespace that contains
         the placeholder function.
     :type namespace_parts: tuple
     :raises BadCallError: If one of the ``arguments`` is not an
         :class:`Operand`.
     
     """
     for argument in arguments:
         if not isinstance(argument, Operand):
             raise BadCallError(u'Placeholder function "%s" received a '
                                'non-operand argument: %s' %
                                (function_name, argument))
     self.arguments = arguments
     super(PlaceholderFunction, self).__init__(function_name,
                                               namespace_parts)
Exemplo n.º 3
0
 def __check_argument_type(self, argument, expected_type):
     if not isinstance(argument, expected_type):
         raise BadCallError("Argument %r does not implement the %s "
                            "datatype" % (argument, expected_type))
Exemplo n.º 4
0
 def check_arguments(self):
     assert isinstance(self.arguments['light'], String)
     light = self.arguments['light'].constant_value
     if light not in ("pedestrians", "drivers"):
         raise BadCallError("Only pedestrians and drivers have lights")