Validate filter condition (template method).
761688
def validate(self):
        
        super(ByteSizeFilter, self).validate()

        # Get scale
        lower_val = str(self._value).lower()
        if any(lower_val.endswith(i) for i in self.UNITS):
            scale = self.UNITS[lower_val[-1]]
            self._value = self._value[:-1]
        else:
            scale = 1

        # Get float value
        try:
            self._value = float(self._value)
        except (ValueError, TypeError), exc:
            raise FilterError("Bad numerical value %r in %r (%s)" % (self._value, self._condition, exc))

        # Scale to bytes
        self._value = self._value * scale
617452
def validate(self):
        """"""
        if self.error:
            return False

        for v in self.validators:
            self.error = v(self.value)
            if self.error:
                return False

        return True
1282595
def filter(self, *condition):
        
        if not condition:
            return self
        cond = true()
        for c in condition:
            if c is not None:
                if isinstance(c, (str, unicode)):
                    c = text(c)
                cond = and_(c, cond)
        if self.condition is not None:
            self.condition = and_(cond, self.condition)
        else:
            self.condition = cond
        return self
387160
def _validate(cls, kind):
        """"""
        if kind not in cls._valid_kinds:
            mesg = "'kind' must be one of {}, {}, {}, or {}."
            raise ValueError(mesg.format(*cls._valid_kinds))
        else:
            return kind
1217412
def check_filtering_param(filtering_param, allowed)
      🔞 = filtering_param.keys.map(&:to_sym) - allowed.map(&:to_sym)
      raise InvalidFilterException, "Attributes #{🔞.map(&:to_s).to_sentence} doesn't exists or aren't filterables. Available filters are: #{allowed.to_sentence}" if 🔞.any?
    end
871698
protected function validateRootFilter(): void
    {
        $rootFilter = $this->getArrayValue($this->joryArray, ['flt', 'filter']);

        // It is not required to add a filter, the absence of a filter just means: don't apply a filter.
        // An empty array also counts as no filter.
        // And if no filter is present, there can be no errors; so return.
        if ($rootFilter === null || count($rootFilter) === 0) {
            return;
        }

        // There is a filter, loop through all filters
        $this->validateFilter($rootFilter, $this->address.'filter');
    }
399214
def validate(self):
        
        super(TaggedAsFilter, self).validate()
        self._value = self._value.lower()

        # If the tag starts with '=', test on equality (just this tag, no others)
        if self._value.startswith('='):
            self._exact = True
            self._value = self._value[1:]
        else:
            self._exact = not self._value

        # For exact matches, value is the set to compare to
        if self._exact:
            # Empty tag means empty set, not set of one empty string
            self._value = set((self._value,)) if self._value else set()
649019
def Validate(self, expression):
    
    parsed = self._Load(expression)

    if not parsed:
      raise DefinitionError("Empty StatFilter expression.")

    bad_keys = set(parsed) - self._KEYS
    if bad_keys:
      raise DefinitionError("Invalid parameters: %s" % ",".join(bad_keys))

    if self.cfg.mask and not self.cfg.mode:
      raise DefinitionError("mode can only be set when mask is also defined.")

    if self.cfg.mask:
      if len(self.cfg.mask) > 1:
        raise DefinitionError("Too many mask values defined.")
      if not self._PERM_RE.match(self.cfg.mask[0]):
        raise DefinitionError("mask=%s is not octal, e.g. 0600" % self.cfg.mask)

    if self.cfg.mode:
      if len(self.cfg.mode) > 1:
        raise DefinitionError("Too many mode values defined.")
      if not self._PERM_RE.match(self.cfg.mode[0]):
        raise DefinitionError("mode=%s is not octal, e.g. 0600" % self.cfg.mode)

    if self.cfg.gid:
      for gid in self.cfg.gid:
        matched = self._UID_GID_RE.match(gid)
        if not matched:
          raise DefinitionError("gid: %s is not an integer preceded by "
                                "!, >, < or =." % gid)

    if self.cfg.uid:
      for uid in self.cfg.uid:
        matched = self._UID_GID_RE.match(uid)
        if not matched:
          raise DefinitionError("uid: %s is not an integer preceded by "
                                "!, >, < or =." % uid)

    if self.cfg.file_re:
      if len(self.cfg.file_re) > 1:
        raise DefinitionError("Too many regexes defined: %s" % self.cfg.file_re)
      try:
        self.file_re = re.compile(self.cfg.file_re[0])
      except (re.error, TypeError) as e:
        raise DefinitionError("Invalid file regex: %s" % e)

    if self.cfg.path_re:
      if len(self.cfg.path_re) > 1:
        raise DefinitionError("Too many regexes defined: %s" % self.cfg.path_re)
      try:
        self.path_re = re.compile(self.cfg.path_re[0])
      except (re.error, TypeError) as e:
        raise DefinitionError("Invalid path regex: %s" % e)

    if self.cfg.file_type:
      if len(self.cfg.file_type) > 1:
        raise DefinitionError(
            "Too many file types defined: %s" % self.cfg.file_type)
      file_type = self.cfg.file_type[0].upper()
      if file_type not in self._TYPES:
        raise DefinitionError("Unsupported file type %s" % file_type)

    self._Initialize()
    if not self.matchers:
      raise DefinitionError("StatFilter has no actions: %s" % expression)
    return True
1248982
def matches(self, filter_props):
        """"""
        if filter_props is None:
            return False

        found_one = False
        for key, value in filter_props.items():
            if key in self.properties and value != self.properties[key]:
                return False
            elif key in self.properties and value == self.properties[key]:
                found_one = True

        return found_one
1228428
private boolean hasFilter(Filter filter, WhileMatchFilter whileMatchFilter) {
    if (filter == whileMatchFilter) {
      return true;
    }

    if (filter instanceof FilterList) {
      FilterList list = (FilterList) filter;
      for (Filter subFilter : list.getFilters()) {
        if (hasFilter(subFilter, whileMatchFilter)) {
          return true;
        }
      }
    }

    return false;
  }
479892
private void validateFilter(Filter filter) throws IllegalArgumentException {
    switch (filter.getFilterTypeCase()) {
      case COMPOSITE_FILTER:
        for (Filter subFilter : filter.getCompositeFilter().getFiltersList()) {
          validateFilter(subFilter);
        }
        break;
      case PROPERTY_FILTER:
        if (UNSUPPORTED_OPERATORS.contains(filter.getPropertyFilter().getOp())) {
          throw new IllegalArgumentException("Query cannot have any inequality filters.");
        }
        break;
      default:
        throw new IllegalArgumentException(
            "Unsupported filter type: " + filter.getFilterTypeCase());
    }
  }
297945
def _match_filters(parameter, filters=None):
        """"""
        for filter_obj in (filters or []):
            key = filter_obj['Key']
            option = filter_obj.get('Option', 'Equals')
            values = filter_obj.get('Values', [])

            what = None
            if key == 'Type':
                what = parameter.type
            elif key == 'KeyId':
                what = parameter.keyid

            if option == 'Equals'\
                    and not any(what == value for value in values):
                return False
            elif option == 'BeginsWith'\
                    and not any(what.startswith(value) for value in values):
                return False
        # True if no false match (or no filters at all)
        return True
133633
def validate(self, instance, value):
        """"""
        if not isinstance(value, (tuple, list, np.ndarray)):
            self.error(instance, value)
        if self.coerce:
            value = self.wrapper(value)
        valid_class = (
            self.wrapper if isinstance(self.wrapper, type) else np.ndarray
        )
        if not isinstance(value, valid_class):
            self.error(instance, value)
        allowed_kinds = ''.join(TYPE_MAPPINGS[typ] for typ in self.dtype)
        if value.dtype.kind not in allowed_kinds:
            self.error(instance, value, extra='Invalid dtype.')
        if self.shape is None:
            return value
        for shape in self.shape:
            if len(shape) != value.ndim:
                continue
            for i, shp in enumerate(shape):
                if shp not in ('*', value.shape[i]):
                    break
            else:
                return value
        self.error(instance, value, extra='Invalid shape.')
1029288
def validate_query_params(self):
        """"""
        allowed_params = set(self.get_filters().keys())
        allowed_params.update(self.get_always_allowed_arguments())

        unallowed = set(self.request.query_params.keys()) - allowed_params

        if unallowed:
            msg = 'Unsupported parameter(s): {}. Please use a combination of: {}.'.format(
                ', '.join(unallowed),
                ', '.join(allowed_params),
            )
            self.form.add_error(field=None, error=ParseError(msg))
789102
def _filter_validate(filepath, location, values, validate):
    
    for value in values:
        if not isinstance(value, dict):
            warn_invalid(filepath, location, value, '(expected a dict)')
            continue
        try:
            yield validate(**value)
        except dbt.exceptions.JSONValidationException as exc:
            # we don't want to fail the full run, but we do want to fail
            # parsing this file
            warn_invalid(filepath, location, value, '- ' + exc.msg)
            continue
1056241
def validate(self, value):
        """"""
        if self.type is not None:
            value = coerce(self.type, value)

        if self.min is not None and value < self.min:
            raise ValueError('%s=%s is less than %s' % (self.name, value,
                                                        self.min))
        if self.max is not None and value > self.max:
            raise ValueError('%s=%s is greater than %s' % (
                self.name, value, self.max))
        if self.allowed is not None and value not in self.allowed:
            raise ValueError('%s=%s is not one of the allowed values: %s' % (
                self.name, value, ','.join(map(str, self.allowed))))

        return value
465966
def Compile(self, filter_implementation):
    """"""
    operator = self.operator.lower()
    if operator in ('and', '&&'):
      method = 'AndFilter'
    elif operator in ('or', '||'):
      method = 'OrFilter'
    else:
      raise errors.ParseError(
          'Invalid binary operator {0:s}.'.format(operator))

    args = [x.Compile(filter_implementation) for x in self.args]
    return filter_implementation.FILTERS[method](arguments=args)