def __init__(self, name, **kwargs): if 'values' not in kwargs and 'callback' not in kwargs: raise NoSelectionError("Selection check must have iterable values or a callback function") self.callback = kwargs.pop('callback', None) self.use_callback = True if self.callback is not None else False self.allow_none = kwargs.pop('allow_none', False) self.required = kwargs.get('required', True) if not self.required: self.allow_none = True try: self._values = list(kwargs.pop('values', [])) except: raise BadSelectionsError("Selection must be iterable") self._values = [val for val in self._values if val] self.ignore_case = self._boolCheck(kwargs.pop('ignore_case', True), normalize=True) XCheck.__init__(self, name, **kwargs) self._object_atts.extend(['ignore_case', 'values', 'use_callback', 'allow_none']) if not self.use_callback and not self.values: raise NoSelectionError("must have values for selection test") for v in self._values: if not isinstance(v, basestring): raise BadSelectionsError("value %s is not string type" % v)
def __init__(self, name, **kwargs): self.min = NINF self.max = INF self.error = XCheckError XCheck.__init__(self, name, **kwargs) self._object_atts.extend(["min", "max"]) self.as_string = False
def __init__(self, name, **kwargs): self.delimiter = kwargs.pop('delimiter', ',') try: self._values = list(kwargs.pop('values', [])) except: raise BadSelectionsError('List values must be iterable') self.callback = kwargs.pop('callback', None) self.allow_duplicates = kwargs.pop('allow_duplicates', False) self.min_items = int(kwargs.pop('min_items', 0) ) self.max_items = int(kwargs.pop('max_items', -1) ) self.ignore_case = self._boolCheck( kwargs.pop('ignore_case', False), normalize=True) if self.max_items in [ -1, INF]: self.max_items = INF self.as_string = self._boolCheck( kwargs.pop('as_string', False), normalize=True) XCheck.__init__(self, name, **kwargs) self._object_atts.extend(['delimiter', 'values', 'allow_duplicates', 'min_items', 'max_items', 'ignore_case', 'as_string'])
def __init__(self, name, **kwargs): self.allow_none = get_bool(kwargs.pop('ignore_case', False)) self.format = kwargs.pop('format', "%a %b %d %H:%M:%S %Y") self.formats = kwargs.pop('formats', []) self.min_datetime = kwargs.pop('min_datetime', datetime.datetime.min.replace(year=1900)) self.max_datetime = kwargs.pop('max_datetime', datetime.datetime.max) #print self.min_datetime XCheck.__init__(self, name, **kwargs) self._object_atts.extend(['allow_none', 'format', 'formats', 'min_datetime', 'max_datetime']) if not isinstance(self.min_datetime, datetime.datetime): try: self.min_datetime = datetime.datetime.strptime( self.min_datetime, self.format) except: raise self.error("cannot parse minimum date") if not isinstance(self.max_datetime, datetime.datetime): try: self.max_datetime = datetime.datetime.strptime( self.max_datetime, self.format) except: raise self.error("cannot parse maximum date") self.as_datetime = False self.as_struct = False self.as_string = True self.as_date = False
def __init__(self, name, **kwargs): self.none_is_false = kwargs.pop('none_is_false', True) XCheck.__init__(self, name, **kwargs) self._object_atts.append('none_is_false') self.as_string = False