def __enter__(self): pair = list_of_integers_only( [self.offset, self.limit], is_strict=self.is_strict, ) if len(pair) != 2: return self.__exit__( exc_val=SphinxQLSyntaxException( 'LIMIT clause wants a pair value and %s is not' % pair ) ) offset, limit = pair if offset < 0: return self.__exit__( exc_val=SphinxQLSyntaxException( '%s offset is less then 0' % offset ) ) if limit <= 0: return self.__exit__( exc_val=SphinxQLSyntaxException( 'The limit value has to be greater then 0, %s is not' % limit ) ) return pair
def __enter__(self): if not isinstance(self.k_attr, six.string_types): return self.__exit__(exc_val=SphinxQLSyntaxException( '%s is not a string as expected' % self.k_attr)) if not bool(self.k_attr.strip()): return self.__exit__( exc_val=SphinxQLSyntaxException('Field is empty')) if isinstance(self.v_attr, (list, tuple)): v_attr = '(%s)' % ','.join([ str(v) for v in list_of_integers_only( self.v_attr, self.is_strict, ) ]) elif (isinstance(self.v_attr, six.string_types) and self.v_attr.isdigit()): v_attr = self.v_attr elif isinstance(self.v_attr, (six.integer_types, float)): v_attr = str(self.v_attr) elif (isinstance(self.v_attr, six.string_types) and not bool(self.v_attr.strip()) or self.v_attr is None): v_attr = '()' else: return self.__exit__(exc_val=SphinxQLSyntaxException( '%s is improper value for UPDATE clause' % self.v_attr)) return '%s=%s' % (self.k_attr, v_attr)
def __enter__(self): v_attr = self.v_attr if isinstance(v_attr, six.string_types): v_attr = int_from_digit(v_attr, is_strict=self.is_strict) if isinstance(self.v_attr, (tuple, list)): v_attr = list_of_integers_only(v_attr, is_strict=self.is_strict) if isinstance(self.v_attr, (datetime, date)): v_attr = unix_timestamp(self.v_attr) if not v_attr and v_attr != 0: return None for ending in self._allowed_conditions_map.keys(): if not self.k_attr.endswith(ending): continue if ( ending not in ("__between", "__in") and isinstance(v_attr, (tuple, list)) and not self.__exit__( exc_val=SphinxQLSyntaxException( "%s found but not allowed for %s condition" % (self.v_attr, self.k_attr) ) ) ): continue if ( ending in ("__between", "__in") and not isinstance(v_attr, (tuple, list)) and not self.__exit__( exc_val=SphinxQLSyntaxException( "%s condition found but the type of %s is not list or tuple" % (self.k_attr, self.v_attr) ) ) ): continue a = self.k_attr[: self.k_attr.rindex(ending)] v = v_attr if ending == "__between": if (len(v_attr) != 2 or len(v_attr) != len(self.v_attr)) and not self.__exit__( exc_val=SphinxQLSyntaxException( "%s condition wants a pair value and %s is not" % (self.k_attr, self.v_attr) ) ): continue f_v, s_v = v_attr return self._allowed_conditions_map[ending].format(a=a, f_v=f_v, s_v=s_v) if ending == "__in": v = ",".join([str(v) for v in v_attr]) return self._allowed_conditions_map[ending].format(a=a, v=v) return self.__exit__(exc_val=SphinxQLSyntaxException("%s is invalid condition" % self.k_attr))
def __enter__(self): v_attr = self.v_attr if isinstance(v_attr, six.string_types): try: v_attr = int_from_digit(v_attr, is_strict=self.is_strict) except SphinxQLSyntaxException: pass if isinstance(self.v_attr, (tuple, list)): v_attr = list_of_integers_only(v_attr, is_strict=self.is_strict) if isinstance(self.v_attr, (datetime, date)): v_attr = unix_timestamp(self.v_attr) if not v_attr and v_attr != 0: return None for ending in self._allowed_conditions_map.keys(): if not self.k_attr.endswith(ending): continue if (ending not in ('__between', '__in') and isinstance(v_attr, (tuple, list)) and not self.__exit__(exc_val=SphinxQLSyntaxException( '%s found but not allowed for %s condition' % (self.v_attr, self.k_attr)))): continue if (ending in ('__between', '__in') and not isinstance( v_attr, (tuple, list) ) and not self.__exit__(exc_val=SphinxQLSyntaxException( '%s condition found but the type of %s is not list or tuple' % (self.k_attr, self.v_attr)))): continue a = self.k_attr[:self.k_attr.rindex(ending)] v = v_attr if ending == '__between': if ((len(v_attr) != 2 or len(v_attr) != len(self.v_attr)) and not self.__exit__(exc_val=SphinxQLSyntaxException( '%s condition wants a pair value and %s is not' % (self.k_attr, self.v_attr)))): continue f_v, s_v = v_attr return self._allowed_conditions_map[ending].format(a=a, f_v=f_v, s_v=s_v) if ending == '__in': v = ','.join([str(v) for v in v_attr]) return self._allowed_conditions_map[ending].format(a=a, v=v) return self.__exit__( exc_val=SphinxQLSyntaxException('%s is invalid condition' % self.k_attr))
def __enter__(self): pair = list_of_integers_only( [self.offset, self.limit], is_strict=self.is_strict, ) if len(pair) != 2: return self.__exit__(exc_val=SphinxQLSyntaxException( 'LIMIT clause wants a pair value and %s is not' % pair)) offset, limit = pair if offset < 0: return self.__exit__( exc_val=SphinxQLSyntaxException('%s offset is less then 0' % offset)) if limit <= 0: return self.__exit__(exc_val=SphinxQLSyntaxException( 'The limit value has to be greater then 0, %s is not' % limit)) return pair
def __enter__(self): if not isinstance(self.k_attr, six.string_types): return self.__exit__( exc_val=SphinxQLSyntaxException( '%s is not a string as expected' % self.k_attr ) ) if not bool(self.k_attr.strip()): return self.__exit__( exc_val=SphinxQLSyntaxException( 'Field is empty' ) ) if isinstance(self.v_attr, (list, tuple)): v_attr = '(%s)' % ','.join([ str(v) for v in list_of_integers_only( self.v_attr, self.is_strict, ) ]) elif ( isinstance(self.v_attr, six.string_types) and self.v_attr.isdigit() ): v_attr = self.v_attr elif isinstance(self.v_attr, (six.integer_types, float)): v_attr = str(self.v_attr) elif ( isinstance(self.v_attr, six.string_types) and not bool(self.v_attr.strip()) or self.v_attr is None ): v_attr = '()' else: return self.__exit__( exc_val=SphinxQLSyntaxException( '%s is improper value for UPDATE clause' % self.v_attr ) ) return '%s=%s' % (self.k_attr, v_attr)
def test_str_sequence_strict(self): sequence = [1, 'boom', 3, 4, '5'] self.assertRaises( SphinxQLSyntaxException, lambda: list_of_integers_only(sequence, is_strict=True), )
def test_str_sequence(self): sequence = [1, 'boom', 3, 4, '5'] self.assertListEqual(list_of_integers_only(sequence), [1, 3, 4, 5])
def test_clean_sequence(self): sequence = [1, 2, 3, 4, 5] self.assertListEqual(list_of_integers_only(sequence), sequence)
def __enter__(self): v_attr = self.v_attr if isinstance(v_attr, six.string_types): try: v_attr = int_from_digit( v_attr, is_strict=self.is_strict ) except SphinxQLSyntaxException: v_attr = string_for_value(v_attr, is_strict=self.is_strict) if isinstance(self.v_attr, (tuple, list)): # This tuple or list can be list of integer or strings try: v_attr = list_of_integers_only( v_attr, is_strict=self.is_strict ) except SphinxQLSyntaxException: #If This list is not integer check if it is strings v_attr = list_of_strings_only( v_attr, is_strict=self.is_strict ) if isinstance(self.v_attr, (datetime, date)): v_attr = unix_timestamp(self.v_attr) if not v_attr and v_attr != 0: return None for ending in self._allowed_conditions_map.keys(): if not self.k_attr.endswith(ending): continue if ( ending not in ('__between', '__in', '__notin') and isinstance(v_attr, (tuple, list)) and not self.__exit__( exc_val=SphinxQLSyntaxException( '%s found but not allowed for %s condition' % (self.v_attr, self.k_attr) ) ) ): continue if ( ending in ('__between', '__in', '__notin') and not isinstance(v_attr, (tuple, list)) and not self.__exit__( exc_val=SphinxQLSyntaxException( '%s condition found but the type of %s is not list or tuple' % (self.k_attr, self.v_attr) ) ) ): continue a = self.k_attr[:self.k_attr.rindex(ending)] v = v_attr if ending == '__between': if ( (len(v_attr) != 2 or len(v_attr) != len(self.v_attr)) and not self.__exit__( exc_val=SphinxQLSyntaxException( '%s condition wants a pair value and %s is not' % (self.k_attr, self.v_attr) ) ) ): continue f_v, s_v = v_attr return self._allowed_conditions_map[ending].format( a=a, f_v=f_v, s_v=s_v ) if ending in ('__in', '__notin'): v = ','.join([str(v) for v in v_attr]) return self._allowed_conditions_map[ending].format(a=a, v=v) return self.__exit__( exc_val=SphinxQLSyntaxException( '%s is invalid condition' % self.k_attr ) )