<s> from . . languages import LANGS <EOL> __all__ = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] <EOL> class _Node ( object ) : <EOL> """<STR_LIT>""" <EOL> def _null_regex ( self , expr ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( expr , expr ) <EOL> def sortkey ( self ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" <EOL> def parameterize ( self , tables ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" , [ ] , [ ] , False <EOL> class _Literal ( object ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class String ( _Literal ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , string ) : <EOL> """<STR_LIT>""" <EOL> self . string = string <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" . format ( self . string ) <EOL> def sortkey ( self ) : <EOL> return self . string <EOL> class Regex ( _Literal ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , regex ) : <EOL> """<STR_LIT>""" <EOL> self . regex = regex <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" . format ( self . regex ) <EOL> def sortkey ( self ) : <EOL> return self . regex <EOL> class Text ( _Node ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , text ) : <EOL> """<STR_LIT>""" <EOL> self . text = text <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" . format ( self . text ) <EOL> def sortkey ( self ) : <EOL> return self . text . sortkey ( ) <EOL> def parameterize ( self , tables ) : <EOL> tables |= { "<STR_LIT:code>" , "<STR_LIT>" } <EOL> if isinstance ( self . text , Regex ) : <EOL> ranks = [ "<STR_LIT>" , "<STR_LIT>" , <EOL> self . _null_regex ( "<STR_LIT>" ) ] <EOL> text = self . text . regex <EOL> else : <EOL> ranks = [ "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> text = self . text . string <EOL> cond = "<STR_LIT:(>" + "<STR_LIT>" . join ( ranks ) + "<STR_LIT:)>" <EOL> return cond , [ text ] * <NUM_LIT:3> , ranks , True <EOL> class Language ( _Node ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , lang ) : <EOL> """<STR_LIT>""" <EOL> self . lang = lang <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" . format ( LANGS [ self . lang ] ) <EOL> def sortkey ( self ) : <EOL> return LANGS [ self . lang ] <EOL> def parameterize ( self , tables ) : <EOL> tables |= { "<STR_LIT:code>" } <EOL> return "<STR_LIT>" , [ self . lang ] , [ ] , False <EOL> class Author ( _Node ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name ) : <EOL> """<STR_LIT>""" <EOL> self . name = name <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" . format ( self . name ) <EOL> def sortkey ( self ) : <EOL> return self . name . sortkey ( ) <EOL> def parameterize ( self , tables ) : <EOL> tables |= { "<STR_LIT>" } <EOL> if isinstance ( self . name , Regex ) : <EOL> cond = self . _null_regex ( "<STR_LIT>" ) <EOL> return cond , [ self . name . regex ] , [ ] , False <EOL> cond = "<STR_LIT>" <EOL> return cond , [ self . name . string ] , [ ] , True <EOL> class Date ( _Node ) : <EOL> """<STR_LIT>""" <EOL> CREATE = <NUM_LIT:1> <EOL> MODIFY = <NUM_LIT:2> <EOL> BEFORE = <NUM_LIT:1> <EOL> AFTER = <NUM_LIT:2> <EOL> def __init__ ( self , type_ , relation , date ) : <EOL> """<STR_LIT>""" <EOL> self . type = type_ <EOL> self . relation = relation <EOL> self . date = date <EOL> def __repr__ ( self ) : <EOL> types = { self . CREATE : "<STR_LIT>" , self . MODIFY : "<STR_LIT>" } <EOL> relations = { self . BEFORE : "<STR_LIT>" , self . AFTER : "<STR_LIT>" } <EOL> tm = "<STR_LIT>" <EOL> return tm . format ( types [ self . type ] , relations [ self . relation ] , self . date ) <EOL> def sortkey ( self ) : <EOL> return self . date . strftime ( "<STR_LIT>" ) <EOL> def parameterize ( self , tables ) : <EOL> column = { self . CREATE : "<STR_LIT>" , <EOL> self . MODIFY : "<STR_LIT>" } [ self . type ] <EOL> op = { self . BEFORE : "<STR_LIT>" , self . AFTER : "<STR_LIT>" } [ self . relation ] <EOL> cond = "<STR_LIT>" % ( column , column , op ) <EOL> return cond , [ self . date ] , [ ] , False <EOL> class Symbol ( _Node ) : <EOL> """<STR_LIT>""" <EOL> ALL = - <NUM_LIT:1> <EOL> DEFINE = <NUM_LIT:0> <EOL> USE = <NUM_LIT:1> <EOL> FUNCTION = <NUM_LIT:0> <EOL> CLASS = <NUM_LIT:1> <EOL> VARIABLE = <NUM_LIT:2> <EOL> NAMESPACE = <NUM_LIT:3> <EOL> INTERFACE = <NUM_LIT:4> <EOL> IMPORT = <NUM_LIT:5> <EOL> TYPES = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> TYPE_REPR = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> def __init__ ( self , context , type_ , name ) : <EOL> """<STR_LIT>""" <EOL> self . context = context <EOL> self . type = type_ <EOL> self . name = name <EOL> def __repr__ ( self ) : <EOL> context = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] [ self . context ] <EOL> type_ = self . TYPE_REPR [ self . type ] if self . type >= <NUM_LIT:0> else "<STR_LIT>" <EOL> return "<STR_LIT>" . format ( context , type_ , self . name ) <EOL> def sortkey ( self ) : <EOL> return self . name . sortkey ( ) <EOL> def parameterize ( self , tables ) : <EOL> tables |= { "<STR_LIT:code>" , "<STR_LIT>" } <EOL> if isinstance ( self . name , Regex ) : <EOL> cond , name = self . _null_regex ( "<STR_LIT>" ) , self . name . regex <EOL> else : <EOL> cond , name = "<STR_LIT>" , self . name . string <EOL> if self . type == self . ALL : <EOL> types = "<STR_LIT:U+002CU+0020>" . join ( str ( typ ) for typ in xrange ( len ( self . TYPES ) ) ) <EOL> part = "<STR_LIT>" <EOL> cond += part % types <EOL> if self . type != self . ALL : <EOL> cond += "<STR_LIT>" % self . type <EOL> if self . context != self . ALL : <EOL> tables |= { "<STR_LIT>" } <EOL> cond += "<STR_LIT>" % self . context <EOL> return "<STR_LIT:(>" + cond + "<STR_LIT:)>" , [ name ] , [ ] , False <EOL> class BinaryOp ( _Node ) : <EOL> """<STR_LIT>""" <EOL> AND = object ( ) <EOL> OR = object ( ) <EOL> OPS = { AND : "<STR_LIT>" , OR : "<STR_LIT>" } <EOL> def __init__ ( self , left , op , right ) : <EOL> self . left = left <EOL> self . op = op <EOL> self . right = right <EOL> def __repr__ ( self ) : <EOL> tmpl = "<STR_LIT>" <EOL> return tmpl . format ( self . left , self . OPS [ self . op ] , self . right ) <EOL> def sortkey ( self ) : <EOL> return self . left . sortkey ( ) + self . right . sortkey ( ) <EOL> def parameterize ( self , tables ) : <EOL> lcond , largs , lranks , need_lranks = self . left . parameterize ( tables ) <EOL> rcond , rargs , rranks , need_rranks = self . right . parameterize ( tables ) <EOL> lranks , rranks = lranks or [ lcond ] , rranks or [ rcond ] <EOL> op = self . OPS [ self . op ] <EOL> cond = "<STR_LIT:(>" + lcond + "<STR_LIT:U+0020>" + op + "<STR_LIT:U+0020>" + rcond + "<STR_LIT:)>" <EOL> need_ranks = need_lranks or need_rranks or self . op == self . OR <EOL> return cond , largs + rargs , lranks + rranks , need_ranks <EOL> class UnaryOp ( _Node ) : <EOL> """<STR_LIT>""" <EOL> NOT = object ( ) <EOL> OPS = { NOT : "<STR_LIT>" } <EOL> def __init__ ( self , op , node ) : <EOL> self . op = op <EOL> self . node = node <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" . format ( self . OPS [ self . op ] , self . node ) <EOL> def sortkey ( self ) : <EOL> return self . node . sortkey ( ) <EOL> def parameterize ( self , tables ) : <EOL> cond , args , ranks , need_ranks = self . node . parameterize ( tables ) <EOL> new_cond = "<STR_LIT:(>" + self . OPS [ self . op ] + "<STR_LIT:U+0020>" + cond + "<STR_LIT:)>" <EOL> ranks = ranks or [ cond ] <EOL> return new_cond , args , ranks , need_ranks </s>
