def init(converter, kwargs): Converter.init(converter, kwargs) attr = converter.attr min_val = kwargs.pop('min', None) if min_val is not None and not isinstance(min_val, int_types): throw(TypeError, "'min' argument for attribute %s must be int. Got: %r" % (attr, min_val)) max_val = kwargs.pop('max', None) if max_val is not None and not isinstance(max_val, int_types): throw(TypeError, "'max' argument for attribute %s must be int. Got: %r" % (attr, max_val)) size = kwargs.pop('size', None) if size is None: if attr.py_type.__name__ == 'long': deprecated(9, "Attribute %s: 'long' attribute type is deprecated. " "Please use 'int' type with size=64 option instead" % attr) attr.py_type = int size = 64 elif attr.py_type.__name__ == 'long': throw(TypeError, "Attribute %s: 'size' option cannot be used with long type. Please use int type instead" % attr) elif not isinstance(size, int_types): throw(TypeError, "'size' option for attribute %s must be of int type. Got: %r" % (attr, size)) elif size not in (8, 16, 24, 32, 64): throw(TypeError, "incorrect value of 'size' option for attribute %s. " "Should be 8, 16, 24, 32 or 64. Got: %d" % (attr, size)) unsigned = kwargs.pop('unsigned', False) if unsigned is not None and not isinstance(unsigned, bool): throw(TypeError, "'unsigned' option for attribute %s must be of bool type. Got: %r" % (attr, unsigned)) if size == 64 and unsigned and not converter.provider.uint64_support: throw(TypeError, 'Attribute %s: %s provider does not support unsigned bigint type' % (attr, converter.provider.dialect)) if unsigned is not None and size is None: size = 32 lowest = highest = None if size: highest = highest = 2 ** size - 1 if unsigned else 2 ** (size - 1) - 1 lowest = 0 if unsigned else -(2 ** (size - 1)) if highest is not None and max_val is not None and max_val > highest: throw(ValueError, "'max' argument should be less or equal to %d because of size=%d and unsigned=%s. " "Got: %d" % (highest, size, max_val, unsigned)) if lowest is not None and min_val is not None and min_val < lowest: throw(ValueError, "'min' argument should be greater or equal to %d because of size=%d and unsigned=%s. " "Got: %d" % (lowest, size, min_val, unsigned)) converter.min_val = min_val or lowest converter.max_val = max_val or highest converter.size = size converter.unsigned = unsigned