Files
Home-AssistantConfig/deps/sqlalchemy/sql/__pycache__/util.cpython-34.pyc

193 lines
18 KiB
Plaintext
Raw Normal View History

2016-10-11 16:42:06 +00:00
<EFBFBD>
|<7C><>W<EFBFBD>P<00>@s:dZddlmZmZddlmZmZddlmZmZddl m
Z
ddl m Z dd l mZmZmZmZmZmZmZmZmZdd
lmZmZmZmZdd lmZejjej d <00>Z!dd l"m#Z#m$Z$m%Z%ddl m&Z&ddl'm(Z(dd<00>Z)dd<00>Z*ddddddd<00>Z+dd<00>Z,dd<00>Z-dd<00>Z.dd<00>Z/dd <00>Z0d!d"<00>Z1d#d$<00>Z2Gd%d&<00>d&e3<00>Z4d'd(<00>Z5d)d*d+<00>Z6d,d-<00>Z7d)d)dd.d/<00>Z8Gd0d1<00>d1ej9<00>Z:Gd2d3<00>d3e:<00>Z;d)S)4z;High level utilities which build upon other modules here.
<EFBFBD>)<02>exc<78>util<69>)<02> _from_objects<74> ColumnSet)<02> operators<72>visitors<72>)<01>chain)<01>deque) <09> BindParameter<65> ColumnClause<73> ColumnElement<6E>Null<6C>UnaryExpression<6F>literal_column<6D>Label<65>_label_reference<63>_textual_label_reference)<04> ScalarSelect<63>Join<69>
FromClause<EFBFBD> FromGrouping)<01>Columnz.sql.util.join_condition)<03>_shallow_annotate<74>_deep_annotate<74>_deep_deannotate)<01> _find_columns)<01> sort_tablescCsatt|<00><00>}xHt|<00>D]6\}}x'|D]}|j|<00>r2||fSq2WqWdSdS)a<>Given 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
N)NN)<04>listr<00> enumerate<74>is_derived_from)<06>clausesZjoin_toZ selectables<65>i<>f<>s<>r&<00>9/tmp/pip-build-zkr322cu/sqlalchemy/sqlalchemy/sql/util.py<70>find_join_source"s  r(cs2g<00><00><00><00>fdd<00><00>t<00>|<00><00>dS)a<>Produce 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 <eq> q
a <eq> e
a <eq> f
b <eq> q
b <eq> e
b <eq> f
j <eq> r
That is, every combination of "left" and
"right" that doesn't further contain
a binary comparison is passed as pairs.
c3st|t<00>r|Vn<>|jdkr<>tj|j<00>r<><00>jd|<00>xE<00>|j<00>D]4}x+<00>|j<00>D]}<00><00>d||<00>qnWqXW<>j d<00>xk|j
<00>D]}<00>|<00>q<>WnJt|t <00>r<>|Vnx0|j
<00>D]"}x<00>|<00>D] }|Vq<>Wq<57>WdS)N<>binaryr ) <0C>
isinstancerZ__visit_name__rZ is_comparison<6F>operator<6F>insert<72>left<66>right<68>pop<6F> get_childrenr )<05>element<6E>l<>r<>elem<65>e)<03>fn<66>stack<63>visitr&r'r8as  z#visit_binary_product.<locals>.visitN)r)r6<00>exprr&)r6r7r8r'<00>visit_binary_product<s#r:Fcs<>g<00>i}|r*<00>j|d<|d<n|r@<00>j|d<n|rV<00>j|d<n|r<><00>fdd<00>|d<|d<|d <n|r<><00>fd
d <00>}||d <n<00>j|d <tj|idd6|<00><01>S)z1locate Table objects within the given expression.<2E>selectZcompound_select<63>join<69>aliascs<00>j|j<00>S)N)<02>append<6E>table)<01>ent)<01>tablesr&r'<00><lambda><3E>szfind_tables.<locals>.<lambda>r,<00>update<74>deletecs<00>j|j<00>dS)N)r>r?)<01>column)rAr&r'<00> visit_column<6D>sz!find_tables.<locals>.visit_columnrEr?FZcolumn_collections)r>r<00>traverse)<08>clauseZ check_columnsZinclude_aliasesZ include_joinsZinclude_selectsZ include_crudZ _visitorsrFr&)rAr'<00> find_tablesxs )  rIcCs<>tj<00>}t|g<00>}x<>|r<>|j<00>}t|t<00>r<>t|t<00> sbtj|j <00> r<>t|t
<00>r}|j }nt|t <00>r<>qn|j |<00>qx!|j<00>D]}|j|<00>q<>WqW|S)zqBreak up an 'order by' expression into individual column-expressions,
without DESC/ASC/NULLS FIRST/NULLS LAST)r<00>
column_setr <00>popleftr*rrrZis_ordering_modifier<65>modifierrr1r<00>addr0r>)rH<00>colsr7<00>t<>cr&r&r'<00>unwrap_order_by<62>s    rQcCsdd<00>}tj|i|<00>S)NcSs t|ttf<00>r|jSdS)N)r*rrr1)r4r&r&r'<00>replace<63>sz'unwrap_label_reference.<locals>.replace)rZreplacement_traverse)r1rRr&r&r'<00>unwrap_label_reference<63>s rScCs/x(t|<00>D]}||kr dSq WdSdS)z<>Given 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)<01>surface_selectables)rH<00>searchr4r&r&r'<00>clause_is_present<6E>s  rVccsx|g}xh|rs|j<00>}|Vt|t<00>rN|j|j|jf<00>q t|t<00>r |j|j<00>q q WdS)N) r/r*r<00>extendr-r.rr>r1)rHr7r4r&r&r'rT<00>s   rTcCs%ttt|<00><00>jt|<00><00><00>S)z:Return True if left/right have some overlapping selectable)<04>bool<6F>setrT<00> intersection)r-r.r&r&r'<00>selectables_overlap<61>sr[cs6g<00><00>fdd<00>}tj|ii|d6<><01>S)z<>Return 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<00>j|j<00>dS)N)r>Zeffective_value)<01>bind)<01>vr&r'<00>visit_bindparam<61>sz$bind_values.<locals>.visit_bindparamZ bindparam)rrG)rHr^r&)r]r'<00> bind_values<65>s r_cCs:t|tj<00>r,|jdd<00>}d|St|<00>SdS)N<>'z''z'%s')r*r<00> string_typesrR<00>repr)r1r&r&r'<00>_quote_ddl_expr<70>srcc@s.eZdZdZdd<00>Zdd<00>ZdS)<07> _repr_paramsznA string view of bound parameters, truncating
display to the given number of 'multi' parameter sets.
cCs||_||_dS)N)<02>params<6D>batches)<03>selfrerfr&r&r'<00>__init__s z_repr_params.__init__cCs<>t|jttf<00>r<>t|j<00>|jkr<>t|jdtttf<00>r<>d}djt|jd|jd<18><19>dd<00>||jt|j<00>ft|jdd<00><19>dd<00>f<00>St|j<00>SdS)Nr z8 ... displaying %i of %i total bound parameter sets ... <20> rr<00><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) r*rer<00>tuple<6C>lenrf<00>dictr<rb)rg<00>msgr&r&r'<00>__repr__s''z_repr_params.__repr__N)<06>__name__<5F>
__module__<EFBFBD> __qualname__<5F>__doc__rhrpr&r&r&r'rd<00>s  rdcs,<00>fdd<00>}tj|ii|d6<>S)zWgiven criterion containing bind params, convert selected elements
to IS NULL.
cs<>t|jt<00>rW|jj<00>krW|j|_t<00>|_tj|_tj |_
nKt|jt<00>r<>|jj<00>kr<>t<00>|_tj|_tj |_
ndS)N) r*r-r Z_identifying_keyr.rr<00>is_r+Zisnot<6F>negate)r))<01>nullsr&r'<00> visit_binarys     z-adapt_criterion_to_null.<locals>.visit_binaryr))rZcloned_traverse)<03>critrwrxr&)rwr'<00>adapt_criterion_to_nullsrzNcCs<>|dkr|S|dfg}t|<00>}d}x<>|r<>|j<00>\}}t|t<00>r<>||k r<>|j<00>}|j<00>|j|j<00>|_|j|j |f<00>n|j|<00>}|dk r<>||_ n|dkr4|}q4q4W|S)N)
<EFBFBD> ClauseAdapterr/r*rZ_cloneZ_reset_exportedrGZonclauser>r-)r-r.<00>stop_onr7<00>adapter<65>retZ prevrightr&r&r'<00> splice_joins+s$    
    rc
s<>|jdd<00>}|jdd<00><00>tj<00><00><00>tj<00><00>x<><00>D]<5D>}x<>tdd<00>|jD<><00>D]<5D>}x<><00>D]<5D>}||kr<>qvny |j}WnGtjk
r<>|r<>wvn<00>Yn$tj k
r<>|r<>wvn<00>YnX|j
|<00>rv<00> s |j |j krv<00>j |<00>PqvqvWqiWqFW|r<><01><00><00>fdd<00>}x:|D]/} | dk rOt j| ii|d 6<>qOqOWnt<00>j<00><00><00>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.
<20>ignore_nonexistent_tablesF<73> only_synonymscSsg|]}|j<00>qSr&)Z foreign_keys)<02>.0rPr&r&r'<00>
<listcomp>_s z"reduce_columns.<locals>.<listcomp>cs<>|jtjkr<>tjtdd<00><00>j<00><00>D<><00><00>}|j|kr<>|j|kr<>xVt <00><00>D]E}|j
|j<00>rh<00> s<>|j |jj krh<00>j |<00>PqhqhWq<57>ndS)NcSsg|]}|j<00>qSr&)<01> proxy_set)r<>rPr&r&r'r<>}s z8reduce_columns.<locals>.visit_binary.<locals>.<listcomp>) r+r<00>eqrrJr
<00>
differencer-r.<00>reversed<65>shares_lineage<67>namerM)r)rNrP)<03>columns<6E>omitr<74>r&r'rxzs% z$reduce_columns.<locals>.visit_binaryNr))r/rZordered_column_setrJr
r<>rErZNoReferencedColumnErrorZNoReferencedTableErrorr<72>r<>rMrrGrr<>)
r<EFBFBD>r"<00>kwr<77><00>colZfkrPZfk_colrxrHr&)r<>r<>r<>r'<00>reduce_columnsDs<  #      $r<>csl<00>r<00>rtjd<00><00>ndd<00><00><00><00><00><00><00>fdd<00>}g<00>tj|ii|d6<><01>S)z9traverse an expression and locate binary criterion pairs.zSCan only specify one of 'consider_as_foreign_keys' or 'consider_as_referenced_keys'cSs |j|<00>S)N)Zcompare)<02>a<>br&r&r'<00>col_is<69>sz"criterion_as_pairs.<locals>.col_iscs"<00> r|jtjk rdSt|jt<00> sCt|jt<00> rGdS<>r<>|j<00>kr<><00>|j|j<00>s<>|j<00>kr<><00>j|j|jf<00>q|j<00>kr<02>|j|j<00>s<>|j<00>kr<02>j|j|jf<00>qn0<01>r<>|j<00>krC<01>|j|j<00>s'|j<00>krC<01>j|j|jf<00>q|j<00>kr<02>|j|j<00>sv|j<00>kr<02>j|j|jf<00>qn<>t|jt<00>rt|jt<00>r|jj |j<00>r<><01>j|j|jf<00>q|jj |j<00>r<02>j|j|jf<00>qndS)N)
r+rr<>r*r-rr.r>rZ
references)r))<05> any_operatorr<72><00>consider_as_foreign_keys<79>consider_as_referenced_keys<79>pairsr&r'rx<00>s:z(criterion_as_pairs.<locals>.visit_binaryr))r<00> ArgumentErrorrrG)Z
expressionr<EFBFBD>r<>r<>rxr&)r<>r<>r<>r<>r<>r'<00>criterion_as_pairs<72>s   r<>c@sOeZdZdZddddddd<00>Zejdd<00>Zdd <00>ZdS)
r{a5Clones 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
NFcCsZi|gd6|d6|_||_||_||_tj|pDi<00>|_||_dS)Nr|<00>anonymize_labels)Z__traverse_options__<5F>
selectable<EFBFBD>
include_fn<EFBFBD>
exclude_fnrZ column_dict<63> equivalents<74>adapt_on_names)rgr<>r<>r<>r<>r<>r<>r&r&r'rh<00>s
    zClauseAdapter.__init__cCs<>|jj|d|<00>}|dkr<>||jkr<>||kr<>xO|j|D]=}|j|d|d|j|g<00><00>}|dk rM|SqMWn|jr<>|dkr<>|jjj|j<00>}n|S)N<>require_embedded<65>_seen) r<>Zcorresponding_columnr<6E><00>_corresponding_column<6D>unionr<6E>rP<00>getr<74>)rgr<>r<>r<>Znewcol<6F>equivr&r&r'r<><00>s  '   z#ClauseAdapter._corresponding_columncCs<>t|t<00>r(|jj|<00>r(|jSt|t<00>s;dS|jrX|j|<00> rXdS|jrt|j|<00>rtdS|j|d<00>SdS)NT)r*rr<>r!rr<>r<>r<>)rgr<>r&r&r'rR<00>szClauseAdapter.replace) rqrrrsrtrhr<00> EMPTY_SETr<54>rRr&r&r&r'r{<00>s  r{c
@s<>eZdZdZdddddddddd<00>ZGdd<00>de<00>Zd d
<00>Zd d <00>ZeZ e
j Z d d<00>Z dd<00>Zdd<00>ZdS)<13> ColumnAdaptera<72>Extends 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
NFTc
Cs<>tj|||d|d|d|d| <00>|rA|j|<00>ntj|j<00>|_|jsh|jr<>|j ||j<00>|_n||_
||_ d|_ dS)Nr<4E>r<>r<>r<>) r{rhr
r<00>populate_column_dict<63> _locate_colr<6C>r<>r<><00>_IncludeExcludeMapping<6E>adapt_required<65>allow_label_resolve<76>_wrap)
rgr<>r<>Zchain_tor<6F>r<>r<>r<>r<>r<>r&r&r'rh"s   zColumnAdapter.__init__c@s(eZdZdd<00>Zdd<00>ZdS)z$ColumnAdapter._IncludeExcludeMappingcCs||_||_dS)N)<02>parentr<74>)rgr<>r<>r&r&r'rh7s z-ColumnAdapter._IncludeExcludeMapping.__init__cCsl|jjr|jj|<00> s=|jjra|jj|<00>ra|jjrZ|jjj|S|Sn|j|S)N)r<>r<>r<>r<>r<>)rg<00>keyr&r&r'<00> __getitem__;s  z0ColumnAdapter._IncludeExcludeMapping.__getitem__N)rqrrrsrhr<>r&r&r&r'r<>6s  r<>cCsw|jj|j<00>}|jj|j<00>||_tj|j<00>|_|j sX|j
rs|j ||j<00>|_n|S)N) <0C> __class__<5F>__new__<5F>__dict__rCr<>rr<>r<>r<>r<>r<>r<>)rgr}<00>acr&r&r'<00>wrapGs zColumnAdapter.wrapcCs |j|S)N)r<>)rg<00>objr&r&r'rGQszColumnAdapter.traversecCsntj||<00>}|jrE|jj|<00>}|dk rE|}qEn|jr^||kr^dS|j|_|S)N)r{rGr<>r<>r<>r<>Z_allow_label_resolve)rgr<>rP<00>c2r&r&r'r<>Ws    zColumnAdapter._locate_colcCs|jj<00>}|d=|S)Nr<4E>)r<><00>copy)rg<00>dr&r&r'<00> __getstate__gszColumnAdapter.__getstate__cCs)|jj|<00>tj|j<00>|_dS)N)r<>rCrZ PopulateDictr<74>r<>)rg<00>stater&r&r'<00> __setstate__lszColumnAdapter.__setstate__)rqrrrsrtrh<00>objectr<74>r<>rGZ adapt_clauser{Zcopy_and_processZ
adapt_listr<EFBFBD>r<>r<>r&r&r&r'r<>s 
   r<>)<rt<00>rr<00>baserrrr<00> itertoolsr
<00> collectionsr <00>elementsr r rrrrrrrr<>rrrrZschemarZ langhelpersZpublic_factoryZ_join_conditionZjoin_conditionZ
annotationrrrrZddlrr(r:rIrQrSrVrTr[r_rcr<>rdrzrr<>r<>ZReplacingCloningVisitorr{r<>r&r&r&r'<00><module>
sD@"    < 

   H1E