<s> """<STR_LIT>""" <EOL> from . elements import ClauseElement , TextClause , ClauseList , and_ , Grouping , UnaryExpression , literal_column <EOL> from . elements import _clone , _literal_as_text , _interpret_as_column_or_from , _expand_cloned , _select_iterables , _anonymous_label , _clause_element_as_expr , _cloned_intersection , _cloned_difference , True_ , _only_column_elements , TRUE <EOL> from . base import Immutable , Executable , _generative , ColumnCollection , ColumnSet , _from_objects , Generative <EOL> from . import type_api <EOL> from . . import inspection <EOL> from . . import util <EOL> from . . import exc <EOL> from operator import attrgetter <EOL> from . import operators <EOL> import operator <EOL> import collections <EOL> from . annotation import Annotated <EOL> import itertools <EOL> def _interpret_as_from ( element ) : <EOL> insp = inspection . inspect ( element , raiseerr = False ) <EOL> if insp is None : <EOL> if isinstance ( element , util . string_types ) : <EOL> return TextClause ( util . text_type ( element ) ) <EOL> elif hasattr ( insp , "<STR_LIT>" ) : <EOL> return insp . selectable <EOL> raise exc . ArgumentError ( "<STR_LIT>" ) <EOL> def _interpret_as_select ( element ) : <EOL> element = _interpret_as_from ( element ) <EOL> if isinstance ( element , Alias ) : <EOL> element = element . original <EOL> if not isinstance ( element , SelectBase ) : <EOL> element = element . select ( ) <EOL> return element <EOL> def subquery ( alias , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return Select ( * args , ** kwargs ) . alias ( alias ) <EOL> def alias ( selectable , name = None , flat = False ) : <EOL> """<STR_LIT>""" <EOL> return selectable . alias ( name = name , flat = flat ) <EOL> class Selectable ( ClauseElement ) : <EOL> """<STR_LIT>""" <EOL> __visit_name__ = '<STR_LIT>' <EOL> is_selectable = True <EOL> @ property <EOL> def selectable ( self ) : <EOL> return self <EOL> class FromClause ( Selectable ) : <EOL> """<STR_LIT>""" <EOL> __visit_name__ = '<STR_LIT>' <EOL> named_with_column = False <EOL> _hide_froms = [ ] <EOL> _is_join = False <EOL> _is_select = False <EOL> _is_from_container = False <EOL> _textual = False <EOL> """<STR_LIT>""" <EOL> schema = None <EOL> """<STR_LIT>""" <EOL> _memoized_property = util . group_expirable_memoized_property ( [ "<STR_LIT>" ] ) <EOL> @ util . dependencies ( "<STR_LIT>" ) <EOL> def count ( self , functions , whereclause = None , ** params ) : <EOL> """<STR_LIT>""" <EOL> if self . primary_key : <EOL> col = list ( self . primary_key ) [ <NUM_LIT:0> ] <EOL> else : <EOL> col = list ( self . columns ) [ <NUM_LIT:0> ] <EOL> return Select ( <EOL> [ functions . func . count ( col ) . label ( '<STR_LIT>' ) ] , <EOL> whereclause , <EOL> from_obj = [ self ] , <EOL> ** params ) <EOL> def select ( self , whereclause = None , ** params ) : <EOL> """<STR_LIT>""" <EOL> return Select ( [ self ] , whereclause , ** params ) <EOL> def join ( self , right , onclause = None , isouter = False ) : <EOL> """<STR_LIT>""" <EOL> return Join ( self , right , onclause , isouter ) <EOL> def outerjoin ( self , right , onclause = None ) : <EOL> """<STR_LIT>""" <EOL> return Join ( self , right , onclause , True ) <EOL> def alias ( self , name = None , flat = False ) : <EOL> """<STR_LIT>""" <EOL> return Alias ( self , name ) <EOL> def is_derived_from ( self , fromclause ) : <EOL> """<STR_LIT>""" <EOL> return fromclause in self . _cloned_set <EOL> def _is_lexical_equivalent ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return self . _cloned_set . intersection ( other . _cloned_set ) <EOL> @ util . dependencies ( "<STR_LIT>" ) <EOL> def replace_selectable ( self , sqlutil , old , alias ) : <EOL> """<STR_LIT>""" <EOL> return sqlutil . ClauseAdapter ( alias ) . traverse ( self ) <EOL> def correspond_on_equivalents ( self , column , equivalents ) : <EOL> """<STR_LIT>""" <EOL> col = self . corresponding_column ( column , require_embedded = True ) <EOL> if col is None and col in equivalents : <EOL> for equiv in equivalents [ col ] : <EOL> nc = self . corresponding_column ( equiv , require_embedded = True ) <EOL> if nc : <EOL> return nc <EOL> return col <EOL> def corresponding_column ( self , column , require_embedded = False ) : <EOL> """<STR_LIT>""" <EOL> def embedded ( expanded_proxy_set , target_set ) : <EOL> for t in target_set . difference ( expanded_proxy_set ) : <EOL> if not set ( _expand_cloned ( [ t ] ) <EOL> ) . intersection ( expanded_proxy_set ) : <EOL> return False <EOL> return True <EOL> if self . c . contains_column ( column ) : <EOL> return column <EOL> col , intersect = None , None <EOL> target_set = column . proxy_set <EOL> cols = self . c . _all_columns <EOL> for c in cols : <EOL> expanded_proxy_set = set ( _expand_cloned ( c . proxy_set ) ) <EOL> i = target_set . intersection ( expanded_proxy_set ) <EOL> if i and ( not require_embedded <EOL> or embedded ( expanded_proxy_set , target_set ) ) : <EOL> if col is None : <EOL> col , intersect = c , i <EOL> elif len ( i ) > len ( intersect ) : <EOL> col , intersect = c , i <EOL> elif i == intersect : <EOL> col_distance = util . reduce ( <EOL> operator . add , <EOL> [ sc . _annotations . get ( '<STR_LIT>' , <NUM_LIT:1> ) for sc in <EOL> col . proxy_set if sc . shares_lineage ( column ) ] ) <EOL> c_distance = util . reduce ( <EOL> operator . add , <EOL> [ sc . _annotations . get ( '<STR_LIT>' , <NUM_LIT:1> ) for sc in <EOL> c . proxy_set if sc . shares_lineage ( column ) ] ) <EOL> if c_distance < col_distance : <EOL> col , intersect = c , i <EOL> return col <EOL> @ property <EOL> def description ( self ) : <EOL> """<STR_LIT>""" <EOL> return getattr ( self , '<STR_LIT:name>' , self . __class__ . __name__ + "<STR_LIT>" ) <EOL> def _reset_exported ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _memoized_property . expire_instance ( self ) <EOL> @ _memoized_property <EOL> def columns ( self ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' not in self . __dict__ : <EOL> self . _init_collections ( ) <EOL> self . _populate_column_collection ( ) <EOL> return self . _columns . as_immutable ( ) <EOL> @ _memoized_property <EOL> def primary_key ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _init_collections ( ) <EOL> self . _populate_column_collection ( ) <EOL> return self . primary_key <EOL> @ _memoized_property <EOL> def foreign_keys ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _init_collections ( ) <EOL> self . _populate_column_collection ( ) <EOL> return self . foreign_keys <EOL> c = property ( attrgetter ( '<STR_LIT>' ) , <EOL> doc = "<STR_LIT>" ) <EOL> _select_iterable = property ( attrgetter ( '<STR_LIT>' ) ) <EOL> def _init_collections ( self ) : <EOL> assert '<STR_LIT>' not in self . __dict__ <EOL> assert '<STR_LIT:primary_key>' not in self . __dict__ <EOL> assert '<STR_LIT>' not in self . __dict__ <EOL> self . _columns = ColumnCollection ( ) <EOL> self . primary_key = ColumnSet ( ) <EOL> self . foreign_keys = set ( ) <EOL> @ property <EOL> def _cols_populated ( self ) : <EOL> return '<STR_LIT>' in self . __dict__ <EOL> def _populate_column_collection ( self ) : <EOL> """<STR_LIT>""" <EOL> def _refresh_for_new_column ( self , column ) : <EOL> """<STR_LIT>""" <EOL> if not self . _cols_populated : <EOL> return None <EOL> elif ( column . key in self . columns and <EOL> self . columns [ column . key ] is column ) : <EOL> return column <EOL> else : <EOL> return None <EOL> class Join ( FromClause ) : <EOL> """<STR_LIT>""" <EOL> __visit_name__ = '<STR_LIT>' <EOL> _is_join = True <EOL> def __init__ ( self , left , right , onclause = None , isouter = False ) : <EOL> """<STR_LIT>""" <EOL> self . left = _interpret_as_from ( left ) <EOL> self . right = _interpret_as_from ( right ) . self_group ( ) <EOL> if onclause is None : <EOL> self . onclause = self . _match_primaries ( self . left , self . right ) <EOL> else : <EOL> self . onclause = onclause <EOL> self . isouter = isouter <EOL> @ classmethod <EOL> def _create_outerjoin ( cls , left , right , onclause = None ) : <EOL> """<STR_LIT>""" <EOL> return cls ( left , right , onclause , isouter = True ) <EOL> @ classmethod <EOL> def _create_join ( cls , left , right , onclause = None , isouter = False ) : <EOL> """<STR_LIT>""" <EOL> return cls ( left , right , onclause , isouter ) <EOL> @ property <EOL> def description ( self ) : <EOL> return "<STR_LIT>" % ( <EOL> self . left . description , <EOL> id ( self . left ) , <EOL> self . right . description , <EOL> id ( self . right ) ) <EOL> def is_derived_from ( self , fromclause ) : <EOL> return fromclause is self or self . left . is_derived_from ( fromclause ) or self . right . is_derived_from ( fromclause ) <EOL> def self_group ( self , against = None ) : <EOL> return FromGrouping ( self ) <EOL> @ util . dependencies ( "<STR_LIT>" ) <EOL> def _populate_column_collection ( self , sqlutil ) : <EOL> columns = [ c for c in self . left . columns ] + [ c for c in self . right . columns ] <EOL> self . primary_key . extend ( sqlutil . reduce_columns ( <EOL> ( c for c in columns if c . primary_key ) , self . onclause ) ) <EOL> self . _columns . update ( ( col . _label , col ) for col in columns ) <EOL> self . foreign_keys . update ( itertools . chain ( <EOL> * [ col . foreign_keys for col in columns ] ) ) <EOL> def _refresh_for_new_column ( self , column ) : <EOL> col = self . left . _refresh_for_new_column ( column ) <EOL> if col is None : <EOL> col = self . right . _refresh_for_new_column ( column ) <EOL> if col is not None : <EOL> if self . _cols_populated : <EOL> self . _columns [ col . _label ] = col <EOL> self . foreign_keys . add ( col ) <EOL> if col . primary_key : <EOL> self . primary_key . add ( col ) <EOL> return col <EOL> return None <EOL> def _copy_internals ( self , clone = _clone , ** kw ) : <EOL> self . _reset_exported ( ) <EOL> self . left = clone ( self . left , ** kw ) <EOL> self . right = clone ( self . right , ** kw ) <EOL> self . onclause = clone ( self . onclause , ** kw ) <EOL> def get_children ( self , ** kwargs ) : <EOL> return self . left , self . right , self . onclause <EOL> def _match_primaries ( self , left , right ) : <EOL> if isinstance ( left , Join ) : <EOL> left_right = left . right <EOL> else : <EOL> left_right = None <EOL> return self . _join_condition ( left , right , a_subset = left_right ) <EOL> @ classmethod <EOL> def _join_condition ( cls , a , b , ignore_nonexistent_tables = False , <EOL> a_subset = None , <EOL> consider_as_foreign_keys = None ) : <EOL> """<STR_LIT>""" <EOL> constraints = collections . defaultdict ( list ) <EOL> for left in ( a_subset , a ) : <EOL> if left is None : <EOL> continue <EOL> for fk in sorted ( <EOL> b . foreign_keys , <EOL> key = lambda fk : fk . parent . _creation_order ) : <EOL> if consider_as_foreign_keys is not None and fk . parent not in consider_as_foreign_keys : <EOL> continue <EOL> try : <EOL> col = fk . get_referent ( left ) <EOL> except exc . NoReferenceError as nrte : <EOL> if nrte . table_name == left . name : <EOL> raise <EOL> else : <EOL> continue <EOL> if col is not None : <EOL> constraints [ fk . constraint ] . append ( ( col , fk . parent ) ) <EOL> if left is not b : <EOL> for fk in sorted ( <EOL> left . foreign_keys , <EOL> key = lambda fk : fk . parent . _creation_order ) : <EOL> if consider_as_foreign_keys is not None and fk . parent not in consider_as_foreign_keys : <EOL> continue <EOL> try : <EOL> col = fk . get_referent ( b ) <EOL> except exc . NoReferenceError as nrte : <EOL> if nrte . table_name == b . name : <EOL> raise <EOL> else : <EOL> continue <EOL> if col is not None : <EOL> constraints [ fk . constraint ] . append ( ( col , fk . parent ) ) <EOL> if constraints : <EOL> break <EOL> if len ( constraints ) > <NUM_LIT:1> : <EOL> if consider_as_foreign_keys : <EOL> for const in list ( constraints ) : <EOL> if set ( f . parent for f in const . elements ) != set ( <EOL> consider_as_foreign_keys ) : <EOL> del constraints [ const ] <EOL> if len ( constraints ) > <NUM_LIT:1> : <EOL> dedupe = set ( tuple ( crit ) for crit in constraints . values ( ) ) <EOL> if len ( dedupe ) == <NUM_LIT:1> : <EOL> key = list ( constraints ) [ <NUM_LIT:0> ] <EOL> constraints = { key : constraints [ key ] } <EOL> if len ( constraints ) != <NUM_LIT:1> : <EOL> raise exc . AmbiguousForeignKeysError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( a . description , b . description ) ) <EOL> if len ( constraints ) == <NUM_LIT:0> : <EOL> if isinstance ( b , FromGrouping ) : <EOL> hint = "<STR_LIT>" "<STR_LIT>" <EOL> else : <EOL> hint = "<STR_LIT>" <EOL> raise exc . NoForeignKeysError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( a . description , b . description , hint ) ) <EOL> crit = [ ( x == y ) for x , y in list ( constraints . values ( ) ) [ <NUM_LIT:0> ] ] <EOL> if len ( crit ) == <NUM_LIT:1> : <EOL> return ( crit [ <NUM_LIT:0> ] ) <EOL> else : <EOL> return and_ ( * crit ) <EOL> def select ( self , whereclause = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> collist = [ self . left , self . right ] <EOL> return Select ( collist , whereclause , from_obj = [ self ] , ** kwargs ) <EOL> @ property <EOL> def bind ( self ) : <EOL> return self . left . bind or self . right . bind <EOL> @ util . dependencies ( "<STR_LIT>" ) <EOL> def alias ( self , sqlutil , name = None , flat = False ) : <EOL> """<STR_LIT>""" <EOL> if flat : <EOL> assert name is None , "<STR_LIT>" <EOL> left_a , right_a = self . left . alias ( flat = True ) , self . right . alias ( flat = True ) <EOL> adapter = sqlutil . ClauseAdapter ( left_a ) . chain ( sqlutil . ClauseAdapter ( right_a ) ) <EOL> return left_a . join ( right_a , adapter . traverse ( self . onclause ) , <EOL> isouter = self . isouter ) <EOL> else : <EOL> return self . select ( use_labels = True , correlate = False ) . alias ( name ) <EOL> @ property <EOL> def _hide_froms ( self ) : <EOL> return itertools . chain ( * [ _from_objects ( x . left , x . right ) <EOL> for x in self . _cloned_set ] ) <EOL> @ property <EOL> def _from_objects ( self ) : <EOL> return [ self ] + self . onclause . _from_objects + self . left . _from_objects + self . right . _from_objects <EOL> class Alias ( FromClause ) : <EOL> """<STR_LIT>""" <EOL> __visit_name__ = '<STR_LIT>' <EOL> named_with_column = True <EOL> _is_from_container = True <EOL> def __init__ ( self , selectable , name = None ) : <EOL> baseselectable = selectable <EOL> while isinstance ( baseselectable , Alias ) : <EOL> baseselectable = baseselectable . element <EOL> self . original = baseselectable <EOL> self . supports_execution = baseselectable . supports_execution <EOL> if self . supports_execution : <EOL> self . _execution_options = baseselectable . _execution_options <EOL> self . element = selectable <EOL> if name is None : <EOL> if self . original . named_with_column : <EOL> name = getattr ( self . original , '<STR_LIT:name>' , None ) <EOL> name = _anonymous_label ( '<STR_LIT>' % ( id ( self ) , name <EOL> or '<STR_LIT>' ) ) <EOL> self . name = name <EOL> @ property <EOL> def description ( self ) : <EOL> if util . py3k : <EOL> return self . name <EOL> else : <EOL> return self . name . encode ( '<STR_LIT:ascii>' , '<STR_LIT>' ) <EOL> def as_scalar ( self ) : <EOL> try : <EOL> return self . element . as_scalar ( ) <EOL> except AttributeError : <EOL> raise AttributeError ( "<STR_LIT>" <EOL> "<STR_LIT>" % self . element ) <EOL> def is_derived_from ( self , fromclause ) : <EOL> if fromclause in self . _cloned_set : <EOL> return True <EOL> return self . element . is_derived_from ( fromclause ) <EOL> def _populate_column_collection ( self ) : <EOL> for col in self . element . columns . _all_columns : <EOL> col . _make_proxy ( self ) <EOL> def _refresh_for_new_column ( self , column ) : <EOL> col = self . element . _refresh_for_new_column ( column ) <EOL> if col is not None : <EOL> if not self . _cols_populated : <EOL> return None <EOL> else : <EOL> return col . _make_proxy ( self ) <EOL> else : <EOL> return None <EOL> def _copy_internals ( self , clone = _clone , ** kw ) : <EOL> if isinstance ( self . element , TableClause ) : <EOL> return <EOL> self . _reset_exported ( ) <EOL> self . element = clone ( self . element , ** kw ) <EOL> baseselectable = self . element <EOL> while isinstance ( baseselectable , Alias ) : <EOL> baseselectable = baseselectable . element <EOL> self . original = baseselectable <EOL> def get_children ( self , column_collections = True , ** kw ) : <EOL> if column_collections : <EOL> for c in self . c : <EOL> yield c <EOL> yield self . element <EOL> @ property <EOL> def _from_objects ( self ) : <EOL> return [ self ] <EOL> @ property <EOL> def bind ( self ) : <EOL> return self . element . bind <EOL> class CTE ( Alias ) : <EOL> """<STR_LIT>""" <EOL> __visit_name__ = '<STR_LIT>' <EOL> def __init__ ( self , selectable , <EOL> name = None , <EOL> recursive = False , <EOL> _cte_alias = None , <EOL> _restates = frozenset ( ) ) : <EOL> self . recursive = recursive <EOL> self . _cte_alias = _cte_alias <EOL> self . _restates = _restates <EOL> super ( CTE , self ) . __init__ ( selectable , name = name ) <EOL> def alias ( self , name = None , flat = False ) : <EOL> return CTE ( <EOL> self . original , <EOL> name = name , <EOL> recursive = self . recursive , <EOL> _cte_alias = self , <EOL> ) <EOL> def union ( self , other ) : <EOL> return CTE ( <EOL> self . original . union ( other ) , <EOL> name = self . name , <EOL> recursive = self . recursive , <EOL> _restates = self . _restates . union ( [ self ] ) <EOL> ) <EOL> def union_all ( self , other ) : <EOL> return CTE ( <EOL> self . original . union_all ( other ) , <EOL> name = self . name , <EOL> recursive = self . recursive , <EOL> _restates = self . _restates . union ( [ self ] ) <EOL> ) <EOL> class FromGrouping ( FromClause ) : <EOL> """<STR_LIT>""" <EOL> __visit_name__ = '<STR_LIT>' <EOL> def __init__ ( self , element ) : <EOL> self . element = element <EOL> def _init_collections ( self ) : <EOL> pass <EOL> @ property <EOL> def columns ( self ) : <EOL> return self . element . columns <EOL> @ property <EOL> def primary_key ( self ) : <EOL> return self . element . primary_key <EOL> @ property <EOL> def foreign_keys ( self ) : <EOL> return self . element . foreign_keys <EOL> def is_derived_from ( self , element ) : <EOL> return self . element . is_derived_from ( element ) <EOL> def alias ( self , ** kw ) : <EOL> return FromGrouping ( self . element . alias ( ** kw ) ) <EOL> @ property <EOL> def _hide_froms ( self ) : <EOL> return self . element . _hide_froms <EOL> def get_children ( self , ** kwargs ) : <EOL> return self . element , <EOL> def _copy_internals ( self , clone = _clone , ** kw ) : <EOL> self . element = clone ( self . element , ** kw ) <EOL> @ property <EOL> def _from_objects ( self ) : <EOL> return self . element . _from_objects <EOL> def __getattr__ ( self , attr ) : <EOL> return getattr ( self . element , attr ) <EOL> def __getstate__ ( self ) : <EOL> return { '<STR_LIT>' : self . element } <EOL> def __setstate__ ( self , state ) : <EOL> self . element = state [ '<STR_LIT>' ] <EOL> class TableClause ( Immutable , FromClause ) : <EOL> """<STR_LIT>""" <EOL> __visit_name__ = '<STR_LIT>' <EOL> named_with_column = True <EOL> implicit_returning = False <EOL> """<STR_LIT>""" <EOL> _autoincrement_column = None <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , * columns ) : <EOL> """<STR_LIT>""" <EOL> super ( TableClause , self ) . __init__ ( ) <EOL> self . name = self . fullname = name <EOL> self . _columns = ColumnCollection ( ) <EOL> self . primary_key = ColumnSet ( ) <EOL> self . foreign_keys = set ( ) <EOL> for c in columns : <EOL> self . append_column ( c ) <EOL> def _init_collections ( self ) : <EOL> pass <EOL> @ util . memoized_property <EOL> def description ( self ) : <EOL> if util . py3k : <EOL> return self . name <EOL> else : <EOL> return self . name . encode ( '<STR_LIT:ascii>' , '<STR_LIT>' ) <EOL> def append_column ( self , c ) : <EOL> self . _columns [ c . key ] = c <EOL> c . table = self <EOL> def get_children ( self , column_collections = True , ** kwargs ) : <EOL> if column_collections : <EOL> return [ c for c in self . c ] <EOL> else : <EOL> return [ ] <EOL> @ util . dependencies ( "<STR_LIT>" ) <EOL> def count ( self , functions , whereclause = None , ** params ) : <EOL> """<STR_LIT>""" <EOL> if self . primary_key : <EOL> col = list ( self . primary_key ) [ <NUM_LIT:0> ] <EOL> else : <EOL> col = list ( self . columns ) [ <NUM_LIT:0> ] <EOL> return Select ( <EOL> [ functions . func . count ( col ) . label ( '<STR_LIT>' ) ] , <EOL> whereclause , <EOL> from_obj = [ self ] , <EOL> ** params ) <EOL> @ util . dependencies ( "<STR_LIT>" ) <EOL> def insert ( self , dml , values = None , inline = False , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return dml . Insert ( self , values = values , inline = inline , ** kwargs ) <EOL> @ util . dependencies ( "<STR_LIT>" ) <EOL> def update ( <EOL> self , dml , whereclause = None , values = None , inline = False , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return dml . Update ( self , whereclause = whereclause , <EOL> values = values , inline = inline , ** kwargs ) <EOL> @ util . dependencies ( "<STR_LIT>" ) <EOL> def delete ( self , dml , whereclause = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return dml . Delete ( self , whereclause , ** kwargs ) <EOL> @ property <EOL> def _from_objects ( self ) : <EOL> return [ self ] <EOL> class ForUpdateArg ( ClauseElement ) : <EOL> @ classmethod <EOL> def parse_legacy_select ( self , arg ) : <EOL> """<STR_LIT>""" <EOL> if arg in ( None , False ) : <EOL> return None <EOL> nowait = read = False <EOL> if arg == '<STR_LIT>' : <EOL> nowait = True <EOL> elif arg == '<STR_LIT>' : <EOL> read = True <EOL> elif arg == '<STR_LIT>' : <EOL> read = nowait = True <EOL> elif arg is not True : <EOL> raise exc . ArgumentError ( "<STR_LIT>" % arg ) <EOL> return ForUpdateArg ( read = read , nowait = nowait ) <EOL> @ property <EOL> def legacy_for_update_value ( self ) : <EOL> if self . read and not self . nowait : <EOL> return "<STR_LIT>" <EOL> elif self . read and self . nowait : <EOL> return "<STR_LIT>" <EOL> elif self . nowait : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return True <EOL> def _copy_internals ( self , clone = _clone , ** kw ) : <EOL> if self . of is not None : <EOL> self . of = [ clone ( col , ** kw ) for col in self . of ] <EOL> def __init__ ( self , nowait = False , read = False , of = None ) : <EOL> """<STR_LIT>""" <EOL> self . nowait = nowait <EOL> self . read = read <EOL> if of is not None : <EOL> self . of = [ _interpret_as_column_or_from ( elem ) <EOL> for elem in util . to_list ( of ) ] <EOL> else : <EOL> self . of = None <EOL> class SelectBase ( Executable , FromClause ) : <EOL> """<STR_LIT>""" <EOL> def as_scalar ( self ) : <EOL> """<STR_LIT>""" <EOL> return ScalarSelect ( self ) <EOL> def label ( self , name ) : <EOL> """<STR_LIT>""" <EOL> return self . as_scalar ( ) . label ( name ) <EOL> def cte ( self , name = None , recursive = False ) : <EOL> """<STR_LIT>""" <EOL> return CTE ( self , name = name , recursive = recursive ) <EOL> @ _generative <EOL> @ util . deprecated ( '<STR_LIT>' , <EOL> message = "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def autocommit ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _execution_options = self . _execution_options . union ( { '<STR_LIT>' : True } ) <EOL> def _generate ( self ) : <EOL> """<STR_LIT>""" <EOL> s = self . __class__ . __new__ ( self . __class__ ) <EOL> s . __dict__ = self . __dict__ . copy ( ) <EOL> s . _reset_exported ( ) <EOL> return s <EOL> @ property <EOL> def _from_objects ( self ) : <EOL> return [ self ] <EOL> class GenerativeSelect ( SelectBase ) : <EOL> """<STR_LIT>""" <EOL> _order_by_clause = ClauseList ( ) <EOL> _group_by_clause = ClauseList ( ) <EOL> _limit = None <EOL> _offset = None <EOL> _for_update_arg = None <EOL> def __init__ ( self , <EOL> use_labels = False , <EOL> for_update = False , <EOL> limit = None , <EOL> offset = None , <EOL> order_by = None , <EOL> group_by = None , <EOL> bind = None , <EOL> autocommit = None ) : <EOL> self . use_labels = use_labels <EOL> if for_update is not False : <EOL> self . _for_update_arg = ( ForUpdateArg . <EOL> parse_legacy_select ( for_update ) ) <EOL> if autocommit is not None : <EOL> util . warn_deprecated ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . _execution_options = self . _execution_options . union ( <EOL> { '<STR_LIT>' : autocommit } ) <EOL> if limit is not None : <EOL> self . _limit = util . asint ( limit ) <EOL> if offset is not None : <EOL> self . _offset = util . asint ( offset ) <EOL> self . _bind = bind <EOL> if order_by is not None : <EOL> self . _order_by_clause = ClauseList ( * util . to_list ( order_by ) ) <EOL> if group_by is not None : <EOL> self . _group_by_clause = ClauseList ( * util . to_list ( group_by ) ) <EOL> @ property <EOL> def for_update ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _for_update_arg is not None : <EOL> return self . _for_update_arg . legacy_for_update_value <EOL> else : <EOL> return None <EOL> @ for_update . setter <EOL> def for_update ( self , value ) : <EOL> self . _for_update_arg = ForUpdateArg . parse_legacy_select ( value ) <EOL> @ _generative <EOL> def with_for_update ( self , nowait = False , read = False , of = None ) : <EOL> """<STR_LIT>""" <EOL> self . _for_update_arg = ForUpdateArg ( nowait = nowait , read = read , of = of ) <EOL> @ _generative <EOL> def apply_labels ( self ) : <EOL> """<STR_LIT>""" <EOL> self . use_labels = True <EOL> @ _generative <EOL> def limit ( self , limit ) : <EOL> """<STR_LIT>""" <EOL> self . _limit = util . asint ( limit ) <EOL> @ _generative <EOL> def offset ( self , offset ) : <EOL> """<STR_LIT>""" <EOL> self . _offset = util . asint ( offset ) <EOL> @ _generative <EOL> def order_by ( self , * clauses ) : <EOL> """<STR_LIT>""" <EOL> self . append_order_by ( * clauses ) <EOL> @ _generative <EOL> def group_by ( self , * clauses ) : <EOL> """<STR_LIT>""" <EOL> self . append_group_by ( * clauses ) <EOL> def append_order_by ( self , * clauses ) : <EOL> """<STR_LIT>""" <EOL> if len ( clauses ) == <NUM_LIT:1> and clauses [ <NUM_LIT:0> ] is None : <EOL> self . _order_by_clause = ClauseList ( ) <EOL> else : <EOL> if getattr ( self , '<STR_LIT>' , None ) is not None : <EOL> clauses = list ( self . _order_by_clause ) + list ( clauses ) <EOL> self . _order_by_clause = ClauseList ( * clauses ) <EOL> def append_group_by ( self , * clauses ) : <EOL> """<STR_LIT>""" <EOL> if len ( clauses ) == <NUM_LIT:1> and clauses [ <NUM_LIT:0> ] is None : <EOL> self . _group_by_clause = ClauseList ( ) <EOL> else : <EOL> if getattr ( self , '<STR_LIT>' , None ) is not None : <EOL> clauses = list ( self . _group_by_clause ) + list ( clauses ) <EOL> self . _group_by_clause = ClauseList ( * clauses ) <EOL> class CompoundSelect ( GenerativeSelect ) : <EOL> """<STR_LIT>""" <EOL> __visit_name__ = '<STR_LIT>' <EOL> UNION = util . symbol ( '<STR_LIT>' ) <EOL> UNION_ALL = util . symbol ( '<STR_LIT>' ) <EOL> EXCEPT = util . symbol ( '<STR_LIT>' ) <EOL> EXCEPT_ALL = util . symbol ( '<STR_LIT>' ) <EOL> INTERSECT = util . symbol ( '<STR_LIT>' ) <EOL> INTERSECT_ALL = util . symbol ( '<STR_LIT>' ) <EOL> _is_from_container = True <EOL> def __init__ ( self , keyword , * selects , ** kwargs ) : <EOL> self . _auto_correlate = kwargs . pop ( '<STR_LIT>' , False ) <EOL> self . keyword = keyword <EOL> self . selects = [ ] <EOL> numcols = None <EOL> for n , s in enumerate ( selects ) : <EOL> s = _clause_element_as_expr ( s ) <EOL> if not numcols : <EOL> numcols = len ( s . c . _all_columns ) <EOL> elif len ( s . c . _all_columns ) != numcols : <EOL> raise exc . ArgumentError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % <EOL> ( <NUM_LIT:1> , len ( self . selects [ <NUM_LIT:0> ] . c . _all_columns ) , <EOL> n + <NUM_LIT:1> , len ( s . c . _all_columns ) ) <EOL> ) <EOL> self . selects . append ( s . self_group ( self ) ) <EOL> GenerativeSelect . __init__ ( self , ** kwargs ) <EOL> @ classmethod <EOL> def _create_union ( cls , * selects , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return CompoundSelect ( CompoundSelect . UNION , * selects , ** kwargs ) <EOL> @ classmethod <EOL> def _create_union_all ( cls , * selects , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return CompoundSelect ( CompoundSelect . UNION_ALL , * selects , ** kwargs ) <EOL> @ classmethod <EOL> def _create_except ( cls , * selects , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return CompoundSelect ( CompoundSelect . EXCEPT , * selects , ** kwargs ) <EOL> @ classmethod <EOL> def _create_except_all ( cls , * selects , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return CompoundSelect ( CompoundSelect . EXCEPT_ALL , * selects , ** kwargs ) <EOL> @ classmethod <EOL> def _create_intersect ( cls , * selects , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return CompoundSelect ( CompoundSelect . INTERSECT , * selects , ** kwargs ) <EOL> @ classmethod <EOL> def _create_intersect_all ( cls , * selects , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return CompoundSelect ( <EOL> CompoundSelect . INTERSECT_ALL , * selects , ** kwargs ) <EOL> def _scalar_type ( self ) : <EOL> return self . selects [ <NUM_LIT:0> ] . _scalar_type ( ) <EOL> def self_group ( self , against = None ) : <EOL> return FromGrouping ( self ) <EOL> def is_derived_from ( self , fromclause ) : <EOL> for s in self . selects : <EOL> if s . is_derived_from ( fromclause ) : <EOL> return True <EOL> return False <EOL> def _populate_column_collection ( self ) : <EOL> for cols in zip ( * [ s . c . _all_columns for s in self . selects ] ) : <EOL> proxy = cols [ <NUM_LIT:0> ] . _make_proxy ( <EOL> self , name = cols [ <NUM_LIT:0> ] . _label if self . use_labels else None , <EOL> key = cols [ <NUM_LIT:0> ] . _key_label if self . use_labels else None ) <EOL> proxy . _proxies = [ <EOL> c . _annotate ( { '<STR_LIT>' : i + <NUM_LIT:1> } ) for ( i , c ) in enumerate ( cols ) ] <EOL> def _refresh_for_new_column ( self , column ) : <EOL> for s in self . selects : <EOL> s . _refresh_for_new_column ( column ) <EOL> if not self . _cols_populated : <EOL> return None <EOL> raise NotImplementedError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def _copy_internals ( self , clone = _clone , ** kw ) : <EOL> self . _reset_exported ( ) <EOL> self . selects = [ clone ( s , ** kw ) for s in self . selects ] <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> del self . _col_map <EOL> for attr in ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if getattr ( self , attr ) is not None : <EOL> setattr ( self , attr , clone ( getattr ( self , attr ) , ** kw ) ) <EOL> def get_children ( self , column_collections = True , ** kwargs ) : <EOL> return ( column_collections and list ( self . c ) or [ ] ) + [ self . _order_by_clause , self . _group_by_clause ] + list ( self . selects ) <EOL> def bind ( self ) : <EOL> if self . _bind : <EOL> return self . _bind <EOL> for s in self . selects : <EOL> e = s . bind <EOL> if e : <EOL> return e <EOL> else : <EOL> return None <EOL> def _set_bind ( self , bind ) : <EOL> self . _bind = bind <EOL> bind = property ( bind , _set_bind ) <EOL> class HasPrefixes ( object ) : <EOL> _prefixes = ( ) <EOL> @ _generative <EOL> def prefix_with ( self , * expr , ** kw ) : <EOL> """<STR_LIT>""" <EOL> dialect = kw . pop ( '<STR_LIT>' , None ) <EOL> if kw : <EOL> raise exc . ArgumentError ( "<STR_LIT>" % <EOL> "<STR_LIT:U+002C>" . join ( kw ) ) <EOL> self . _setup_prefixes ( expr , dialect ) <EOL> def _setup_prefixes ( self , prefixes , dialect = None ) : <EOL> self . _prefixes = self . _prefixes + tuple ( <EOL> [ ( _literal_as_text ( p ) , dialect ) for p in prefixes ] ) <EOL> class Select ( HasPrefixes , GenerativeSelect ) : <EOL> """<STR_LIT>""" <EOL> __visit_name__ = '<STR_LIT>' <EOL> _prefixes = ( ) <EOL> _hints = util . immutabledict ( ) <EOL> _distinct = False <EOL> _from_cloned = None <EOL> _correlate = ( ) <EOL> _correlate_except = None <EOL> _memoized_property = SelectBase . _memoized_property <EOL> _is_select = True <EOL> def __init__ ( self , <EOL> columns = None , <EOL> whereclause = None , <EOL> from_obj = None , <EOL> distinct = False , <EOL> having = None , <EOL> correlate = True , <EOL> prefixes = None , <EOL> ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . _auto_correlate = correlate <EOL> if distinct is not False : <EOL> if distinct is True : <EOL> self . _distinct = True <EOL> else : <EOL> self . _distinct = [ <EOL> _literal_as_text ( e ) <EOL> for e in util . to_list ( distinct ) <EOL> ] <EOL> if from_obj is not None : <EOL> self . _from_obj = util . OrderedSet ( <EOL> _interpret_as_from ( f ) <EOL> for f in util . to_list ( from_obj ) ) <EOL> else : <EOL> self . _from_obj = util . OrderedSet ( ) <EOL> try : <EOL> cols_present = bool ( columns ) <EOL> except TypeError : <EOL> raise exc . ArgumentError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if cols_present : <EOL> self . _raw_columns = [ ] <EOL> for c in columns : <EOL> c = _interpret_as_column_or_from ( c ) <EOL> if isinstance ( c , ScalarSelect ) : <EOL> c = c . self_group ( against = operators . comma_op ) <EOL> self . _raw_columns . append ( c ) <EOL> else : <EOL> self . _raw_columns = [ ] <EOL> if whereclause is not None : <EOL> self . _whereclause = _literal_as_text ( <EOL> whereclause ) . self_group ( against = operators . _asbool ) <EOL> else : <EOL> self . _whereclause = None <EOL> if having is not None : <EOL> self . _having = _literal_as_text ( <EOL> having ) . self_group ( against = operators . _asbool ) <EOL> else : <EOL> self . _having = None <EOL> if prefixes : <EOL> self . _setup_prefixes ( prefixes ) <EOL> GenerativeSelect . __init__ ( self , ** kwargs ) <EOL> @ property <EOL> def _froms ( self ) : <EOL> froms = [ ] <EOL> seen = set ( ) <EOL> translate = self . _from_cloned <EOL> def add ( items ) : <EOL> for item in items : <EOL> if item is self : <EOL> raise exc . InvalidRequestError ( <EOL> "<STR_LIT>" ) <EOL> if translate and item in translate : <EOL> item = translate [ item ] <EOL> if not seen . intersection ( item . _cloned_set ) : <EOL> froms . append ( item ) <EOL> seen . update ( item . _cloned_set ) <EOL> add ( _from_objects ( * self . _raw_columns ) ) <EOL> if self . _whereclause is not None : <EOL> add ( _from_objects ( self . _whereclause ) ) <EOL> add ( self . _from_obj ) <EOL> return froms <EOL> def _get_display_froms ( self , explicit_correlate_froms = None , <EOL> implicit_correlate_froms = None ) : <EOL> """<STR_LIT>""" <EOL> froms = self . _froms <EOL> toremove = set ( itertools . chain ( * [ <EOL> _expand_cloned ( f . _hide_froms ) <EOL> for f in froms ] ) ) <EOL> if toremove : <EOL> if self . _from_cloned : <EOL> toremove . update ( <EOL> self . _from_cloned [ f ] for f in <EOL> toremove . intersection ( self . _from_cloned ) <EOL> if self . _from_cloned [ f ] . _is_lexical_equivalent ( f ) <EOL> ) <EOL> froms = [ f for f in froms if f not in toremove ] <EOL> if self . _correlate : <EOL> to_correlate = self . _correlate <EOL> if to_correlate : <EOL> froms = [ <EOL> f for f in froms if f not in <EOL> _cloned_intersection ( <EOL> _cloned_intersection ( <EOL> froms , explicit_correlate_froms or ( ) ) , <EOL> to_correlate <EOL> ) <EOL> ] <EOL> if self . _correlate_except is not None : <EOL> froms = [ <EOL> f for f in froms if f not in <EOL> _cloned_difference ( <EOL> _cloned_intersection ( <EOL> froms , explicit_correlate_froms or ( ) ) , <EOL> self . _correlate_except <EOL> ) <EOL> ] <EOL> if self . _auto_correlate and implicit_correlate_froms and len ( froms ) > <NUM_LIT:1> : <EOL> froms = [ <EOL> f for f in froms if f not in <EOL> _cloned_intersection ( froms , implicit_correlate_froms ) <EOL> ] <EOL> if not len ( froms ) : <EOL> raise exc . InvalidRequestError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % self ) <EOL> return froms <EOL> def _scalar_type ( self ) : <EOL> elem = self . _raw_columns [ <NUM_LIT:0> ] <EOL> cols = list ( elem . _select_iterable ) <EOL> return cols [ <NUM_LIT:0> ] . type <EOL> @ property <EOL> def froms ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _get_display_froms ( ) <EOL> @ _generative <EOL> def with_hint ( self , selectable , text , dialect_name = '<STR_LIT:*>' ) : <EOL> """<STR_LIT>""" <EOL> self . _hints = self . _hints . union ( <EOL> { ( selectable , dialect_name ) : text } ) <EOL> @ property <EOL> def type ( self ) : <EOL> raise exc . InvalidRequestError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> @ _memoized_property . method <EOL> def locate_all_froms ( self ) : <EOL> """<STR_LIT>""" <EOL> froms = self . _froms <EOL> return froms + list ( _from_objects ( * froms ) ) <EOL> @ property <EOL> def inner_columns ( self ) : <EOL> """<STR_LIT>""" <EOL> return _select_iterables ( self . _raw_columns ) <EOL> def is_derived_from ( self , fromclause ) : <EOL> if self in fromclause . _cloned_set : <EOL> return True <EOL> for f in self . locate_all_froms ( ) : <EOL> if f . is_derived_from ( fromclause ) : <EOL> return True <EOL> return False <EOL> def _copy_internals ( self , clone = _clone , ** kw ) : <EOL> self . _from_cloned = from_cloned = dict ( <EOL> ( f , clone ( f , ** kw ) ) for f in self . _from_obj . union ( self . _froms ) ) <EOL> self . _from_obj = util . OrderedSet ( from_cloned [ f ] for f in <EOL> self . _from_obj ) <EOL> self . _correlate = set ( clone ( f ) for f in <EOL> self . _correlate ) . union ( self . _correlate ) <EOL> self . _raw_columns = [ clone ( c , ** kw ) for c in self . _raw_columns ] <EOL> for attr in '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' : <EOL> if getattr ( self , attr ) is not None : <EOL> setattr ( self , attr , clone ( getattr ( self , attr ) , ** kw ) ) <EOL> self . _reset_exported ( ) <EOL> def get_children ( self , column_collections = True , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return ( column_collections and list ( self . columns ) or [ ] ) + self . _raw_columns + list ( self . _froms ) + [ x for x in <EOL> ( self . _whereclause , self . _having , <EOL> self . _order_by_clause , self . _group_by_clause ) <EOL> if x is not None ] <EOL> @ _generative <EOL> def column ( self , column ) : <EOL> """<STR_LIT>""" <EOL> self . append_column ( column ) <EOL> @ util . dependencies ( "<STR_LIT>" ) <EOL> def reduce_columns ( self , sqlutil , only_synonyms = True ) : <EOL> """<STR_LIT>""" <EOL> return self . with_only_columns ( <EOL> sqlutil . reduce_columns ( <EOL> self . inner_columns , <EOL> only_synonyms = only_synonyms , <EOL> * ( self . _whereclause , ) + tuple ( self . _from_obj ) <EOL> ) <EOL> ) <EOL> @ _generative <EOL> def with_only_columns ( self , columns ) : <EOL> """<STR_LIT>""" <EOL> self . _reset_exported ( ) <EOL> rc = [ ] <EOL> for c in columns : <EOL> c = _interpret_as_column_or_from ( c ) <EOL> if isinstance ( c , ScalarSelect ) : <EOL> c = c . self_group ( against = operators . comma_op ) <EOL> rc . append ( c ) <EOL> self . _raw_columns = rc <EOL> @ _generative <EOL> def where ( self , whereclause ) : <EOL> """<STR_LIT>""" <EOL> self . append_whereclause ( whereclause ) <EOL> @ _generative <EOL> def having ( self , having ) : <EOL> """<STR_LIT>""" <EOL> self . append_having ( having ) <EOL> @ _generative <EOL> def distinct ( self , * expr ) : <EOL> """<STR_LIT>""" <EOL> if expr : <EOL> expr = [ _literal_as_text ( e ) for e in expr ] <EOL> if isinstance ( self . _distinct , list ) : <EOL> self . _distinct = self . _distinct + expr <EOL> else : <EOL> self . _distinct = expr <EOL> else : <EOL> self . _distinct = True <EOL> @ _generative <EOL> def select_from ( self , fromclause ) : <EOL> """<STR_LIT>""" <EOL> self . append_from ( fromclause ) <EOL> @ _generative <EOL> def correlate ( self , * fromclauses ) : <EOL> """<STR_LIT>""" <EOL> self . _auto_correlate = False <EOL> if fromclauses and fromclauses [ <NUM_LIT:0> ] is None : <EOL> self . _correlate = ( ) <EOL> else : <EOL> self . _correlate = set ( self . _correlate ) . union ( <EOL> _interpret_as_from ( f ) for f in fromclauses ) <EOL> @ _generative <EOL> def correlate_except ( self , * fromclauses ) : <EOL> """<STR_LIT>""" <EOL> self . _auto_correlate = False <EOL> if fromclauses and fromclauses [ <NUM_LIT:0> ] is None : <EOL> self . _correlate_except = ( ) <EOL> else : <EOL> self . _correlate_except = set ( self . _correlate_except or ( ) ) . union ( <EOL> _interpret_as_from ( f ) for f in fromclauses ) <EOL> def append_correlation ( self , fromclause ) : <EOL> """<STR_LIT>""" <EOL> self . _auto_correlate = False <EOL> self . _correlate = set ( self . _correlate ) . union ( <EOL> _interpret_as_from ( f ) for f in fromclause ) <EOL> def append_column ( self , column ) : <EOL> """<STR_LIT>""" <EOL> self . _reset_exported ( ) <EOL> column = _interpret_as_column_or_from ( column ) <EOL> if isinstance ( column , ScalarSelect ) : <EOL> column = column . self_group ( against = operators . comma_op ) <EOL> self . _raw_columns = self . _raw_columns + [ column ] <EOL> def append_prefix ( self , clause ) : <EOL> """<STR_LIT>""" <EOL> clause = _literal_as_text ( clause ) <EOL> self . _prefixes = self . _prefixes + ( clause , ) <EOL> def append_whereclause ( self , whereclause ) : <EOL> """<STR_LIT>""" <EOL> self . _reset_exported ( ) <EOL> self . _whereclause = and_ ( <EOL> True_ . _ifnone ( self . _whereclause ) , whereclause ) <EOL> def append_having ( self , having ) : <EOL> """<STR_LIT>""" <EOL> self . _reset_exported ( ) <EOL> self . _having = and_ ( True_ . _ifnone ( self . _having ) , having ) <EOL> def append_from ( self , fromclause ) : <EOL> """<STR_LIT>""" <EOL> self . _reset_exported ( ) <EOL> fromclause = _interpret_as_from ( fromclause ) <EOL> self . _from_obj = self . _from_obj . union ( [ fromclause ] ) <EOL> @ _memoized_property <EOL> def _columns_plus_names ( self ) : <EOL> if self . use_labels : <EOL> names = set ( ) <EOL> def name_for_col ( c ) : <EOL> if c . _label is None : <EOL> return ( None , c ) <EOL> name = c . _label <EOL> if name in names : <EOL> name = c . anon_label <EOL> else : <EOL> names . add ( name ) <EOL> return name , c <EOL> return [ <EOL> name_for_col ( c ) <EOL> for c in util . unique_list ( <EOL> _select_iterables ( self . _raw_columns ) ) <EOL> ] <EOL> else : <EOL> return [ <EOL> ( None , c ) <EOL> for c in util . unique_list ( <EOL> _select_iterables ( self . _raw_columns ) ) <EOL> ] <EOL> def _populate_column_collection ( self ) : <EOL> for name , c in self . _columns_plus_names : <EOL> if not hasattr ( c , '<STR_LIT>' ) : <EOL> continue <EOL> if name is None : <EOL> key = None <EOL> elif self . use_labels : <EOL> key = c . _key_label <EOL> if key is not None and key in self . c : <EOL> key = c . anon_label <EOL> else : <EOL> key = None <EOL> c . _make_proxy ( self , key = key , <EOL> name = name , <EOL> name_is_truncatable = True ) <EOL> def _refresh_for_new_column ( self , column ) : <EOL> for fromclause in self . _froms : <EOL> col = fromclause . _refresh_for_new_column ( column ) <EOL> if col is not None : <EOL> if col in self . inner_columns and self . _cols_populated : <EOL> our_label = col . _key_label if self . use_labels else col . key <EOL> if our_label not in self . c : <EOL> return col . _make_proxy ( <EOL> self , <EOL> name = col . _label if self . use_labels else None , <EOL> key = col . _key_label if self . use_labels else None , <EOL> name_is_truncatable = True ) <EOL> return None <EOL> return None <EOL> def self_group ( self , against = None ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( against , CompoundSelect ) : <EOL> return self <EOL> return FromGrouping ( self ) <EOL> def union ( self , other , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return CompoundSelect . _create_union ( self , other , ** kwargs ) <EOL> def union_all ( self , other , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return CompoundSelect . _create_union_all ( self , other , ** kwargs ) <EOL> def except_ ( self , other , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return CompoundSelect . _create_except ( self , other , ** kwargs ) <EOL> def except_all ( self , other , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return CompoundSelect . _create_except_all ( self , other , ** kwargs ) <EOL> def intersect ( self , other , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return CompoundSelect . _create_intersect ( self , other , ** kwargs ) <EOL> def intersect_all ( self , other , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return CompoundSelect . _create_intersect_all ( self , other , ** kwargs ) <EOL> def bind ( self ) : <EOL> if self . _bind : <EOL> return self . _bind <EOL> froms = self . _froms <EOL> if not froms : <EOL> for c in self . _raw_columns : <EOL> e = c . bind <EOL> if e : <EOL> self . _bind = e <EOL> return e <EOL> else : <EOL> e = list ( froms ) [ <NUM_LIT:0> ] . bind <EOL> if e : <EOL> self . _bind = e <EOL> return e <EOL> return None <EOL> def _set_bind ( self , bind ) : <EOL> self . _bind = bind <EOL> bind = property ( bind , _set_bind ) <EOL> class ScalarSelect ( Generative , Grouping ) : <EOL> _from_objects = [ ] <EOL> _is_from_container = True <EOL> def __init__ ( self , element ) : <EOL> self . element = element <EOL> self . type = element . _scalar_type ( ) <EOL> @ property <EOL> def columns ( self ) : <EOL> raise exc . InvalidRequestError ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> c = columns <EOL> @ _generative <EOL> def where ( self , crit ) : <EOL> """<STR_LIT>""" <EOL> self . element = self . element . where ( crit ) <EOL> def self_group ( self , ** kwargs ) : <EOL> return self <EOL> class Exists ( UnaryExpression ) : <EOL> """<STR_LIT>""" <EOL> __visit_name__ = UnaryExpression . __visit_name__ <EOL> _from_objects = [ ] <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if args and isinstance ( args [ <NUM_LIT:0> ] , ( SelectBase , ScalarSelect ) ) : <EOL> s = args [ <NUM_LIT:0> ] <EOL> else : <EOL> if not args : <EOL> args = ( [ literal_column ( '<STR_LIT:*>' ) ] , ) <EOL> s = Select ( * args , ** kwargs ) . as_scalar ( ) . self_group ( ) <EOL> UnaryExpression . __init__ ( self , s , operator = operators . exists , <EOL> type_ = type_api . BOOLEANTYPE ) <EOL> def select ( self , whereclause = None , ** params ) : <EOL> return Select ( [ self ] , whereclause , ** params ) <EOL> def correlate ( self , * fromclause ) : <EOL> e = self . _clone ( ) <EOL> e . element = self . element . correlate ( * fromclause ) . self_group ( ) <EOL> return e <EOL> def correlate_except ( self , * fromclause ) : <EOL> e = self . _clone ( ) <EOL> e . element = self . element . correlate_except ( * fromclause ) . self_group ( ) <EOL> return e <EOL> def select_from ( self , clause ) : <EOL> """<STR_LIT>""" <EOL> e = self . _clone ( ) <EOL> e . element = self . element . select_from ( clause ) . self_group ( ) <EOL> return e <EOL> def where ( self , clause ) : <EOL> """<STR_LIT>""" <EOL> e = self . _clone ( ) <EOL> e . element = self . element . where ( clause ) . self_group ( ) <EOL> return e <EOL> class TextAsFrom ( SelectBase ) : <EOL> """<STR_LIT>""" <EOL> __visit_name__ = "<STR_LIT>" <EOL> _textual = True <EOL> def __init__ ( self , text , columns ) : <EOL> self . element = text <EOL> self . column_args = columns <EOL> @ property <EOL> def _bind ( self ) : <EOL> return self . element . _bind <EOL> @ _generative <EOL> def bindparams ( self , * binds , ** bind_as_values ) : <EOL> self . element = self . element . bindparams ( * binds , ** bind_as_values ) <EOL> def _populate_column_collection ( self ) : <EOL> for c in self . column_args : <EOL> c . _make_proxy ( self ) <EOL> def _copy_internals ( self , clone = _clone , ** kw ) : <EOL> self . _reset_exported ( ) <EOL> self . element = clone ( self . element , ** kw ) <EOL> def _scalar_type ( self ) : <EOL> return self . column_args [ <NUM_LIT:0> ] . type <EOL> class AnnotatedFromClause ( Annotated ) : <EOL> def __init__ ( self , element , values ) : <EOL> element . c <EOL> Annotated . __init__ ( self , element , values ) </s>
