def regex_filter(query, model, filters):
 regexp_op_map = {'postgresql': '~', 'mysql': 'REGEXP', 'oracle': 'REGEXP_LIKE', 'sqlite': 'REGEXP'}
 db_string = CONF.sql_connection.split(':')[0].split('+')[0]
 db_regexp_op = regexp_op_map.get(db_string, 'LIKE')
 for filter_name in filters.iterkeys():
  try:
   column_attr = getattr(model, filter_name)
  except AttributeError:
   continue
  if ('property' == type(column_attr).__name__):
   continue
  query = query.filter(column_attr.op(db_regexp_op)(str(filters[filter_name])))
 return query

def regex_filter ( query , model , filters ) : regexp_op_map = { 'postgresql' : '~' , 'mysql' : 'REGEXP' , 'oracle' : 'REGEXP_LIKE' , 'sqlite' : 'REGEXP' } db_string = CONF . sql_connection . split ( ':' ) [ 0 ] . split ( '+' ) [ 0 ] db_regexp_op = regexp_op_map . get ( db_string , 'LIKE' ) for filter_name in filters . iterkeys ( ) : try : column_attr = getattr ( model , filter_name ) except AttributeError : continue if ( 'property' == type ( column_attr ) . __name__ ) : continue query = query . filter ( column_attr . op ( db_regexp_op ) ( str ( filters [ filter_name ] ) ) ) return query
applies regular expression filtering to a query .