<s> from . import nodes <EOL> __all__ = [ "<STR_LIT>" ] <EOL> QUERY_TEMPLATE = """<STR_LIT>""" . replace ( "<STR_LIT:\n>" , "<STR_LIT:U+0020>" ) <EOL> class Tree ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , root ) : <EOL> self . _root = root <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" . format ( self . _root ) <EOL> @ property <EOL> def root ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _root <EOL> def sortkey ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _root . sortkey ( ) <EOL> def serialize ( self ) : <EOL> """<STR_LIT>""" <EOL> return repr ( self ) <EOL> def walk ( self , node_type = None ) : <EOL> """<STR_LIT>""" <EOL> pending = [ self . _root ] <EOL> while pending : <EOL> node = pending . pop ( ) <EOL> if not node_type or isinstance ( node , node_type ) : <EOL> yield node <EOL> if isinstance ( node , nodes . UnaryOp ) : <EOL> pending . append ( node . node ) <EOL> elif isinstance ( node , nodes . BinaryOp ) : <EOL> pending . extend ( [ node . left , node . right ] ) <EOL> def build_query ( self , page = <NUM_LIT:1> , page_size = <NUM_LIT:10> ) : <EOL> """<STR_LIT>""" <EOL> def get_table_joins ( tables ) : <EOL> joins = [ <EOL> ( "<STR_LIT>" , "<STR_LIT:code>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> ] <EOL> tmpl = "<STR_LIT>" <EOL> for args in joins : <EOL> if args [ <NUM_LIT:1> ] in tables : <EOL> yield tmpl % args <EOL> tables = set ( ) <EOL> cond , arglist , ranks , need_ranks = self . _root . parameterize ( tables ) <EOL> ranks = ranks or [ cond ] <EOL> if need_ranks : <EOL> score = "<STR_LIT>" % ( "<STR_LIT>" . join ( ranks ) , len ( ranks ) ) <EOL> else : <EOL> score = "<STR_LIT>" <EOL> joins = "<STR_LIT:U+0020>" . join ( get_table_joins ( tables ) ) <EOL> offset = ( page - <NUM_LIT:1> ) * page_size <EOL> query = QUERY_TEMPLATE % ( score , joins , cond , page_size , offset ) <EOL> return query , tuple ( arglist * <NUM_LIT:2> if need_ranks else arglist ) </s>
