def __init__(self, doc, target, ConfigClass=None, default=None, check=None, deprecated=None): ConfigClass = self.validateTarget(target, ConfigClass) if default is None: default = ConfigClass if default != ConfigClass and type(default) != ConfigClass: raise TypeError("'default' is of incorrect type %s. Expected %s" % (_typeStr(default), _typeStr(ConfigClass))) source = getStackFrame() self._setup(doc=doc, dtype=ConfigurableInstance, default=default, check=check, optional=False, source=source, deprecated=deprecated) self.target = target self.ConfigClass = ConfigClass
def __init__(self, doc, dtype, default=None, optional=False, min=None, max=None, inclusiveMin=True, inclusiveMax=False, deprecated=None): if dtype not in self.supportedTypes: raise ValueError("Unsupported RangeField dtype %s" % (_typeStr(dtype))) source = getStackFrame() if min is None and max is None: raise ValueError("min and max cannot both be None") if min is not None and max is not None: if min > max: raise ValueError("min = %s > %s = max" % (min, max)) elif min == max and not (inclusiveMin and inclusiveMax): raise ValueError( "min = max = %s and min and max not both inclusive" % (min, )) self.min = min """Minimum value accepted in the range. If `None`, the range has no lower bound (equivalent to negative infinity). """ self.max = max """Maximum value accepted in the range. If `None`, the range has no upper bound (equivalent to positive infinity). """ if inclusiveMax: self.maxCheck = lambda x, y: True if y is None else x <= y else: self.maxCheck = lambda x, y: True if y is None else x < y if inclusiveMin: self.minCheck = lambda x, y: True if y is None else x >= y else: self.minCheck = lambda x, y: True if y is None else x > y self._setup(doc, dtype=dtype, default=default, check=None, optional=optional, source=source, deprecated=deprecated) self.rangeString = "%s%s,%s%s" % \ (("[" if inclusiveMin else "("), ("-inf" if self.min is None else self.min), ("inf" if self.max is None else self.max), ("]" if inclusiveMax else ")")) """String representation of the field's allowed range (`str`). """ self.__doc__ += "\n\nValid Range = " + self.rangeString
def __init__(self, doc, typemap, default=None, optional=False, multi=False, deprecated=None): source = getStackFrame() self._setup(doc=doc, dtype=self.instanceDictClass, default=default, check=None, optional=optional, source=source, deprecated=deprecated) self.typemap = typemap self.multi = multi
def __init__(self, doc, dtype, allowed, default=None, optional=True, deprecated=None): self.allowed = dict(allowed) if optional and None not in self.allowed: self.allowed[None] = "Field is optional" if len(self.allowed) == 0: raise ValueError("ChoiceFields must allow at least one choice") Field.__init__(self, doc=doc, dtype=dtype, default=default, check=None, optional=optional, deprecated=deprecated) self.__doc__ += "\n\nAllowed values:\n\n" for choice, choiceDoc in self.allowed.items(): if choice is not None and not isinstance(choice, dtype): raise ValueError("ChoiceField's allowed choice %s is of incorrect type %s. Expected %s" % (choice, _typeStr(choice), _typeStr(dtype))) self.__doc__ += "%s\n %s\n" % ('``{0!r}``'.format(str(choice)), choiceDoc) self.source = getStackFrame()
def __init__(self, doc, dtype, default=None, optional=False, listCheck=None, itemCheck=None, length=None, minLength=None, maxLength=None, deprecated=None): if dtype not in Field.supportedTypes: raise ValueError("Unsupported dtype %s" % _typeStr(dtype)) if length is not None: if length <= 0: raise ValueError("'length' (%d) must be positive" % length) minLength = None maxLength = None else: if maxLength is not None and maxLength <= 0: raise ValueError("'maxLength' (%d) must be positive" % maxLength) if minLength is not None and maxLength is not None \ and minLength > maxLength: raise ValueError("'maxLength' (%d) must be at least" " as large as 'minLength' (%d)" % (maxLength, minLength)) if listCheck is not None and not hasattr(listCheck, "__call__"): raise ValueError("'listCheck' must be callable") if itemCheck is not None and not hasattr(itemCheck, "__call__"): raise ValueError("'itemCheck' must be callable") source = getStackFrame() self._setup(doc=doc, dtype=List, default=default, check=None, optional=optional, source=source, deprecated=deprecated) self.listCheck = listCheck """Callable used to check the list as a whole. """ self.itemCheck = itemCheck """Callable used to validate individual items as they are inserted into the list. """ self.itemtype = dtype """Data type of list items. """ self.length = length """Number of items that must be present in the list (or `None` to disable checking the list's length). """ self.minLength = minLength """Minimum number of items that must be present in the list (or `None` to disable checking the list's minimum length). """ self.maxLength = maxLength """Maximum number of items that must be present in the list (or `None`