TODO (kayagoban) A validator accepting a block for conditional execution
 might be useful.
 Maybe require_keys should accept a block.  Figure out later.
323320
def validate_field(field, params)
      begin
        value = params.fetch(field)
        required_error(field) if value.nil? || value.empty?
      rescue KeyError
        required_error(field)
      end
    end
105458
private boolean checkConstraints(Set<CryptoPrimitive> primitives,
            String algorithm, Key key, AlgorithmParameters parameters) {

        // check the key parameter, it cannot be null.
        if (key == null) {
            throw new IllegalArgumentException("The key cannot be null");
        }

        // check the target algorithm
        if (algorithm != null && algorithm.length() != 0) {
            if (!permits(primitives, algorithm, parameters)) {
                return false;
            }
        }

        // check the key algorithm
        if (!permits(primitives, key.getAlgorithm(), null)) {
            return false;
        }

        // check the key constraints
        if (keySizeConstraints.disables(key)) {
            return false;
        }

        return true;
    }
943562
function(block, shouldValidate) {
    if (!config.skipValidation && shouldValidate && !block.valid()) {
      this.mediator.trigger('errors:add', { text: _.result(block, 'validationFailMsg') });
      utils.log("Block " + block.blockID + " failed validation");
      return;
    }

    if (block.type === 'text' && block.isEmpty()) {
      return;
    }

    var blockData = block.getData();
    utils.log("Adding data for block " + block.blockID + " to block store:",
              blockData);
    this.store.addData(blockData);
  }
262853
def validate(cls, keystr):
        
        if "#{" in keystr:
            # it's a template with keys vars
            keys = cls.from_template(keystr)
            for k in keys:
                cls.validate_one(cls.extract(k))
        else:
            # plain keys str
            cls.validate_one(keystr)
117883
def requires(self, require=None):
		

		# If require is None, this is a getter
		if require is None:
			return self._requires

		# If it's not a valid dict
		if not isinstance(require, dict):
			raise ValueError('__require__')

		# Go through each key and make sure it goes with a field
		for k,v in iteritems(require):

			# If the field doesn't exist
			if k not in self._nodes:
				raise ValueError('__require__[%s]' % str(k))

			# If the value is a string
			if isinstance(v, basestring):
				v = [v]

			# Else if it's not a list type
			elif not isinstance(v, (tuple,list)):
				raise ValueError('__require__[%s]' % str(k))

			# Make sure each required field also exists
			for s in v:
				if s not in self._nodes:
					raise ValueError('__require__[%s]: %s' % (str(k), str(v)))

			# If it's all good
			self._requires[k] = v
999680
def validate_block!(original_values)
      raise InvalidBlock, "gas_used mistmatch actual: #{gas_used} target: #{original_values[:gas_used]}" if gas_used != original_values[:gas_used]
      raise InvalidBlock, "timestamp mistmatch actual: #{timestamp} target: #{original_values[:timestamp]}" if timestamp != original_values[:timestamp]
      raise InvalidBlock, "difficulty mistmatch actual: #{difficulty} target: #{original_values[:difficulty]}" if difficulty != original_values[:difficulty]
      raise InvalidBlock, "bloom mistmatch actual: #{bloom} target: #{original_values[:bloom]}" if bloom != original_values[:bloom]

      uh = Utils.keccak256_rlp uncles
      raise InvalidBlock, "uncles_hash mistmatch actual: #{uh} target: #{original_values[:uncles_hash]}" if uh != original_values[:uncles_hash]

      raise InvalidBlock, "header must reference no block" unless header.block.nil?

      raise InvalidBlock, "state_root mistmatch actual: #{Utils.encode_hex @state.root_hash} target: #{Utils.encode_hex header.state_root}" if @state.root_hash != header.state_root
      raise InvalidBlock, "tx_list_root mistmatch actual: #{@transactions.root_hash} target: #{header.tx_list_root}" if @transactions.root_hash != header.tx_list_root
      raise InvalidBlock, "receipts_root mistmatch actual: #{@receipts.root_hash} target: #{header.receipts_root}" if @receipts.root_hash != header.receipts_root

      raise ValueError, "Block is invalid" unless validate_fields

      raise ValueError, "Extra data cannot exceed #{config[:max_extradata_length]} bytes" if header.extra_data.size > config[:max_extradata_length]
      raise ValueError, "Coinbase cannot be empty address" if header.coinbase.false?
      raise ValueError, "State merkle root of block #{self} not found in database" unless @state.root_hash_valid?
      raise InvalidNonce, "PoW check failed" if !genesis? && nonce.true? && !header.check_pow
    end
167587
def any_validator(obj, validators, **kwargs):
    
    if not len(validators) > 1:
        raise ValueError(
            "any_validator requires at least 2 validator.  Only got "
            "{0}".format(len(validators))
        )
    errors = ErrorDict()
    for key, validator in validators.items():
        try:
            validator(obj, **kwargs)
        except ValidationError as err:
            errors[key] = err.detail
        else:
            break
    else:
        if len(errors) == 1:
            # Special case for a single error.  Just raise it as if it was the
            # only validator run.
            error = errors.values()[0]
            raise ValidationError(error)
        else:
            # Raise all of the errors with the key namespaces.
            errors.raise_()
778305
def _validate_and_get_value(options, options_name, key, _type):
  
  if isinstance(options, dict):
    has = lambda k: k in options
    get = lambda k: options[k]
  elif isinstance(options, object):
    has = lambda k: hasattr(options, k)
    get = lambda k: getattr(options, k)
  else:
    raise ImproperlyConfigured(
        '`{}` must be a dictionary-like object.'.format(options_name))

  if not has(key):
    raise ImproperlyConfigured(
        '`{}` must be specified in `{}`'.format(key, options_name))

  value = get(key)
  if not isinstance(value, _type):
    raise ImproperlyConfigured(
        '`{}` in `{}` must be a {}'.format(key, options_name, repr(_type)))

  return value
428840
function checkSync(validations, input, key) {
  var arr = new Checkit(validations).runSync(input);
  if (arr[0] === null) return arr;
  if (arr[0] instanceof CheckitError) {
    return [arr[0].get(key), null]
  }
  return arr;
}
705463
function validate (schema, data, key) {
  let value = data[key]
  const bool = value == null || value === ''
  const { required, type, validate, transform, elements } = schema
  const def = schema['default']
  // trigger error if undefined but required
  if (required && bool) throw new Error(`field ${key} is missing`)
  // coerce to type
  if (type && !bool) {
    let before = coerce(type, key, value)
    data[key] = elements
      ? (type === 'object' ? validator(before, elements) : before.map(item => validator(item, elements)))
      : before
  }
  // validate value
  if (validate) {
    const cb = check(validate, key)
    if (type === 'array') value.map(cb)
    else cb(value)
  }
  // apply default value
  if (def && bool) data[key] = def
  // apply transform
  if (transform && def == null) {
    data[key] = typeof transform === 'function'
      ? (type === 'array' ? value.map(transform) : transform(value))
      : transform
  }
}
400995
def validate_key(key)
      unless key.is_a?(Symbol) || key.is_a?(String)
        raise ArgumentError, 'Key must be a string or symbol'
      end
      key
    end
647788
def is_suitable(self, request):
        
        if self.key_type:
            validation = KEY_TYPE_VALIDATIONS.get( self.get_type() )
            return validation( request ) if validation else None
        return True
130184
private void validate(List<ByteBuffer> variables) throws InvalidRequestException
    {
        // Ensure that exactly one key has been specified.
        if (keyValidator.size() < 1)
            throw new InvalidRequestException("You must specify a PRIMARY KEY");
        else if (keyValidator.size() > 1)
            throw new InvalidRequestException("You may only specify one PRIMARY KEY");

        AbstractType<?> comparator;

        try
        {
            cfProps.validate();
            comparator = cfProps.getComparator();
        }
        catch (ConfigurationException e)
        {
            throw new InvalidRequestException(e.toString());
        }
        catch (SyntaxException e)
        {
            throw new InvalidRequestException(e.toString());
        }

        for (Map.Entry<Term, String> column : columns.entrySet())
        {
            ByteBuffer name = column.getKey().getByteBuffer(comparator, variables);

            if (keyAlias != null && keyAlias.equals(name))
                throw new InvalidRequestException("Invalid column name: "
                                                  + column.getKey().getText()
                                                  + ", because it equals to the key_alias.");

        }
    }
663746
def run_validator(value)
      return unless validator
      error = validator.call(value)
      raise ValidationError unless error.nil?
    end
310374
def meets_requirements?(params)
      requirements.reject {|k| params.keys.map(&:to_s).include? k.to_s }.empty?
    end
1314642
def _pv_required(opts, key, is_required=true)
        if is_required
          if (opts.has_key?(key.to_s) && !opts[key.to_s].nil?) ||
              (opts.has_key?(key.to_sym) && !opts[key.to_sym].nil?)
            true
          else
            raise ValidationFailed, "Required argument #{key} is missing!"
          end
        end
      end
936065
def validate_re key, value, opts
      if opts[:re]
        if value.to_s !~ opts[:re]
          raise RegApi2::ContractError.new(
            "Field #{key} mismatch regular expression: #{value}",
            key
          )
        end
      end
      value
    end