Context Validation
555043
public function validateContext($data, $rules)
	{
		// Start off with a valid status.
		$status = 'valid';

		// We only need to validate context if context rules are given.
		if(array_key_exists('context', $rules))
		{
			foreach($rules['context'] as $rule)
			{
				switch($rule)
				{
					case 'unique_email':
						$userPayload = $this->service['user']->get([['field' => 'email', 'value' => $data['email'], 'operator' => '=', 'or' => false]]);

						if($userPayload->getStatus() == 'found')
						{
							if(in_array($data['email'], $userPayload->getData()->pluck('email')->toArray()))
							{
								$status = $rule;
							}
						}
					break;

					case 'unique_username':
						$userPayload = $this->service['user']->get([['field' => 'username', 'value' => $data['username'], 'operator' => '=', 'or' => false]]);
						
						if($userPayload->getStatus() == 'found')
						{
							if(in_array($data['username'], $userPayload->getData()->pluck('username')->toArray()))
							{
								$status = $rule;
							}
						}
					break;

					default:
					break;
				}
			}
		}

		// @todo: check if we need to unset this.
		// Remove context rules as they're no longer needed.
		unset($rules['context']);

		return new Payload($data, $status);
	}
52065
def validate(self, value=None, model=None, context=None):
        
        errors = []
        for validator in self.validators:
            if value is None and not isinstance(validator, Required):
                continue

            error = validator.run(
                value=value,
                model=model,
                context=context if self.use_context else None
            )
            if error:
                errors.append(error)

        return errors
55734
private void validateCommandResult(DockerCommand command, TestContext context) {
        if (log.isDebugEnabled()) {
            log.debug("Starting Docker command result validation");
        }

        if (StringUtils.hasText(expectedCommandResult)) {
            if (command.getCommandResult() == null) {
                throw new ValidationException("Missing Docker command result");
            }

            try {
                String commandResultJson = jsonMapper.writeValueAsString(command.getCommandResult());
                JsonMessageValidationContext validationContext = new JsonMessageValidationContext();
                jsonTextMessageValidator.validateMessage(new DefaultMessage(commandResultJson), new DefaultMessage(expectedCommandResult), context, validationContext);
                log.info("Docker command result validation successful - all values OK!");
            } catch (JsonProcessingException e) {
                throw new CitrusRuntimeException(e);
            }
        }

        if (command.getResultCallback() != null) {
            command.getResultCallback().doWithCommandResult(command.getCommandResult(), context);
        }
    }
1226941
def validate_context(context):
  
  # Service must exist in service registry
  if not context.service_registry.service_record(context.service_name):
    fail("service: {} not found in service registry: {}".format(
         context.service_name, context.service_registry.filespec))
  service_type = context.service_registry.service_record(context.service_name)["type"]

  # Key must be valid
  if context.key not in EFConfig.VERSION_KEYS:
    fail("invalid key: {}; see VERSION_KEYS in ef_config for supported keys".format(context.key))

  # Lookup allowed key for service type
  if "allowed_types" in EFConfig.VERSION_KEYS[context.key] and \
          service_type not in EFConfig.VERSION_KEYS[context.key]["allowed_types"]:
    fail("service_type: {} is not allowed for key {}; see VERSION_KEYS[KEY]['allowed_types']"
         "in ef_config and validate service registry entry".format(service_type, context.key))

  return True
517876
protected T findValidationContext(List<ValidationContext> validationContexts) {
        for (ValidationContext validationContext : validationContexts) {
            if (getRequiredValidationContextType().isInstance(validationContext)) {
                return (T) validationContext;
            }
        }

        return null;
    }
343797
def set_context(context):
    """"""
    global _context
    _context = {k: v for k, v in context.items()}
681525
protected function validate_data() {
        parent::validate_data();
        if (!isset($this->other['searchterm'])) {
            throw new \coding_exception('The \'searchterm\' value must be set in other.');
        }

        if ($this->contextlevel != CONTEXT_COURSE) {
            throw new \coding_exception('Context level must be CONTEXT_COURSE.');
        }
    }
1120303
def get_context_data(self, **kwargs):
        """"""
        context = super().get_context_data(**kwargs)
        context.update({
            'title': self.title,
            'submit_value': self.submit_value,
            'cancel_url': self.cancel_url
        })
        return context
493783
function validate(entityAspect, validator, value, context) {
    var ve = validator.validate(value, context);
    if (ve) {
      entityAspect._addValidationError(ve);
      return false;
    } else {
      var key = ValidationError.getKey(validator, context ? context.propertyName : null);
      entityAspect._removeValidationError(key);
      return true;
    }
  }
110692
@Override
    public void validate(final FacesContext context) {
        if (context == null) {
            throw new NullPointerException();
        }

        final Validator[] validators = getValidators();
        final Object value = getValue();

        if (!validateRequired(context, value)) {
            return;
        }

        if (validators == null) {
            return;
        }

        for (final Validator validator : validators) {
            try {
                validator.validate(context, this, value);
            }
            catch (final ValidatorException ve) {
                // If the validator throws an exception, we're
                // invalid, and we need to add a message
                setValid(false);
                FacesMessage message;
                final String validatorMessageString = getValidatorMessage();

                if (null != validatorMessageString) {
                    message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                validatorMessageString,
                                validatorMessageString);
                    message.setSeverity(FacesMessage.SEVERITY_ERROR);
                }
                else {
                    final Collection<FacesMessage> messages = ve.getFacesMessages();
                    if (null != messages) {
                        message = null;
                        final String cid = getClientId(context);
                        for (final FacesMessage m : messages) {
                            context.addMessage(cid, m);
                        }
                    }
                    else {
                        message = ve.getFacesMessage();
                    }
                }
                if (message != null) {
                    final Sheet sheet = getSheet();
                    if (sheet == null) {
                        return;
                    }
                    context.addMessage(getClientId(context), message);
                    sheet.getInvalidUpdates().add(
                                new SheetInvalidUpdate(sheet.getRowKeyValue(context), sheet.getColumns().indexOf(this), this, value,
                                            message.getDetail()));

                }
            }
        }

    }
175249
def context(self, size, placeholder=None, scope=None):
        """"""
        return self.leftcontext(size, placeholder,scope) + [self] + self.rightcontext(size, placeholder,scope)
816248
def validate(context = Attributor::DEFAULT_ROOT_CONTEXT)
      raise AttributorException, 'validation conflict' if @validating
      @validating = true

      context = [context] if context.is_a? ::String
      keys_with_values = []
      errors = []

      self.class.attributes.each do |sub_attribute_name, sub_attribute|
        sub_context = self.class.generate_subcontext(context, sub_attribute_name)

        value = __send__(sub_attribute_name)
        keys_with_values << sub_attribute_name unless value.nil?

        if value.respond_to?(:validating) # really, it's a thing with sub-attributes
          next if value.validating
        end

        errors.concat sub_attribute.validate(value, sub_context)
      end
      self.class.requirements.each do |req|
        validation_errors = req.validate(keys_with_values, context)
        errors.concat(validation_errors) unless validation_errors.empty?
      end

      errors
    ensure
      @validating = false
    end
371228
def perform_validations(options={}) # :nodoc:
      if options.is_a?(Hash)
        options[:validate] == false || valid?(options[:context])
      else
        valid?
      end
    end
240029
final protected function _validate(AnCommandContext $context)
    {
        foreach ($this as $filter) {
            if ($filter->execute('validate', $context) === false) {
                return false;
            }
        }

        return true;
    }
1043691
def _context_string(context):
    """"""
    msg = 'Code block context:\n            '
    lines = ['Selective arithmetic coding bypass:  {0}',
             'Reset context probabilities on coding pass boundaries:  {1}',
             'Termination on each coding pass:  {2}',
             'Vertically stripe causal context:  {3}',
             'Predictable termination:  {4}',
             'Segmentation symbols:  {5}']
    msg += '\n            '.join(lines)
    msg = msg.format(((context & 0x01) > 0),
                     ((context & 0x02) > 0),
                     ((context & 0x04) > 0),
                     ((context & 0x08) > 0),
                     ((context & 0x10) > 0),
                     ((context & 0x20) > 0))
    return msg
972757
function (className, context) {
        context = context || '';
        if (!className || !className.match(/^[_A-Z]\w*$/)) {
            Aria.$logError(Aria.INVALID_CLASSNAME_FORMAT, [className, context]);
            return false;
        }
        if (Aria.isJsReservedWord(className)) {
            Aria.$logError(Aria.INVALID_CLASSNAME_RESERVED, [className, context]);
            return false;
        }
        return true;
    }
68367
def validate(self):
        """"""
        try:
            for pkg in self.resolved_packages:
                pkg.validate_data()
        except RezError as e:
            raise ResolvedContextError("%s: %s" % (e.__class__.__name__, str(e)))