#NEWLINE# def __query__( self , q ) : #NEWLINE# #INDENT# if ( not isinstance ( q , Query ) ) : #NEWLINE# #INDENT# raise TypeError ( 'Expected a Query.' , q ) #NEWLINE# #UNINDENT# variables = OrderedSet ( ) #NEWLINE# for tag in q . include : #NEWLINE# #INDENT# variables . update ( sq . __db__ [ tag ] ) #NEWLINE# #UNINDENT# for tag in q . require : #NEWLINE# #INDENT# variables . intersection_update ( self . __db__ [ tag ] ) #NEWLINE# #UNINDENT# for tag in q . exclude : #NEWLINE# #INDENT# variables . difference_update ( self . __db__ [ tag ] ) #NEWLINE# #UNINDENT# remove = OrderedSet ( ) #NEWLINE# add = OrderedSet ( ) #NEWLINE# for obj in variables : #NEWLINE# #INDENT# if isinstance ( obj , DB ) : #NEWLINE# #INDENT# def_sub_query = q #NEWLINE# if q . extra_optimizations : #NEWLINE# #INDENT# def_sub_query = copy . copy ( q ) #NEWLINE# def_sub_query . extra_optimizations = [ ] #NEWLINE# #UNINDENT# sq = q . subquery . get ( obj . name , def_sub_query ) #NEWLINE# replacement = obj . query ( sq ) #NEWLINE# replacement . name = obj . name #NEWLINE# remove . add ( obj ) #NEWLINE# add . add ( replacement ) #NEWLINE# #UNINDENT# #UNINDENT# variables . difference_update ( remove ) #NEWLINE# variables . update ( add ) #NEWLINE# return variables