Validate the named integer within the supplied limits inclusive and
    strip supplied unit characters
549578
def _validate_int(name, value, limits=(), strip='%'):
    '''
    
    '''
    comment = ''
    # Must be integral
    try:
        if isinstance(value, string_types):
            value = value.strip(' ' + strip)
        value = int(value)
    except (TypeError, ValueError):
        comment += '{0} must be an integer '.format(name)
    # Must be in range
    else:
        if len(limits) == 2:
            if value < limits[0] or value > limits[1]:
                comment += '{0} must be in the range [{1[0]}, {1[1]}] '.format(name, limits)
    return value, comment
137033
def validateMemberName(n):
    
    try:
        if len(n) < 1:
            raise Exception('Name must be at least one byte in length')
        if len(n) > 255:
            raise Exception('Name exceeds maximum length of 255')
        if n[0].isdigit():
            raise Exception('Names may not begin with a digit')
        if mbr_re.search(n):
            raise Exception(
                'Names contains a character outside the set [A-Za-z0-9_]')
    except Exception as e:
        raise MarshallingError('Invalid member name "%s": %s' % (n, str(e)))
551007
def filter_int(string, default=None, start=None, stop=None):
    """"""
    try:
        i = int(string)
        if start is not None and i < start:
            raise InvalidInputError("value too small")
        if stop is not None and i >= stop:
            raise InvalidInputError("value too large")
        return i
    except ValueError:
        if not string and default is not None:
            # empty string, default was given
            return default
        else:
            raise InvalidInputError
857579
def validate_none(b):
    """"""
    if isinstance(b, six.string_types):
        b = b.lower()
    if b is None or b == 'none':
        return None
    else:
        raise ValueError('Could not convert "%s" to None' % b)
886775
def validate_VALUERANGE(in_value, restriction):
    
    if len(restriction) != 2:
        raise ValidationError("Template ERROR: Only two values can be specified in a date range.")
    value = _get_val(in_value)
    if type(value) is list:
        for subval in value:
            if type(subval) is tuple:
                subval = subval[1]
            validate_VALUERANGE(subval, restriction)
    else:
        min_val = Decimal(restriction[0])
        max_val = Decimal(restriction[1])
        val     = Decimal(value)
        if val < min_val or val > max_val:
            raise ValidationError("VALUERANGE: %s, %s"%(min_val, max_val))
774027
private function __validateNumeric($int, $minLength = 1, $maxLength = 0)
    {
        if (!is_numeric($int)) {
            $this->error = 'parameter is not number';
            return false;
        } else if ($maxLength > 0 && strlen($int) > $maxLength) {
            $this->error = 'parameter is too long. number:' . $int;
            return false;
        } else if (strlen($int) < $minLength) {
            $this->error = 'parameter is too short. number:' . $int;
            return false;
        }
        return true;
    }
675942
def _check_d1_characters(name):
    # type: (bytes) -> None
    '''
    
    '''
    bytename = bytearray(name)
    for char in bytename:
        if char not in _allowed_d1_characters:
            raise pycdlibexception.PyCdlibInvalidInput('ISO9660 filenames must consist of characters A-Z, 0-9, and _')
586311
def _validated(self, value):
        """"""
        if value is None:
            return None
        try:
            return self._format_num(value)
        except (TypeError, ValueError):
            self.fail('invalid', input=value)
        except OverflowError:
            self.fail('too_large', input=value)
726555
def validate_integer(option, value):
    
    if isinstance(value, integer_types):
        return value
    elif isinstance(value, string_type):
        try:
            return int(value)
        except ValueError:
            raise ValueError("The value of %s must be "
                             "an integer" % (option,))
    raise TypeError("Wrong type for %s, value must be an integer" % (option,))
578698
def _remove_invalid_char(s):
    """"""

    s = ''.join([i if ord(i) >= 32 and ord(i) < 127 else '' for i in s])
    s = s.translate(dict.fromkeys(map(ord, "_%~#\\{}\":")))
    return s
307003
def value_validate(self, value):
        
        if not isinstance(value, str):
            raise tldap.exceptions.ValidationError("Invalid sid")

        array = value.split("-")
        length = len(array) - 3

        if length < 1:
            raise tldap.exceptions.ValidationError("Invalid sid")

        if array.pop(0) != "S":
            raise tldap.exceptions.ValidationError("Invalid sid")

        try:
            [int(i) for i in array]
        except TypeError:
            raise tldap.exceptions.ValidationError("Invalid sid")
309306
def validate(self, value, redis):
        '''
        
        '''
        # cleanup
        if type(value) == str:
            value = value.strip()

        value = self.value_or_default(value)

        # validation
        self.validate_required(value)

        if self.regex and not re.match(self.regex, value, flags=re.ASCII):
            raise InvalidFieldError(self.name)

        if self.forbidden and value in self.forbidden:
            raise ReservedFieldError(self.name)

        if self.allowed and value not in self.allowed:
            raise InvalidFieldError(self.name)

        if self.index:
            key = self.key()

            old = debyte_string(redis.hget(key, value))
            old_value = getattr(self.obj, self.name)

            if old is not None and old != self.obj.id:
                raise NotUniqueFieldError(self.name)
            elif old_value != value:
                self.obj._old[self.name] = old_value

        return value
1099155
def _value_validate(self, value, rnge, identifier="Given"):
        
        if value is not None and (value < rnge[0] or value > rnge[1]):
            raise ValueError('%s value must be between %d and %d.'
                             % (identifier, rnge[0], rnge[1]))
863292
def validate_length(self, value):
        """"""
        list_len = len(value) if value else 0

        if self.max_length is not None and list_len > self.max_length:
            raise ValidationError(
                u'List has {} values; max length is {}'.format(list_len, self.max_length))

        if self.min_length is not None and list_len < self.min_length:
            raise ValidationError(
                u'List has {} values; min length is {}'.format(list_len, self.min_length))
345143
def validate(self, value):
        
        try:
            int_value = int(value)
            self._choice = int_value
            return True
        except ValueError:
            self.error_message = '%s is not a valid integer.' % value
            return False
1147379
def validate(self, val):
        
        if not isinstance(val, six.string_types):
            raise ValidationError("'%s' expected to be a string, got %s"
                                  % (val, generic_type_name(val)))
        if not six.PY3 and isinstance(val, str):
            try:
                val = val.decode('utf-8')
            except UnicodeDecodeError:
                raise ValidationError("'%s' was not valid utf-8")

        if self.max_length is not None and len(val) > self.max_length:
            raise ValidationError("'%s' must be at most %d characters, got %d"
                                  % (val, self.max_length, len(val)))
        if self.min_length is not None and len(val) < self.min_length:
            raise ValidationError("'%s' must be at least %d characters, got %d"
                                  % (val, self.min_length, len(val)))

        if self.pattern and not self.pattern_re.match(val):
            raise ValidationError("'%s' did not match pattern '%s'"
                                  % (val, self.pattern))
        return val
1072088
def validate_arg(arg, argdef):
        
        datatype = argdef['datatype']
        reasons = set()
        ranges = {
            'ui1': (int, 0, 255),
            'ui2': (int, 0, 65535),
            'ui4': (int, 0, 4294967295),
            'i1': (int, -128, 127),
            'i2': (int, -32768, 32767),
            'i4': (int, -2147483648, 2147483647),
            'r4': (Decimal, Decimal('3.40282347E+38'), Decimal('1.17549435E-38'))
        }
        try:
            if datatype in set(ranges.keys()):
                v_type, v_min, v_max = ranges[datatype]
                if not v_min <= v_type(arg) <= v_max:
                    reasons.add('%r datatype must be a number in the range %s to %s' % (
                        datatype, v_min, v_max))

            elif datatype in {'r8', 'number', 'float', 'fixed.14.4'}:
                v = Decimal(arg)
                if v < 0:
                    assert Decimal('-1.79769313486232E308') <= v <= Decimal('4.94065645841247E-324')
                else:
                    assert Decimal('4.94065645841247E-324') <= v <= Decimal('1.79769313486232E308')

            elif datatype == 'char':
                v = arg.decode('utf8') if six.PY2 or isinstance(arg, bytes) else arg
                assert len(v) == 1

            elif datatype == 'string':
                v = arg.decode("utf8") if six.PY2 or isinstance(arg, bytes) else arg
                if argdef['allowed_values'] and v not in argdef['allowed_values']:
                    reasons.add('Value %r not in allowed values list' % arg)

            elif datatype == 'date':
                v = parse_date(arg)
                if any((v.hour, v.minute, v.second)):
                    reasons.add("'date' datatype must not contain a time")

            elif datatype in ('dateTime', 'dateTime.tz'):
                v = parse_date(arg)
                if datatype == 'dateTime' and v.tzinfo is not None:
                    reasons.add("'dateTime' datatype must not contain a timezone")

            elif datatype in ('time', 'time.tz'):
                now = datetime.datetime.utcnow()
                v = parse_date(arg, default=now)
                if v.tzinfo is not None:
                    now += v.utcoffset()
                if not all((
                        v.day == now.day,
                        v.month == now.month,
                        v.year == now.year)):
                    reasons.add('%r datatype must not contain a date' % datatype)
                if datatype == 'time' and v.tzinfo is not None:
                    reasons.add('%r datatype must not have timezone information' % datatype)

            elif datatype == 'boolean':
                valid = {'true', 'yes', '1', 'false', 'no', '0'}
                if arg.lower() not in valid:
                    reasons.add('%r datatype must be one of %s' % (datatype, ','.join(valid)))

            elif datatype == 'bin.base64':
                b64decode(arg)

            elif datatype == 'bin.hex':
                unhexlify(arg)

            elif datatype == 'uri':
                urlparse(arg)

            elif datatype == 'uuid':
                if not re.match(
                        r'^[0-9a-f]{8}\-[0-9a-f]{4}\-[0-9a-f]{4}\-[0-9a-f]{4}\-[0-9a-f]{12}$',
                        arg, re.I):
                    reasons.add('%r datatype must contain a valid UUID')

            else:
                reasons.add("%r datatype is unrecognised." % datatype)

        except ValueError as exc:
            reasons.add(str(exc))

        return not bool(len(reasons)), reasons