<s> """<STR_LIT>""" <EOL> from pyrseas . dbobject import DbObjectDict , DbSchemaObject <EOL> from pyrseas . dbobject import quote_id , commentable , ownable <EOL> class Operator ( DbSchemaObject ) : <EOL> """<STR_LIT>""" <EOL> keylist = [ '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> objtype = "<STR_LIT>" <EOL> single_extern_file = True <EOL> def extern_key ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % ( self . objtype . lower ( ) , self . name , <EOL> self . leftarg , self . rightarg ) <EOL> def qualname ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . schema == '<STR_LIT>' and self . name or "<STR_LIT>" % ( quote_id ( self . schema ) , self . name ) <EOL> def identifier ( self ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( self . qualname ( ) , self . leftarg , self . rightarg ) <EOL> @ commentable <EOL> @ ownable <EOL> def create ( self ) : <EOL> """<STR_LIT>""" <EOL> opt_clauses = [ ] <EOL> if self . leftarg != '<STR_LIT>' : <EOL> opt_clauses . append ( "<STR_LIT>" % self . leftarg ) <EOL> if self . rightarg != '<STR_LIT>' : <EOL> opt_clauses . append ( "<STR_LIT>" % self . rightarg ) <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> opt_clauses . append ( "<STR_LIT>" % self . commutator ) <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> opt_clauses . append ( "<STR_LIT>" % self . negator ) <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> opt_clauses . append ( "<STR_LIT>" % self . restrict ) <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> opt_clauses . append ( "<STR_LIT>" % self . join ) <EOL> if hasattr ( self , '<STR_LIT>' ) and self . hashes : <EOL> opt_clauses . append ( "<STR_LIT>" ) <EOL> if hasattr ( self , '<STR_LIT>' ) and self . merges : <EOL> opt_clauses . append ( "<STR_LIT>" ) <EOL> return [ "<STR_LIT>" % ( <EOL> self . qualname ( ) , self . procedure , <EOL> '<STR_LIT>' if opt_clauses else '<STR_LIT>' , '<STR_LIT>' . join ( opt_clauses ) ) ] <EOL> class OperatorDict ( DbObjectDict ) : <EOL> "<STR_LIT>" <EOL> cls = Operator <EOL> query = """<STR_LIT>""" <EOL> def _from_catalog ( self ) : <EOL> """<STR_LIT>""" <EOL> for oper in self . fetch ( ) : <EOL> sch , opr , lft , rgt = oper . key ( ) <EOL> if lft == '<STR_LIT:->' : <EOL> lft = oper . leftarg = '<STR_LIT>' <EOL> if rgt == '<STR_LIT:->' : <EOL> rgt = oper . rightarg = '<STR_LIT>' <EOL> if oper . commutator == '<STR_LIT:0>' : <EOL> del oper . commutator <EOL> if oper . negator == '<STR_LIT:0>' : <EOL> del oper . negator <EOL> if oper . restrict == '<STR_LIT:->' : <EOL> del oper . restrict <EOL> if oper . join == '<STR_LIT:->' : <EOL> del oper . join <EOL> self [ ( sch , opr , lft , rgt ) ] = Operator ( ** oper . __dict__ ) <EOL> def from_map ( self , schema , inopers ) : <EOL> """<STR_LIT>""" <EOL> for key in inopers : <EOL> ( objtype , spc , opr ) = key . partition ( '<STR_LIT:U+0020>' ) <EOL> if spc != '<STR_LIT:U+0020>' or objtype != '<STR_LIT>' : <EOL> raise KeyError ( "<STR_LIT>" % key ) <EOL> paren = opr . find ( '<STR_LIT:(>' ) <EOL> if paren == - <NUM_LIT:1> or opr [ - <NUM_LIT:1> : ] != '<STR_LIT:)>' : <EOL> raise KeyError ( "<STR_LIT>" % opr ) <EOL> ( leftarg , rightarg ) = opr [ paren + <NUM_LIT:1> : - <NUM_LIT:1> ] . split ( '<STR_LIT:U+002C>' ) <EOL> rightarg = rightarg . lstrip ( ) <EOL> inoper = inopers [ key ] <EOL> opr = opr [ : paren ] <EOL> self [ ( schema . name , opr , leftarg , rightarg ) ] = oper = Operator ( <EOL> schema = schema . name , name = opr , leftarg = leftarg , <EOL> rightarg = rightarg ) <EOL> if not inoper : <EOL> raise ValueError ( "<STR_LIT>" % opr ) <EOL> for attr , val in list ( inoper . items ( ) ) : <EOL> setattr ( oper , attr , val ) <EOL> if '<STR_LIT>' in inoper : <EOL> oper . oldname = inoper [ '<STR_LIT>' ] <EOL> if '<STR_LIT:description>' in inoper : <EOL> oper . description = inoper [ '<STR_LIT:description>' ] <EOL> def diff_map ( self , inopers ) : <EOL> """<STR_LIT>""" <EOL> stmts = [ ] <EOL> for ( sch , opr , lft , rgt ) in inopers : <EOL> inoper = inopers [ ( sch , opr , lft , rgt ) ] <EOL> if ( sch , opr , lft , rgt ) not in self : <EOL> if not hasattr ( inoper , '<STR_LIT>' ) : <EOL> stmts . append ( inoper . create ( ) ) <EOL> else : <EOL> stmts . append ( self [ ( sch , opr , lft , rgt ) ] . rename ( inoper ) ) <EOL> else : <EOL> stmts . append ( self [ ( sch , opr , lft , rgt ) ] . diff_map ( inoper ) ) <EOL> for ( sch , opr , lft , rgt ) in self : <EOL> oper = self [ ( sch , opr , lft , rgt ) ] <EOL> if ( sch , opr , lft , rgt ) not in inopers : <EOL> oper . dropped = False <EOL> return stmts <EOL> def _drop ( self ) : <EOL> """<STR_LIT>""" <EOL> stmts = [ ] <EOL> for ( sch , opr , lft , rgt ) in self : <EOL> oper = self [ ( sch , opr , lft , rgt ) ] <EOL> if hasattr ( oper , '<STR_LIT>' ) : <EOL> stmts . append ( oper . drop ( ) ) <EOL> return stmts </s>
