def union_q(token):
 query = Q()
 operation = 'and'
 negation = False
 for t in token:
  if (type(t) is ParseResults):
   query &= union_q(t)
  elif (t in ('or', 'and')):
   operation = t
  elif (t == '-'):
   negation = True
  else:
   if negation:
    t = (~ t)
   if (operation == 'or'):
    query |= t
   else:
    query &= t
 return query

def union_q ( token ) : query = Q ( ) operation = 'and' negation = False for t in token : if ( type ( t ) is ParseResults ) : query &= union_q ( t ) elif ( t in ( 'or' , 'and' ) ) : operation = t elif ( t == '-' ) : negation = True else : if negation : t = ( ~ t ) if ( operation == 'or' ) : query |= t else : query &= t return query
appends all the q() objects .