<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _validate(self, val):
 """ Checks that the list is of the right length and has the right contents. Otherwise, an exception is raised. """

        if self.allow_None and val is None:
            return

        if not isinstance(val, list):
            raise ValueError("List '%s' must be a list."%(self.name))

        if self.bounds is not None:
            min_length,max_length = self.bounds
            l=len(val)
            if min_length is not None and max_length is not None:
                if not (min_length <= l <= max_length):
                    raise ValueError("%s: list length must be between %s and %s (inclusive)"%(self.name,min_length,max_length))
            elif min_length is not None:
                if not min_length <= l:
                    raise ValueError("%s: list length must be at least %s."%(self.name,min_length))
            elif max_length is not None:
                if not l <= max_length:
                    raise ValueError("%s: list length must be at most %s."%(self.name,max_length))

        self._check_type(val)