def get_cutoff(self): value = int_from_digit(self.params, is_strict=self.is_strict) if not value: return self.__exit__( exc_val=SphinxQLSyntaxException('"cutoff" option is empty') ) return 'cutoff=%s' % value
def get_max_query_time(self): value = int_from_digit(self.params, is_strict=self.is_strict) if not value: return self.__exit__( exc_val=SphinxQLSyntaxException('"max_query_time" option is empty') ) return 'max_query_time=%s' % value
def get_retry_delay(self): value = int_from_digit(self.params, is_strict=self.is_strict) if not value: return self.__exit__( exc_val=SphinxQLSyntaxException('"retry_delay" option is empty') ) return 'retry_delay=%s' % value
def get_index_weights(self): if not isinstance(self.params, dict): return self.__exit__( exc_val=SphinxQLSyntaxException( '%s is not a dict as expected' % str(self.params) ) ) clean_pairs = [] for field, value in self.params.items(): if not isinstance(field, six.string_types): return self.__exit__( exc_val=SphinxQLSyntaxException( '%s is not a string as expected' % field ) ) value = int_from_digit(value, self.is_strict) if not value: if not self.__exit__( exc_val=SphinxQLSyntaxException( 'One of the "index_weights" is not valid integer value' ) ): continue else: clean_pairs.append('='.join([field, str(value)])) return 'index_weights=(%s)' % ', '.join(clean_pairs)
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 get_index_weights(self): if not isinstance(self.params, dict): return self.__exit__(exc_val=SphinxQLSyntaxException( '%s is not a dict as expected' % str(self.params))) clean_pairs = [] for field, value in self.params.items(): if not isinstance(field, six.string_types): return self.__exit__(exc_val=SphinxQLSyntaxException( '%s is not a string as expected' % field)) value = int_from_digit(value, self.is_strict) if not value: if not self.__exit__(exc_val=SphinxQLSyntaxException( 'One of the "index_weights" is not valid integer value' )): continue else: clean_pairs.append('='.join([field, str(value)])) return 'index_weights=(%s)' % ', '.join(clean_pairs)
def test_int(self): self.assertEqual(int_from_digit(42), 42)
def test_str_strict(self): self.assertRaises( SphinxQLSyntaxException, lambda: int_from_digit('boom', is_strict=True), )
def test_str(self): self.assertIsNone(int_from_digit('boom'))
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)): # for v in self.v_attr: # if not isinstance(v, (int, float)) and not self.__exit__( # exc_val=SphinxQLSyntaxException( # 'value %s must be instance of int or float' % v # ) # ): # continue pass 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 get_max_matches(self): value = int_from_digit(self.params, is_strict=self.is_strict) if not value: return self.__exit__(exc_val=SphinxQLSyntaxException('"max_matches" option is empty')) return "max_matches=%s" % value
def test_digit_str(self): self.assertEqual(int_from_digit('42'), 42)
def get_retry_delay(self): value = int_from_digit(self.params, is_strict=self.is_strict) if not value: return self.__exit__(exc_val=SphinxQLSyntaxException( '"retry_delay" option is empty')) return 'retry_delay=%s' % value
def get_cutoff(self): value = int_from_digit(self.params, is_strict=self.is_strict) if not value: return self.__exit__( exc_val=SphinxQLSyntaxException('"cutoff" option is empty')) return 'cutoff=%s' % value
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 ) )
def get_max_query_time(self): value = int_from_digit(self.params, is_strict=self.is_strict) if not value: return self.__exit__(exc_val=SphinxQLSyntaxException( '"max_query_time" option is empty')) return 'max_query_time=%s' % value