ÿØÿàJFIFÿþ ÿÛC       ÿÛC ÿÀÿÄÿÄ"#QrÿÄÿÄ&1!A"2qQaáÿÚ ?Øy,æ/3JæÝ¹È߲؋5êXw²±ÉyˆR”¾I0ó2—PI¾IÌÚiMö¯–þrìN&"KgX:Šíµ•nTJnLK„…@!‰-ý ùúmë;ºgµŒ&ó±hw’¯Õ@”Ü— 9ñ-ë.²1<yà‚¹ïQÐU„ہ?.’¦èûbß±©Ö«Âw*VŒ) `$‰bØÔŸ’ëXÖ-ËTÜíGÚ3ð«g Ÿ§¯—Jx„–’U/ÂÅv_s(Hÿ@TñJÑãõçn­‚!ÈgfbÓc­:él[ðQe 9ÀPLbÃãCµm[5¿ç'ªjglå‡Ûí_§Úõl-;"PkÞÞÁQâ¼_Ñ^¢SŸx?"¸¦ùY騐ÒOÈ q’`~~ÚtËU¹CڒêV  I1Áß_ÿÙ 4]c@s,dZddlmZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd l m Z dd l mZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddlm%Z%dd lm&Z&e&j'j(e!j)d!Z*d"Z+d#Z,d$Z-d%Z.e/e/e/e/e/d&Z0d'Z1d(Z2d)Z3d*Z4d+Z5d,Z6e7d-Z8d.Z9d/Z:d0Z;d1e<fd2YZ=d3e=fd4YZ>d5e=fd6YZ?d7Z@d?d8ZBd9ZCd?d?e/d:ZDd;ejEfd<YZFd=eFfd>YZGd?S(@s;High level utilities which build upon other modules here. i(tdeque(tchaini(t operators(tvisitors(t_deep_annotate(t_deep_deannotate(t_shallow_annotate(t _from_objects(t ColumnSet(t sort_tables(t_expand_cloned(t _find_columns(t_label_reference(t_textual_label_reference(t BindParameter(t ColumnClause(t ColumnElement(tNull(tUnaryExpression(tColumn(tAlias(t FromClause(t FromGrouping(tJoin(t ScalarSelect(t SelectBase(t TableClausei(texc(tutils.sql.util.join_conditioncCsitt|}g}xJt|D]<\}}x-|D]%}|j|r8|j|q8q8Wq%W|S(sGiven 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 (tlistRt enumeratetis_derived_fromtappend(tclausestjoin_tot selectablestidxtitfts((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pytfind_join_source1s c Cstt|}g}xKt|D]=\}}x.|D]&}|j|r8|j|Pq8q8Wq%Wt|dkrg}x[|D]S}||}x@|D]8}tt|jt|r|j|PqqWqW|r|Sn|S(sGiven a list of FROM clauses and a selectable, return the indexes from the list of clauses which is derived from the selectable. i( RRRRR tlentsettsurface_selectablest intersection( R!t join_fromR#t liberal_idxR%R&R'tconservative_idxR$((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyt#find_left_clause_that_matches_givenKs&        c Csg}tt|}t|dkrK|dk rKt}t|}n t}d}xt|D]\}}x|j|gD]s} |rt|j j | j j |r|j |Pqqt j|| s|dk r|j |PqqWqdWt|dkrjttg|D]}t|j^q} g|D]}||| krE|^qE}n| r|dk rtt|S|SdS(s 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. iN(R*RR)tNonetTrueR tFalseRt differencetctuniont issupersetR Rt _can_joinRR t _hide_fromstrange( R!R"tonclauseR$R#tresolve_ambiguitytcols_in_onclauseR%R&R'ttoremove((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pytfind_left_clause_to_join_fromus. $   +,cs/gfdt|dS(sProduce 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. c3st|tr|Vn|jdkrtj|jrjd|xE|jD]4}x+|jD]}d||qnWqXWj dxk|j D]}|qWnJt|t r|Vnx0|j D]"}x|D] }|VqWqWdS(Ntbinaryi( t isinstanceRt__visit_name__Rt is_comparisontoperatortinserttlefttrighttpopt get_childrenR(telementtltrtelemte(tfntstacktvisit(sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyRQs   N(R(ROtexpr((RORPRQsF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pytvisit_binary_products#csgi}|r*j|d<|dtREtupdatetdeletecsj|jdS(N(R RX(tcolumn(RZ(sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyt visit_columnsR_RXtcolumn_collections(R RttraverseR3(tclauset check_columnstinclude_aliasest include_joinstinclude_selectst include_crudt _visitorsR`((RZsF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyt find_tabless &  cCstj}g}t|g}x|r|j}t|trt|t shtj|j  rt|t r|j }nt|t rq$n||kr|j ||j|qq$x!|jD]}|j|qWq$W|S(sqBreak up an 'order by' expression into individual column-expressions, without DESC/ASC/NULLS FIRST/NULLS LAST(Rt column_setRtpopleftRARRRtis_ordering_modifiertmodifierR RJR taddR RI(RctcolstresultRPttR5((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pytunwrap_order_bys$      cCsd}tj|i|S(NcSs t|ttfr|jSdS(N(RAR R RJ(RM((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pytreplace*s(Rtreplacement_traverse(RJRt((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pytunwrap_label_reference)s cCsytg|D]$}|jdk r(|jn|^q }gtg|D]}t|^qDD]}||kr]|^q]S(sGiven 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. N(R*t_order_by_label_elementR1RJRRs(tcollisttorder_bytcoltcols_already_presentto((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyt expand_column_list_from_order_by1s 1)cCs/x(t|D]}||kr tSq WtSdS(sGiven 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. N(R+R2R3(RctsearchRM((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pytclause_is_presentFs  ccsx|g}xh|rs|j}|Vt|trN|j|j|jfq t|tr |j|jq q WdS(N( RHRARtextendRFRGRR RJ(RcRPRM((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyR+Vs   ccs|g}x|r|j}t|ttfr;|Vnt|trf|j|j|jfq t|tr|j |j q t|t r |j |j q q WdS(N( RHRARRRRRFRGRR RJRRX(RcRPRM((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pytsurface_selectables_onlyas   ccstf}|s|tf7}nt|g}xT|r|j}|Vx6|jD](}t||rpqUn|j|qUWq1WdS(straverse and yield only outer-exposed column elements, such as would be addressable in the WHERE clause of a SELECT if this element were in the columns clause.N(RRRRlRIRAR (Rctinclude_scalar_selectstfilter_RPRMtsub((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pytsurface_column_elementsos   cCs%ttt|jt|S(s:Return True if left/right have some overlapping selectable(tboolR*R+R,(RFRG((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pytselectables_overlapscs3gfd}tj|ii|d6S(sReturn 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] csj|jdS(N(R teffective_value(tbind(tv(sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pytvisit_bindparamst bindparam(RRb(RcR((RsF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyt bind_valuess cCs:t|tjr,|jdd}d|St|SdS(Nt's''s'%s'(RARt string_typesRttrepr(RJ((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyt_quote_ddl_exprst _repr_basecBs)eZdZdZdZdZdZRS(iiit max_charscCs`t|}t|}||jkr\|jd}|d|!d||j|| }n|S(Niis# ... (%d characters truncated) ... (RR)R(tselftvaluetreptlenreptsegment_length((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyttruncs    ((R(t__name__t __module__t_LISTt_TUPLEt_DICTt __slots__R(((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyRs t _repr_rowcBs)eZdZdZddZdZRS(sProvide a string view of a row.trowi,cCs||_||_dS(N(RR(RRR((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyt__init__s csN|jddjfd|jDt|jdkrFdndfS(Ns(%s%s)s, c3s|]}|VqdS(N((t.0R(R(sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pys sit,R\(RRVRR)(R((RsF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyt__repr__s (R(RRt__doc__RRR(((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyRs t _repr_paramscBs;eZdZdZddZdZdZdZRS( sProvide a string view of bound parameters. Truncates display to a given numnber of 'multi' parameter sets, as well as long values to a given number of characters. tparamstbatchesi,cCs||_||_||_dS(N(RRR(RRRR((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyRs  cCsxt|jtrF|j}|jo@t|jdtttf}nzt|jtr|j}|jot|jdtttf}n4t|jtr|j}t}n|j |jS|rHt |j|j krHd}dj |j |j|j d |dd!||j t |jf|j |jd|dfS|ra|j |j|S|j|j|SdS(Nis8 ... displaying %i of %i total bound parameter sets ... t iiii(RARRRtdictttupleRRR3RR)RRVt _repr_multiR(Rttyptismultitmsg((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyRs,      !cs|rt|dtr%jn^t|dtrDjn?t|dtrcjn tstdt |ddj fd|D}nd}|jkrd|Sd|SdS(NisUnknown parameter type %ss, c3s!|]}j|VqdS(N(R(RR(t elem_typeR(sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pys sR\s[%s]s(%s)( RARRRRRRR3tAssertionErrorttypeRV(Rt multi_paramsRtelements((RRsF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyRs    cs|j||jkr?ddjfd|jDS||jkrddjfd|Dt|dkrdndfSd djfd |DSdS( Ns{%s}s, c3s+|]!\}}d||fVqdS(s%r: %sN((RtkeyR(R(sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pys ss(%s%s)c3s|]}|VqdS(N((RR(R(sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pys "siRR\s[%s]c3s|]}|VqdS(N((RR(R(sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pys &s(RRRVtitemsRR)(RRR((RsF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyRs   (RR(RRRRRRRR(((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyRs   ! cs)fd}tj|ii|d6S(sWgiven criterion containing bind params, convert selected elements to IS NULL. cst|jtrW|jjkrW|j|_t|_tj|_tj |_ nKt|jtr|jjkrt|_tj|_tj |_ ndS(N( RARFRt_identifying_keyRGRRtis_RDtisnottnegate(R@(tnulls(sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyt visit_binary/s     R@(Rtcloned_traverse(tcritRR((RsF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pytadapt_criterion_to_null)scCs|dkr|S|dfg}t|}d}x|r|j\}}t|tr||k r|j}|j|j|j|_|j |j |fn|j|}|dk r||_ n|dkr4|}q4q4W|S(N( R1t ClauseAdapterRHRARt_clonet_reset_exportedRbR;R RF(RFRGtstop_onRPtadaptertrett prevright((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyt splice_joinsDs$         c s|jdt}|jdttjtjxD]}xtg|jD]}|j^q\D]}xD]}||krqny |j}WnEt j k r|rqqn#t j k r|rqqnX|j |r s|j |j krj|PqqWqrWqFW|rfd}x:|D]/} | dk rStj| ii|d6qSqSWntjS(sCgiven 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. tignore_nonexistent_tablest only_synonymscs|jtjkrtjtgjD]}|j^q+}|j|kr|j |krxVt D]E}|j |j rq s|j |jj krqj |PqqqqWqndS(N(RDRteqRRkRR4t proxy_setRFRGtreversedtshares_lineagetnameRo(R@R5Rp(tcolumnstomitR(sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyRs. R@N(RHR3Rtordered_column_setRkRRt foreign_keysR_RtNoReferencedColumnErrortNoReferencedTableErrorRRRoR1RRbRR4( RR!tkwRRzR5tfktfk_colRRc((RRRsF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pytreduce_columns]s:  ,      $csfrrtjdndfd}gtj|ii|d6S(s9traverse an expression and locate binary criterion pairs.sSCan only specify one of 'consider_as_foreign_keys' or 'consider_as_referenced_keys'cSs |j|S(N(tcompare(tatb((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pytcol_isscs" r|jtjk rdSt|jt sCt|jt rGdSr|jkr|j|js|jkrj|j|jfq|jkr|j|js|jkrj|j|jfqn0r|jkrC|j|js'|jkrCj|j|jfq|jkr|j|jsv|jkrj|j|jfqnt|jtrt|jtr|jj |jrj|j|jfq|jj |jrj|j|jfqndS(N( RDRRRARFRRGR Rt references(R@(t any_operatorRtconsider_as_foreign_keystconsider_as_referenced_keystpairs(sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyRs:R@(Rt ArgumentErrorRRb(t expressionRRRR((RRRRRsF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pytcriterion_as_pairss   'RcBs>eZdZdddeedZejdZdZ RS(s5Clones 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 cCsZi|gd6|d6|_||_||_||_tj|pDi|_||_dS(NRtanonymize_labels(t__traverse_options__t selectablet include_fnt exclude_fnRt column_dictt equivalentstadapt_on_names(RRRRRRR((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyRs      cCs|jj|d|}|dkr||jkr||krxO|j|D]=}|j|d|d|j|g}|dk rM|SqMWn|jr|dkr|jjj|j }n|S(Ntrequire_embeddedt_seen( Rtcorresponding_columnR1Rt_corresponding_columnR6RR5tgetR(RRzRRtnewcoltequiv((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyRs '  cCst|tr(|jj|r(|jSt|ts;dS|jrX|j| rXdS|jrt|j|rtdS|j|t SdS(N( RARRRRR1RRRR2(RRz((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyRt(s N( RRRR1R3RRt EMPTY_SETRRt(((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyRs t ColumnAdaptercBs~eZdZd ed d eeedZdefdYZdZ dZ e Z e j ZdZdZdZRS( sExtends 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 c Cstj|||d|d|d|d|tj|j|_|jsR|jrm|j||j|_n||_ ||_ d|_ dS(NRRRR( RRRtpopulate_column_dictt _locate_colRRRt_IncludeExcludeMappingtadapt_requiredtallow_label_resolveR1t_wrap( RRRRRRRRR((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyRVs   RcBseZdZdZRS(cCs||_||_dS(N(tparentR(RRR((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyRss cCsl|jjr|jj| s=|jjra|jj|ra|jjrZ|jjj|S|Sn|j|S(N(RRRRR(RR((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyt __getitem__ws  (RRRR(((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyRrs cCsw|jj|j}|jj|j||_tj|j|_|j sX|j rs|j ||j|_n|S(N( t __class__t__new__t__dict__R]RRRRRRRR(RRtac((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pytwraps cCs |j|S(N(R(Rtobj((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyRbscCsntj||}|jrE|jj|}|dk rE|}qEn|jr^||kr^dS|j|_|S(N(RRbRRR1RRt_allow_label_resolve(RRzR5tc2((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyRs    cCs|jj}|d=|S(NR(Rtcopy(Rtd((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyt __getstate__scCs)|jj|tj|j|_dS(N(RR]Rt PopulateDictRR(Rtstate((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyt __setstate__sN(RRRR1R3R2RtobjectRRRbt adapt_clauseRtcopy_and_processt adapt_listRR R (((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyR7s      N(HRt collectionsRt itertoolsRR\RRt annotationRRRtbaseRRtddlR RR R R R RRRRRtschemaRRRRRRRRRRRt langhelperstpublic_factoryt_join_conditiontjoin_conditionR(R0R?RSR3RjRsRvR}RR+RR2RRRRR RRRRR1RRRtReplacingCloningVisitorRR(((sF/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/sql/util.pyt sz   * 4 @ "         Z   M ;P