22 from .config
import Field, _typeStr
23 from .callStack
import getStackFrame
26 __all__ = [
"RangeField"]
31 Defines a Config Field which allows only a range of values. 32 The range is defined by providing min and/or max values. 33 If min or max is None, the range will be open in that direction 34 If inclusive[Min|Max] is True the range will include the [min|max] value 38 supportedTypes = set((int, float))
40 def __init__(self, doc, dtype, default=None, optional=False,
41 min=None, max=None, inclusiveMin=True, inclusiveMax=False):
43 raise ValueError(
"Unsupported RangeField dtype %s" % (_typeStr(dtype)))
45 if min
is None and max
is None:
46 raise ValueError(
"min and max cannot both be None")
48 if min
is not None and max
is not None:
50 raise ValueError(
"min = %s > %s = max" % (min, max))
51 elif min == max
and not (inclusiveMin
and inclusiveMax):
52 raise ValueError(
"min = max = %s and min and max not both inclusive" % (min,))
58 self.
maxCheck =
lambda x, y:
True if y
is None else x <= y
60 self.
maxCheck =
lambda x, y:
True if y
is None else x < y
62 self.
minCheck =
lambda x, y:
True if y
is None else x >= y
64 self.
minCheck =
lambda x, y:
True if y
is None else x > y
65 self.
_setup(doc, dtype=dtype, default=default, check=
None, optional=optional, source=source)
67 ((
"[" if inclusiveMin
else "("),
68 (
"-inf" if self.
min is None else self.
min),
69 (
"inf" if self.
max is None else self.
max),
70 (
"]" if inclusiveMax
else ")"))
73 def _validateValue(self, value):
74 Field._validateValue(self, value)
77 msg =
"%s is outside of valid range %s" % (value, self.
rangeString)
def __init__(self, doc, dtype, default=None, optional=False, min=None, max=None, inclusiveMin=True, inclusiveMax=False)
def _setup(self, doc, dtype, default, check, optional, source)
def getStackFrame(relative=0)