U kfͻ @sdZddlmZddlmZddlZddlmZddlZddlm Z ddlm Z ddlm Z dd lm Z dd lm Z dd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddl m!Z!ddl m"Z"ddl m#Z#ddl$m%Z%dd l$m&Z&dd!l'm(Z(dd"l)m*Z*dd#l+m,Z,dd$l+m-Z-dd%l+m.Z.dd&l+m/Z/dd'l+m0Z0dd(l+m1Z1dd)l+m2Z2dd*l+m3Z3dd+l+m4Z4dd,l+m5Z5dd-l+m6Z6dd.l+m7Z7dd/l+m8Z8dd0l9m:Z:dd1l;mZ>dd4l;m?Z?dd5l;m@Z@dd6l;mAZAdd7l;mBZBdd8lmCZCd9d:lmDZDd9d;lmEZEd9dlmIZIdd?lmJZJdd@lmKZKddAl+mLZLddBl+mMZMddCl;mNZNddDl;mOZOddEl;mPZPddFlmQZQddGlmRZRddHlmSZSd9dIlTmUZUd9dJlTmVZVd9dKlTmWZWd9dLlTmXZXd9dMlYmZZZedNdOdPZ[ddQdQdRdSdTdUdVdWZ\dXdQdYdZd[d\Z]d]dQdYd^d_d`Z^d]dadbdYdcdddeZ_dfdOdgdhdidjZ`dkdkdkdkdkdldmdndndndndndodpdqdrZadsdsdtdudvZbdwdxZcdydzZdd{d|ZedQd}dtd~dZfddZgddZhddZidQdQdndddZjddZkddZlGdddZmddZnGdddemZoGdddepZqGdddemZrdNddNdddZsddRdRdRdRdddZtedddnddddZuedddnddddZudddnddddZudddZvGdddejwZxGdddeHZyGdddexZzddddddddZ{dddtddZ|ddddddddZ}dS)z;High level utilities which build upon other modules here. ) annotations)dequeN)chain) AbstractSet)Any)Callable)cast) Collection)Dict)Iterable)Iterator)List)Optional)overload)Sequence)Tuple) TYPE_CHECKING)TypeVar)Union) coercions) operators)roles)visitorsis_text_clause)_deep_annotate)_deep_deannotate)_shallow_annotate)_expand_cloned) _from_objects) HasCacheKey) sort_tables) _find_columns)_label_reference)_textual_label_reference) BindParameter) ClauseElement) ColumnClause) ColumnElement)Grouping)KeyedColumnElement)Label) NamedColumn)Null)UnaryExpression)Column)Alias) FromClause) FromGrouping)Join) ScalarSelect) SelectBase) TableClause)_ET)exc)util)Literal)Protocol)_EquivalentColumnMap)_LimitOffsetType)_TypeEngineArgument)BinaryExpression) TextClause)_JoinTargetElement)_SelectIterable) Selectable)_TraverseCallableType)ExternallyTraversible)ExternalTraversal)_AnyExecuteParams)_AnyMultiExecuteParams)_AnySingleExecuteParams)_CoreSingleExecuteParams)Row_CEColumnElement[Any])boundr2zOptional[FromClause]z(Optional[AbstractSet[ColumnClause[Any]]]zColumnElement[bool])aba_subsetconsider_as_foreign_keysreturncCstj||||dS)aCreate a join condition between two tables or selectables. e.g.:: join_condition(tablea, tableb) would produce an expression along the lines of:: tablea.c.id==tableb.c.tablea_id The join is determined based on the foreign key relationships between the two selectables. If there are multiple ways to join, or no way to join, an error is raised. :param a_subset: An optional expression that is a sub-component of ``a``. An attempt will be made to join to just this sub-component first before looking at the full ``a`` construct, and if found will be successful even if there are other ways to join to ``a``. This allows the "right side" of a join to be passed thereby providing a "natural join". )rSrT)r4Z_join_condition)rQrRrSrTrVC/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/sql/util.pyjoin_condition_s rXzList[FromClause]z List[int])clausesjoin_torUcCsDtt|}g}t|D]&\}}|D]}||r$||q$q|S)aGiven a list of FROM clauses and a selectable, return the first index and element from the list of clauses which can be joined against the selectable. returns None, None if no match is found. e.g.:: clause1 = table1.join(table2) clause2 = table4.join(table5) join_to = table2.join(table3) find_join_source([clause1, clause2], join_to) == clause1 )listr enumerateis_derived_fromappend)rYrZ selectablesidxifsrVrVrWfind_join_sources  rdzSequence[FromClause])rY join_fromrUc Cstt|}g}t|D]*\}}|D]}||r$||qq$qt|dkrg}|D]:}||}|D](}tt|t|rh||qXqhqX|r|S|S)zGiven a list of FROM clauses and a selectable, return the indexes from the list of clauses which is derived from the selectable. r) r[r r\r]r^lensetsurface_selectables intersection) rYrer_Z liberal_idxrarbrcZconservative_idxr`rVrVrW#find_left_clause_that_matches_givens(      rjrCOptional[ColumnElement[Any]])rYrZonclauserUc sg}tt|}tdkr2|dk r2d}t|}nd}d}tD]t\}}||gD]^} |r|dk sjtt|j| j |r| |qBqV|dk st || rV| |qBqVqBt|dkrtt ddDfdd|D}|s|dk rtttS|SdS)a Given a list of FROM clauses, a selectable, and optional ON clause, return a list of integer indexes from the clauses list indicating the clauses that can be joined from. The presence of an "onclause" indicates that at least one clause can definitely be joined from; if the list of clauses is of length one and the onclause is given, returns that index. If the list of clauses is more than length one, and the onclause is given, attempts to locate which clauses contain the same columns. rNTFcSsg|]}t|jqSrV)rZ _hide_froms).0rbrVrVrW sz1find_left_clause_to_join_from..csg|]}|kr|qSrVrV)rmrarYZtoremoverVrWrns )rgr rfr#r\ differenceAssertionErrorcunion issupersetr^r4Z _can_joinrr[range) rYrZrlr`r_Zresolve_ambiguityZcols_in_onclauserarbrcrVrorWfind_left_clause_to_join_froms2      rvzOCallable[[BinaryExpression[Any], ColumnElement[Any], ColumnElement[Any]], None]None)fnexprrUcs0gdddfdd t|ddS)aProduce a traversal of the given expression, delivering column comparisons to the given function. The function is of the form:: def my_fn(binary, left, right) For each binary expression located which has a comparison operator, the product of "left" and "right" will be delivered to that function, in terms of that binary. Hence an expression like:: and_( (a + b) == q + func.sum(e + f), j == r ) would have the traversal:: a q a e a f b q b e b f j r That is, every combination of "left" and "right" that doesn't further contain a binary comparison is passed as pairs. r'zIterator[ColumnElement[Any]])elementrUc3st|tr|Vn|jdkrt|jrd||jD]$}|jD]}d||qLq> d| D] }|qvn,t|t r|V| D]}|EdHqdS)Nbinaryr) isinstancer5Z__visit_name__rZ is_comparisonoperatorinsertleftrightpop get_childrenr()rzlrelemrxstackvisitrVrWr.s        z#visit_binary_product..visitN)r[)rxryrVrrWvisit_binary_products( rF) check_columnsinclude_aliases include_joinsinclude_selects include_crudr'boolzList[TableClause])clauserrrrrrUcsgi}|rj|d<|d<|r,j|d<|rRj|d<|d<|d<|d<|rvfdd |d <|d <|d <|rfd d}||d<j|d<t|i|S)z1locate Table objects within the given expression.selectZcompound_selectjoinaliasZsubqueryZ tablesampleZlateralcs |jSNr^table)ZentZtablesrVrWbzfind_tables..r~updatedeletecs|jdSrr)columnrrVrW visit_columngsz!find_tables..visit_columnrr)r^rtraverse)rrrrrrZ _visitorsrrVrrW find_tablesGs*     rr)rrUcCst}g}t|g}|r|}t|trt|trBt|j st|t r|t|j t s||j }t|t rn|j }||qnt|tr|j }||qt|trq||kr||||q|D]}||qq|S)zqBreak up an 'order by' expression into individual column-expressions, without DESC/ASC/NULLS FIRST/NULLS LAST)r; column_setrpopleftr|r)r/rZis_ordering_modifiermodifierr,rzr5r*r^r$r%addr)rcolsresultrtrrrVrVrWunwrap_order_byrs>            rcCs dddddd}t|i|S)NrGrOptional[ExternallyTraversible])rzkwrUc[s*t|tr|jSt|tr&ds&tddS)NFz&can't unwrap a textual label reference)r|r$rzr%rq)rzrrVrVrWreplaces    z'unwrap_label_reference..replace)rZreplacement_traverse)rzrrVrVrWunwrap_label_references rcs6dd|Dttdd|D}fdd|DS)zGiven the columns clause and ORDER BY of a selectable, return a list of column expressions that can be added to the collist corresponding to the ORDER BY, without repeating those already in the collist. cSs h|]}|jdk r|jn|qSr)Z_order_by_label_elementrzrmcolrVrVrW sz3expand_column_list_from_order_by..cSsg|] }t|qSrV)r)rmorVrVrWrnsz4expand_column_list_from_order_by..csg|]}|kr|qSrVrVrZcols_already_presentrVrWrns)r[r)ZcollistZorder_byZ to_look_forrVrrW expand_column_list_from_order_bys rcCs t|D]}||krdSqdS)zGiven a target clause and a second to search within, return True if the target is plainly present in the search without any subqueries or aliases involved. Basically descends through Joins. TFN)rh)rsearchrrVrVrWclause_is_presents rzIterator[FromClause]ccsRt|tr,t|jEdHt|jEdHn"t|trHt|jEdHn|VdSr)r|r4tables_from_leftmostrrr3rz)rrVrVrWrs   rccsR|g}|rN|}|Vt|tr6||j|jfqt|tr||jqdSr) rr|r4extendrrr3r^rzrrrrVrVrWrhs  rhccs|g}|r|}t|ttfr&|Vt|trD||j|jfqt|tr\| |j qt|t r|j dk r~| |j q|Vq|dk r|VqdSr) rr|r7r1r4rrrr3r^rzr(rrrVrVrWsurface_selectables_onlys    rcCs\ttf}t|g}|rX|}||jkr2|j|S|D]}t||rJq:||q:qdSr)r3r6rr _annotationsrr|r^)rZannotation_namefilter_rrsubrVrVrWextract_first_column_annotations     r)rrrUcCsttt|t|S)z:Return True if left/right have some overlapping selectable)rrgrhri)rrrVrVrWselectables_overlapsrcs&gfdd}t|id|iS)zReturn an ordered list of "bound" values in the given clause. E.g.:: >>> expr = and_( ... table.c.foo==5, table.c.foo==7 ... ) >>> bind_values(expr) [5, 7] cs|jdSr)r^Zeffective_value)bindvrVrWvisit_bindparamsz$bind_values..visit_bindparamZ bindparam)rr)rrrVrrW bind_valuess  rcCs*t|tr|dd}d|St|SdS)N'z''z'%s')r|strrrepr)rzrVrVrW_quote_ddl_expr#s  rc@sNeZdZUdZded<dZded<dZded<dZded <d d d d dZdS) _repr_baserint_LISTr_TUPLEr9_DICT) max_charsrrr)valuerUcCsPt|}t|}||jkrL|jd}|d|d||j|| d}|S)Nr9rz# ... (%d characters truncated) ... )rrfr)selfrrepZlenrepsegment_lengthrVrVrWtrunc4s    z_repr_base.truncN) __name__ __module__ __qualname__r__annotations__rr __slots__rrVrVrVrWr+s    rcCst}d|_||S)N,)rrr)rrprVrVrW_repr_single_valueDsrc@s4eZdZdZdZddddddZd d d d Zd S) _repr_rowzProvide a string view of a row.)rowrzRow[Any]rrrcCs||_||_dSrr)rrrrVrVrW__init__Osz_repr_row.__init__rrUcs:|jddfdd|jDt|jdkr2dndfS)N(%s%s), c3s|]}|VqdSrrVrmrrrVrW Vsz%_repr_row.__repr__..r,)rrrrfrrVrrW__repr__Ss z_repr_row.__repr__N)r)rrr__doc__rrrrVrVrVrWrJsrc@seZdZddddZdS)_long_statementrrcCsXt|}|dkrJd}d}|||}|d|d|d|| dSt|SdS)Nidr ... z characters truncated ... )rfr__str__)rZlselflleftZlrightrrVrVrWr\s $z_long_statement.__str__N)rrrrrVrVrVrWr[src@seZdZdZdZd%dddddd d d Zd d ddZddd dddZdddddZddd dddZ dd dddZ d d dd!d"Z dd dd#d$Z dS)& _repr_paramszProvide a string view of bound parameters. Truncates display to a given number of 'multi' parameter sets, as well as long values to a given number of characters. )paramsbatchesismulti max_paramsrrNzOptional[_AnyExecuteParams]rzOptional[bool])rrrrrcCs"||_||_||_||_||_dSr)rrrrr)rrrrrrrVrVrWrts z_repr_params.__init__rrc Cs|jdkr||jSt|jtr*|j}n4t|jtr>|j}n t|jtrR|j }n ||jS|jrt d|j}t |j|j krd}d ||d|j d|dd||j t |jf||dd|ddfS|||Sn|t d |j|SdS) NrJz8 ... displaying %i of %i total bound parameter sets ...  r9rrrK)rrrr|r[rtuplerdictrrrfrr _repr_multir)rtyp multi_paramsmsgrVrVrWrsJ       z_repr_params.__repr__rJ)rrrUcs|rzt|dtrjnDt|dtr0jn.t|dtrFjnds^tdt|dd fdd|D}nd}|jkrd|Sd |SdS) NrFzUnknown parameter type %src3s|]}|VqdSr)r)rmrZ elem_typerrVrWrsz+_repr_params._repr_multi..r[%s]z(%s)) r|r[rrrrrrqtyper)rrrelementsrVrrWrs"   z_repr_params._repr_multiz Iterable[Any]r)rrUcCsTt|}t|}||jkrF|jd}|d||| d||jfS|ddfSdS)Nr9r)r[rfr)rrZlparamsZ lenparamsrrVrVrW _get_batchess    z_repr_params._get_batchesrK)rrrUcCsB||jkr|td|S||jkr4|td|S||SdS)NrL Sequence[Any])r_repr_param_dictrr_repr_param_tuple_repr_param_list)rrrrVrVrWrs  z_repr_params._repr_paramsrLcs|j||\}}}|rlddfdd|D}|d|d7}|ddfdd|D7}nd dfd d|D}|S) Nz{%src3s$|]\}}|d|VqdSz: NrVrmkeyrrrVrWrsz0_repr_params._repr_param_dict..r parameters truncated ... z%s}c3s$|]\}}|d|VqdSrrVrrrVrWrsz{%s}c3s$|]\}}|d|VqdSrrVrrrVrWrs)rritemsrrrZitems_first_batchZitems_second_batchZtrunclentextrVrrWrs0 z_repr_params._repr_param_dictrcs|j||\}}}|rjddfdd|D}|d|d7}|ddfdd|Df7}n0d dfd d|Dt|d krd nd f}|S)Nz(%src3s|]}|VqdSrrVrrrVrWrsz1_repr_params._repr_param_tuple..rrz%s)c3s|]}|VqdSrrVrrrVrWrsrc3s|]}|VqdSrrVrrrVrWrsrrr)rrrrfr rVrrWrs& z_repr_params._repr_param_tuplecs|j||\}}}|rhddfdd|D}|d|d7}|ddfdd|D7}nd dfd d|D}|S) Nz[%src3s|]}|VqdSrrVrrrVrWr'sz0_repr_params._repr_param_list..rrz%s]c3s|]}|VqdSrrVrrrVrWr+src3s|]}|VqdSrrVrrrVrWr/s)rrrr rVrrWrs$z_repr_params._repr_param_list)rrN) rrrrrrrrrrrrrrVrVrVrWrjs- rzCollection[Any])critnullsrUcsfdd}t|id|iS)zWgiven criterion containing bind params, convert selected elements to IS NULL. csnt|jtr:|jjkr:|j|_t|_tj|_tj |_ n0t|jtrj|jjkrjt|_tj|_tj |_ dSr) r|rr&Z_identifying_keyrr.ris_r}is_notnegater{r rVrW visit_binary:s     z-adapt_criterion_to_null..visit_binaryr{)rZcloned_traverse)r r rrVrrWadapt_criterion_to_null4s r)rrstop_onrUcCs|dkr |S|dfg}t|}d}|r|\}}t|trl||k rl|}||j|_||j|fn ||}|dk r|dk st ||_|dkr"|}q"|Sr) ClauseAdapterrr|r4Z_clonerrlr^rrq)rrrradapterretZ prevrightrVrVrW splice_joinsOs$    rzIterable[ColumnElement[Any]]zOptional[ClauseElement]zSequence[ColumnElement[Any]])columnsrYrrUcOsdSrrVrrYrrVrVrWreduce_columnslsrrDz/Sequence[Union[ColumnElement[Any], TextClause]]cOsdSrrVrrVrVrWrtsz1Collection[Union[ColumnElement[Any], TextClause]]c s4|dd}|ddt|}|dd|DtD]}tdd|jDD]}D]}||krpqbz |j}WnBtj k r|rYqbnYn"tj k r|rYqbnYnX| |rbr|j |j krb |qZqbqZqB|r*fdd } |D]"} | d k rt| id | iq|S) aCgiven a list of columns, return a 'reduced' set based on natural equivalents. the set is reduced to the smallest list of columns which have no natural equivalent present in the list. A "natural equivalent" means that two columns will ultimately represent the same value because they are related by a foreign key. \*clauses is an optional list of join clauses which will be traversed to further identify columns that are "equivalent". \**kw may specify 'ignore_nonexistent_tables' to ignore foreign keys whose tables are not yet configured, or columns that aren't yet present. This function is primarily used to determine the most minimal "primary key" from a selectable, by reducing the set of primary key columns present in the selectable to just those that are not repeated. ignore_nonexistent_tablesF only_synonymscss|]}t|r|VqdSrrrmrrrVrVrWrsz!reduce_columns..cSsg|] }|jqSrV)Z foreign_keysrrVrVrWrnsz"reduce_columns..cs||jtjkrxttddD}|j|krx|j|krxt D]0}| |jrFrh|j |jj krF |qxqFdS)NcSsg|] }|jqSrV) proxy_setrrVrVrWrnsz8reduce_columns..visit_binary..) r}reqr;rrrprrreversedshares_lineagenamer)r{rrrZ cset_no_textZomitrrVrWrs     z$reduce_columns..visit_binaryNr{)rr;Z OrderedSetrprrr rr:ZNoReferencedColumnErrorZNoReferencedTableErrorr#r$rrr) rrYrrrrZfkrrZfk_colrrrVr%rWr|sF          csHrrtdddfdd}gt|id|iS)z9traverse an expression and locate binary criterion pairs.zSCan only specify one of 'consider_as_foreign_keys' or 'consider_as_referenced_keys'cSs ||Sr)compare)rQrRrVrVrWcol_issz"criterion_as_pairs..col_iscs~s|jtjk rdSt|jtr,t|jts0dSr|jkrj|j|jsV|jkrj|j|jfn4|jkr|j|js|jkr|j|jfnڈr|jkr܈|j|js|jkr܈|j|jfn:|jkrz|j|js|jkrz|j|jfnbt|jtrzt|jtrz|j |jrX|j|jfn"|j |jrz|j|jfdSr) r}rr!r|rr)rr^r0Z referencesr any_operatorr'rTconsider_as_referenced_keyspairsrVrWrsR        z(criterion_as_pairs..visit_binaryr{)r: ArgumentErrorrr) expressionrTr*r)rrVr(rWcriterion_as_pairss'r.c @seZdZdZdZdddddddd d d d Zerhed ddddZedddddZdddddZe j fddZ e ddddddddZ dS)ra5Clones and modifies clauses based on column correspondence. E.g.:: table1 = Table('sometable', metadata, Column('col1', Integer), Column('col2', Integer) ) table2 = Table('someothertable', metadata, Column('col1', Integer), Column('col2', Integer) ) condition = table1.c.col1 == table2.c.col1 make an alias of table1:: s = table1.alias('foo') calling ``ClauseAdapter(s).traverse(condition)`` converts condition to read:: s.c.col1 == table2.c.col1 )__traverse_options__ selectable include_fn exclude_fn equivalentsadapt_on_namesadapt_from_selectablesNFrEOptional[_EquivalentColumnMap])Optional[Callable[[ClauseElement], bool]]r!Optional[AbstractSet[FromClause]])r0r3r1r2r4anonymize_labelsr5cCs@|g|d|_||_||_||_t|p*i|_||_||_dS)N)rr9) r/r0r1r2r;Z column_dictr3r4r5)rr0r3r1r2r4r9r5rVrVrWr4s zClauseAdapter.__init__ Literal[None]rwobjrUcCsdSrrVrr<rVrVrWrKszClauseAdapter.traverser8cCsdSrrVr=rVrVrWrVsrcCsdSrrVr=rVrVrWrYscCs|jj||d}|dkrb||jkrb||krb|j|D],}|j||||gd}|dk r4|Sq4|jr|dkrt|tr|jj |j }|S)Nrequire_embedded)r?_seen) r0corresponding_columnr3_corresponding_columnrsr4r|r-Zexported_columnsgetr$)rrr?r@newcolequivrVrVrWrB]s*  z#ClauseAdapter._corresponding_columnzsqlalchemy.sql.functionsz Optional[_ET])r_include_singleton_constantsrUcCsBtjj}|jr||sdS|jr0||r0dSt|trt||js|j |r||j rv|j D]}| |r^qvq^dS|jSt|t rt|j t r|SdSnt|tsdS|s|jrdSd|jkr|jd}trt|tst|j r||jkr|j D] }|j|ddk rqqdStr4t|ts4t|j|ddS)NZ adapt_columnFTr>)r;Z preloadedZ sql_functionsr1r2r|r2ZFunctionElementr0r]r5r1rzr7r)Z_is_singleton_constantrrr+rqr3rrrArB)rrrFZ functionsZadprVrVrWrusR            zClauseAdapter.replace)NNNFFN)F)rrrrrrrrrr; EMPTY_SETrBZpreload_modulerrVrVrVrWrs(   rc@sleZdZedddddZedddddZedddddZed d dd dZd d dd dZd S) _ColumnLookuprw)rrUcCsdSrrVrrrVrVrW __getitem__sz_ColumnLookup.__getitem__zColumnClause[Any]cCsdSrrVrIrVrVrWrJsrOcCsdSrrVrIrVrVrWrJsr8cCsdSrrVrIrVrVrWrJsrcCsdSrrVrIrVrVrWrJrN)rrrrrJrVrVrVrWrHsrHc seZdZUdZdZded<d,dd d d d d d d d d fdd ZGdddZddZe dddddZ e dddddZ dddddZ dddfdd Z e re d!d"d#d$Ze ZejZd%d&d'd(d)Zd%d&d'd*d+ZZS)- ColumnAdapteraExtends ClauseAdapter with extra utility functions. Key aspects of ColumnAdapter include: * Expressions that are adapted are stored in a persistent .columns collection; so that an expression E adapted into an expression E1, will return the same object E1 when adapted a second time. This is important in particular for things like Label objects that are anonymized, so that the ColumnAdapter can be used to present a consistent "adapted" view of things. * Exclusion of items from the persistent collection based on include/exclude rules, but also independent of hash identity. This because "annotated" items all have the same hash identity as their parent. * "wrapping" capability is added, so that the replacement of an expression E can proceed through a series of adapters. This differs from the visitor's "chaining" feature in that the resulting object is passed through all replacing functions unconditionally, rather than stopping at the first one that returns non-None. * An adapt_required option, used by eager loading to indicate that We don't trust a result row column that is not translated. This is to prevent a column from being interpreted as that of the child row in a self-referential scenario, see inheritance/test_basic.py->EagerTargetingTest.test_adapt_stringency )radapt_requiredallow_label_resolve_wrap __weakref__rHrNFTrEr6rr7r8) r0r3rLr1r2r4rMr9r5c sZtj||||||| dt|j|_|js4|jrD|||j|_||_ ||_ d|_ dS)N)r1r2r4r9r5) superrr;WeakPopulateDict _locate_colrr1r2_IncludeExcludeMappingrLrMrN) rr0r3rLr1r2r4rMr9r5 __class__rVrWrs   zColumnAdapter.__init__c@seZdZddZddZdS)z$ColumnAdapter._IncludeExcludeMappingcCs||_||_dSr)parentr)rrVrrVrVrWrsz-ColumnAdapter._IncludeExcludeMapping.__init__cCsL|jjr|j|r(|jjrB|j|rB|jjr>|jjj|S|S|j|Sr)rVr1r2rNrrIrVrVrWrJs  z0ColumnAdapter._IncludeExcludeMapping.__getitem__N)rrrrrJrVrVrVrWrSsrScCs>t|}||_t|j|_|js*|jr:|||j|_|Sr) copyrNr;rQrRrr1r2rS)rracrVrVrWwrap$s   zColumnAdapter.wrapr:rwr;cCsdSrrVr=rVrVrWr-szColumnAdapter.traverser8cCsdSrrVr=rVrVrWr0srcCs |j|Sr)rr=rVrVrWr3srH)visitorrUcst|tstt|Sr)r|rKrqrPr)rrZrTrVrWr8szColumnAdapter.chainzIterator[ColumnAdapter]rcCsdSrrVrrVrVrWvisitor_iterator?szColumnAdapter.visitor_iteratorrOrk)rrUcCs*|j|}||kr&||ddkr&dS|S)NT)rrB)rrrDrVrVrWadapt_check_presentEs z!ColumnAdapter.adapt_check_presentcCs|jr2|jD]}|j|dd}|dk r q>q |}n t||}|jr\|j|}|dk r\|}|jrn||krndS||k r~|j|_ |S)NT)rF) _is_immutabler[rrrrNrRrLrMZ_allow_label_resolve)rrZvisrrc2rVrVrWrROs     zColumnAdapter._locate_col)NFNNFTFN)rrrrrrrrSrYrrrrpropertyr[Z adapt_clauserZcopy_and_processZ adapt_listr\rR __classcell__rVrVrTrWrKs6 $  rKr?z Optional[str]z"Optional[_TypeEngineArgument[int]]zColumnElement[int])rzr$type_rUcCstjtj|||dS)zConvert the given value to an "offset or limit" clause. This handles incoming integers and converts to an expression; if an expression is already given, it is passed through. )r$ra)rexpectrZLimitOffsetRole)rzr$rarVrVrW_offset_or_limit_clause|s rccCs.|dkr dSt|dr&|j}t|S|SdS)zdReturn the offset or limit clause as a simple integer if possible, else return the clause. N_limit_offset_value)hasattrrdr;Zasint)rrrVrVrW)_offset_or_limit_clause_asint_if_possibles   rfrzATuple[Optional[ColumnElement[int]], Optional[ColumnElement[int]]]) limit_clause offset_clausestartstoprUcCs|dk rd|dk rdt|}|dkr$d}|dkr4||}|dkrBd}n|dk sNtt|}t||}nd|dkr~|dk r~t|}nJ|dk r|dkrt|}|dkrd}|dkr||}|dkrd}nt|}||fS)z0Compute LIMIT/OFFSET in terms of slice start/endNr)rfrqrc)rgrhrirjrVrVrW _make_slices6  rk)NN)N)NNF)NN)~r __future__r collectionsrrW itertoolsrtypingrrrrr r r r r rrrrrrrrrrrrZ_typingr annotationrrrbaserr cache_keyr!Zddlr"rr#r$r%r&r'r(r)r*r+r,r-r.r/Zschemar0r0r1r2r3r4r5r6r7r8r:r;Z util.typingr<r=r>r?r@rArBrCrDrErFrGrHZengine.interfacesrIrJrKrLZ engine.rowrMrNrXrdrjrvrrrrrrrrhrrrrrrrrrrrrrrr.ZReplacingExternalTraversalrrHrKrcrfrkrVrVrVrW s                                                                          $,9F+/   KV ?10