def sort(self, sort): if sort is None: sort = ASC sort = sort.upper() if sort not in (ASC, DESC): raise InvalidArgumentException('Type of order can be only %s or %s.' % (ASC, DESC)) self._sort = sort
def _parse_list(self, list_): for item in list_: if isinstance(item, (list, tuple)): self._parse_item(item) elif self.options.min_items == 1: self._parse_item((item, )) else: raise InvalidArgumentException('Too few arguments.')
def _check_value_type(self, value): # isinstance(True, (int, long)) is True => must be special condition if (not is_sql_instance(value) and ((bool not in self._allowed_types and isinstance(value, bool)) or not isinstance(value, self._allowed_types))): raise InvalidArgumentException( 'Relation "{}" is not allowed for data type "{}".'.format( self._string_representation, type(value)))
def wrapper(self, value, *args, **kwds): if ( (not isinstance(value, allowed_types) or (isinstance(value, bool) and bool not in allowed_types)) and not hasattr(value, 'tosql') ): raise InvalidArgumentException('%s cannot be of type %s.' % ( func.__name__, type(value), )) return func(self, value, *args, **kwds)
def join(self, arg, join_type=INNER_JOIN): if isinstance(arg, (list, tuple)) and len(arg) == 2: table = Table(*arg) elif isinstance(arg, dict) and len(arg) == 1: table = Table(*arg.popitem()) elif isinstance(arg, str): table = Table(arg) else: raise InvalidArgumentException('Invalid argument "{}" for join.'.format(arg)) self._joins.append({ 'type': join_type, 'table': table, 'ons': OnConditions(), })
def parse(self): if (self.options.min_items > 1 and self.input_data.is_args and self.input_data.count_of_args_is_in_interval( self.options.min_items, self.options.max_items)): self._parse_item(self.input_data.args) elif self.options.allow_list and self.input_data.is_list: self._parse_list(self.input_data.list) elif not self.input_data.is_dictionary and self.input_data.args: self._parse_list(self.input_data.args) if self.input_data.is_dictionary or self.input_data.is_kwds: if not self.options.allow_dict: raise InvalidArgumentException( 'Dictionary or kwds is disabled.') self._parse_dictionary(self.input_data.dictionary_or_kwds)
def _create_batch(self, values): if len(values) > self.options.max_items: raise InvalidArgumentException('Too many arguments.') return self._append_nones(tuple(values))
def _list(self): if self.value: return '({})'.format(', '.join(force_text(SqlValue(item)) for item in self.value)) raise InvalidArgumentException('Empty list is not allowed.')
def __init__(self, *expr): self._columns = Columns().columns(*expr) if not self._columns.is_set: raise InvalidArgumentException('You must specify columns for %s.' % self._function_name)
def union_type(self, union_type): if not union_type in UNION_TYPES: raise InvalidArgumentException('Union type can not be %s.' % union_type) self._union_type = union_type
def _list(self): if self.value: return six.u('(%s)') % six.u(', ').join(force_text(SqlValue(item)) for item in self.value) raise InvalidArgumentException('Empty list is not allowed.')