Validate any explicitly specified consumer groups.

        While the check does not require specifying consumer groups,
        if they are specified this method should be used to validate them.

        val = {'consumer_group': {'topic': [0, 1]}}
977482
def _validate_explicit_consumer_groups(cls, val):
        
        assert isinstance(val, dict)
        for consumer_group, topics in iteritems(val):
            assert isinstance(consumer_group, string_types)
            # topics are optional
            assert isinstance(topics, dict) or topics is None
            if topics is not None:
                for topic, partitions in iteritems(topics):
                    assert isinstance(topic, string_types)
                    # partitions are optional
                    assert isinstance(partitions, (list, tuple)) or partitions is None
                    if partitions is not None:
                        for partition in partitions:
                            assert isinstance(partition, int)
462295
def _validate(self, val):
        
        if not self.check_on_set:
            self._ensure_value_is_in_objects(val)
            return

        if not (val in self.objects or (self.allow_None and val is None)):
            # CEBALERT: can be called before __init__ has called
            # super's __init__, i.e. before attrib_name has been set.
            try:
                attrib_name = self.name
            except AttributeError:
                attrib_name = ""

            items = []
            limiter = ']'
            length = 0
            for item in self.objects:
                string = str(item)
                length += len(string)
                if length < 200:
                    items.append(string)
                else:
                    limiter = ', ...]'
                    break
            items = '[' + ', '.join(items) + limiter
            raise ValueError("%s not in Parameter %s's list of possible objects, "
                             "valid options include %s"%(val,attrib_name, items))
1031094
public void ifHasValue(Consumer<? super V> consumer) {

        LettuceAssert.notNull(consumer, "Consumer must not be null");

        if (hasValue()) {
            consumer.accept(getValue());
        }
    }
1311528
def _validate_filter(self, keys, filterset_class):
        
        for k in keys:
            if ((not filterset_class) or (k not in filterset_class.base_filters)):
                raise ValidationError("invalid filter[{}]".format(k))
858057
def validate_ENUM(in_value, restriction):
    
    value = _get_val(in_value)
    if type(value) is list:
        for subval in value:
            if type(subval) is tuple:
                subval = subval[1]
            validate_ENUM(subval, restriction)
    else:
        if value not in restriction:
            raise ValidationError("ENUM : %s"%(restriction))
606882
def check(self, val):
        
        # If there is no `type` requirement, everything is allowed
        if self.type is None:
            return True

        is_list = isinstance(val, list)
        # If lists are not allowed, and this is a list --> false
        if not self.listable and is_list:
            return False

        # `is_number` already checks for either list or single value
        if self.type == KEY_TYPES.NUMERIC and not is_number(val):
            return False
        elif (self.type == KEY_TYPES.TIME and
              not is_number(val) and '-' not in val and '/' not in val):
            return False
        elif self.type == KEY_TYPES.STRING:
            # If its a list, check first element
            if is_list:
                if not isinstance(val[0], basestring):
                    return False
            # Otherwise, check it
            elif not isinstance(val, basestring):
                return False
        elif self.type == KEY_TYPES.BOOL:
            if is_list and not isinstance(val[0], bool):
                return False
            elif not isinstance(val, bool):
                return False

        return True
60043
def validate(self):
        
        for name, field in self._fields.items():
            v = getattr(self, name)
            if v is None and not self._values[name].explicit and field.has_default:
                v = field.get_default()
            val = field.validate(v)
            setattr(self, name, val)
612644
def validate(self, instance, value):
        
        if not self.coerce and not isinstance(value, self._class_container):
            self.error(instance, value)
        if self.coerce and not isinstance(value, CONTAINERS):
            value = [value]
        if not isinstance(value, self._class_container):
            out_class = self._class_container
        else:
            out_class = value.__class__
        out = []
        for val in value:
            try:
                out += [self.prop.validate(instance, val)]
            except ValueError:
                self.error(instance, val, extra='This item is invalid.')
        return out_class(out)
16524
def validate(self, value, attribute_filter=None, minified=False):
        

        if not self._required and value is None:
            return None
        elif self._required and value is None:
            raise exception.RequiredAttributeError()

        _validated_value = self.__class__(
            element_template=self._element_template,
            min_length=self._min_length,
            max_length=self._max_length
        )

        if not isinstance(value, (list, tuple)):
            raise TypeError(value)

        for array_element in value:

            if isinstance(self._element_template, DataCollection):
                validated_array_element = self._element_template.validate(array_element, attribute_filter, minified)
            else:
                validated_array_element = self._element_template.validate(array_element)

            _validated_value.append(validated_array_element)

        if self._min_length is not None and len(_validated_value) < self._min_length:
            raise exception.LessThanMinimumError(value, self._min_length)

        if self._max_length is not None and len(_validated_value) > self._max_length:
            raise exception.MoreThanMaximumError(value, self._max_length)

        return _validated_value
717686
def check(self):
        
        try:
            value = self.raw_value
        except (AttributeError, KeyError) as err:
            self._reraise_if_required(err)
        else:
            if self.checker:
                self.checker(self.full_name, value)
            try:
                self.validate(value)
                self.run_validators(value)
            except ValidationError as error:
                raise ValueError("Setting {} has an invalid value: {}".format(self.full_name, error))
1303823
def is_valid(self, value):
        
        if not self.is_array:
            return self._valid(value)

        if isinstance(value, (list, set, tuple)):
            return all([self._valid(item) for item in value])

        return self._valid(value)
260032
def validate(self, value):
        
        if not isinstance(value, self.nested_klass):
            self.raise_error('NestedClass is of the wrong type: {0} vs expected {1}'
                             .format(value.__class__.__name__, self.nested_klass.__name__))
        super(NestedDocumentField, self).validate(value)
83709
def valid(self, value, level=[]):
		

		# Reset validation failures
		self.validation_failures = []

		# If the value is None and it's optional, we're good
		if value is None and self._optional:
			return True

		# If the value isn't a list
		if not isinstance(value, list):
			self.validation_failures.append(('.'.join(level), str(value)))
			return False

		# Init the return, assume valid
		bRet = True

		# Keep track of duplicates
		if self._type == 'unique':
			lItems	= []

		# Go through each item in the list
		for i in range(len(value)):

			# Add the field to the level
			lLevel = level[:]
			lLevel.append('[%d]' % i)

			# If the element isn't valid, return false
			if not self._node.valid(value[i], lLevel):
				self.validation_failures.extend(self._node.validation_failures[:])
				bRet = False;
				continue;

			# If we need to check for duplicates
			if self._type == 'unique':

				# Try to get an existing item
				try:

					# If it is found, we have a duplicate
					iIndex = lItems.index(value[i])

					# Add the error to the list
					self.validation_failures.append(('.'.join(lLevel), 'duplicate of %s[%d]' % ('.'.join(level), iIndex)))
					bRet = False
					continue

				# If a Value Error is thrown, there is no duplicate, add the
				# 	value to the list and continue
				except ValueError:
					lItems.append(value[i])

		# If there's a minumum
		if self._minimum is not None:

			# If we don't have enough
			if len(value) < self._minimum:
				self.validation_failures.append(('.'.join(level), 'did not meet minimum'))
				bRet = False

		# If there's a maximum
		if self._maximum is not None:

			# If we have too many
			if len(value) > self._maximum:
				self.validation_failures.append(('.'.join(level), 'exceeds maximum'))
				bRet = False

		# Return whatever the result was
		return bRet
732044
def is_group_valid(self, groupID):
        
        cur = self.conn.cursor()
        cur.execute('SELECT * FROM groups WHERE id=? LIMIT 1', [groupID])
        results = cur.fetchall()
        cur.close()

        logging.debug('is_group_valid(groupID={}) => {}'.format(groupID, True if len(results) else False))
        return len(results) > 0
811461
def verify(self, verifier, consumer_key=None, consumer_secret=None,
               access_token=None, access_token_secret=None):
        
        # Stored values can be supplied to verify
        self.consumer_key = consumer_key or self.consumer_key
        self.consumer_secret = consumer_secret or self.consumer_secret
        self.access_token = access_token or self.access_token
        self.access_token_secret = access_token_secret or self.access_token_secret

        oauth = OAuth1(
            self.consumer_key,
            client_secret=self.consumer_secret,
            resource_owner_key=self.access_token,
            resource_owner_secret=self.access_token_secret,
            verifier=verifier)
        r = requests.post(self.url('ACCESS_TOKEN'), auth=oauth)
        if r.status_code == 200:
            creds = parse_qs(r.content)
        else:
            return (False, r.content)

        self.finalize_oauth(creds.get('oauth_token')[0],
                            creds.get('oauth_token_secret')[0])
        return (True, None)
534548
def validate_unique_items(value, **kwargs):
    
    # we can't just look at the items themselves since 0 and False are treated
    # the same as dictionary keys, and objects aren't hashable.

    counter = collections.Counter((
        json.dumps(v, sort_keys=True) for v in value
    ))
    dupes = [json.loads(v) for v, count in counter.items() if count > 1]
    if dupes:
        raise ValidationError(
            MESSAGES['unique_items']['invalid'].format(
                repr(dupes),
            ),
        )
658238
def _validate_group(self, group):
        """"""
        # All groups allowed
        if self._show_all_groups:
            return

        # Group specifically allowed
        if group.id in self._allowed_group_ids:
            return

        # Group allowed by subgroup membership
        for parent_group_id in self._allowed_subgroup_ids:
            # Get each group, and check subgroup ids
            parent_group = self._swimlane.groups.get(id=parent_group_id)
            parent_group_child_ids = set([g['id'] for g in parent_group._raw['groups']])
            if group.id in parent_group_child_ids:
                return

        raise ValidationError(
            self.record,
            'Group `{}` is not a valid selection for field `{}`'.format(
                group,
                self.name
            )
        )