idddlZddlZddlZddlmZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z dd lm Z dd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZedZ GddeZ!dZ" d;d Z#d!Z$Gd"d#ej%Z&Gd$d%e'Z(Gd&d'e Z)ej*e(d(ej*e)d)dd-Z-d.Z.d/Z/Gd0d1ej0Z1 d?d2Z2d@d3Z3d>d4Z4d5Z5d6Z6d7Z7d8Z8d9Z9d:Z:dS)AN) attributes)_class_to_mapper) _never_set) _none_set) attribute_str) class_mapper)InspectionAttr) instance_str) object_mapper) object_state)state_attribute_str)state_class_str) state_str)MapperProperty)PropComparator) PathRegistry)event)exc) inspection)sql)util) expression)delete delete-orphanallmergeexpunge save-updaterefresh-expirenonecreZdZdZegdZeZgdZdZ dZ dZ e dZ dS) CascadeOptionszHKeeps track of the options sent to :paramref:`.relationship.cascade`)rr"r)rrr"r!) save_updaterrefresh_expirerr delete_orphanc t|tjs|||St |}||jrYtjdd dt||jDzd|vr| |j d|vr| |dtt"|}d|v|_d|v|_d|v|_d |v|_d |v|_d |v|_|jr|jstjd |S) NzInvalid cascade option(s): %s, c,g|]}t|S)repr.0xs H/opt/cloudlinux/venv/lib/python3.11/site-packages/sqlalchemy/orm/util.py z*CascadeOptions.__new__..Ps.Qrr"r rr!rrrz5The 'delete-orphan' cascade option requires 'delete'.) isinstancer string_types from_stringset difference_allowed_cascadessa_exc ArgumentErrorjoinsortedupdate_add_w_all_cascadescleardiscard frozenset__new__r$r%rr&rrr'warn)cls value_listvaluesselfs r0rBzCascadeOptions.__new__Hs j$"3 4 4 / 8J??:.. .Z   S2 3 3 &/))!'"--c.CDD""    F?? MM#1 2 2 2 V   LLNNNu  88(F2&( .&8&  F* ,6   dk  IJ    r2c`dddt|DzS)NzCascadeOptions(%r),cg|]}|Sr+r+r-s r0r1z+CascadeOptions.__repr__..ns0I0I0Iq0I0I0Ir2)r;r<rGs r0__repr__zCascadeOptions.__repr__ms.#sxx0I0IF4LL0I0I0I'J'JKKr2cZdtjd|pdD}||S)Ncg|]}||Sr+r+)r.cs r0r1z.CascadeOptions.from_string..rsBBBB!BBBr2z\s*,\s*)resplit)rDargrFs r0r5zCascadeOptions.from_stringps3BBRXj#)<<BBBs6{{r2N)__name__ __module__ __qualname____doc__ all_cascadesr7r>r8_viewonly_cascades __slots__rBrL classmethodr5r+r2r0r$r$4s))'11(((%EEEI###JLLL[r2r$c` sfd |r! fd} fd} fd} fd}n fd} fd} fd}tj|d |d d tj|d |d tj|d|d d |rtj|d|d d dSdS)zNRuns a validation method on an attribute value to be set or appended. c:|jj}|j|uSN)managerimpl)state initiatorr`keys r0detect_is_backrefz,_validator_events..detect_is_backref}s=%*D>- -r2c|jtjur.s ||s ||dS|SNFoprOP_BULK_REPLACEobjravaluerbrdinclude_backrefsrc validators r0appendz!_validator_events..appendsU|:#=== >(9(9%(K(K>!yc5%@@@ r2c|s ||s+|fd|D|dd<dSdS)Nc,g|]}|dS)Fr+r.rlrcrjrns r0r1z7_validator_events..bulk_set..s6:?IIc3u55r2rjrarFrbrjrdrmrcrns @r0bulk_setz#_validator_events..bulk_setsv '8'8 'J'J iikkCIqqq   r2cds ||s ||dS|Srfrsrarloldvaluerbrdrmrcrns r0set_z_validator_events..set_sC '8'8 'J'J  yc5%@@@ r2chs ||s"||ddSdS)NTrsrks r0removez!_validator_events..removesN 9'8'8 'J'J 9 %))++sE488888 9 9r2c|jtjur-s ||s||S|Sr^rgrks r0roz!_validator_events..appendsS|:#=== >(9(9%(K(K>!yc5999 r2c|s ||s+|fd|D|dd<dSdS)Nc*g|]}|Sr+r+rrs r0r1z7_validator_events..bulk_set..s'LLLEYYsC77LLLr2rsrts @r0ruz#_validator_events..bulk_setsg M'8'8 'J'J MiikkLLLLLLVLLLqqq  M Mr2cbs ||s||S|Sr^rsrws r0ryz_validator_events..set_sA '8'8 'J'J  yc5999 r2roT)rawretval bulk_replace)rr6r{N)rlisten) descrcrninclude_removesrmroruryr{rds `` ` @r0_validator_eventsrvs . . . . . ..                          9 9 9 9 9 9 9 9 9          M M M M M M M M           LxT$???? L~xT:::: LudT::::D T8VdCCCCCCDDr2p_unionTc " tj}i i |D]}|| t tjr  ||<i} jD]5}||j|||j<|j |j<6| < fd g}| D]\} |s| tj fd|Dtj tj| |gz gz| tj fd|D gtj||S)a0Create a ``UNION`` statement used by a polymorphic mapper. See :ref:`concrete_inheritance` for an example of how this is used. :param table_map: mapping of polymorphic identities to :class:`_schema.Table` objects. :param typecolname: string name of a "discriminator" column, which will be derived from the query, producing the polymorphic identity for each row. If ``None``, no polymorphic discriminator is generated. :param aliasname: name of the :func:`~sqlalchemy.sql.expression.alias()` construct generated. :param cast_nulls: if True, non-existent columns, which are represented as labeled NULLs, will be passed into CAST. This is a legacy behavior that is problematic on some backends such as Oracle - in which case it can be set to False. cF ||S#t$rrAtjtj||cYStjtj||cYSwxYwr^)KeyErrorrcastnulllabel type_coerce)nametable cast_nulls colnamemapstypess r0colzpolymorphic_union..cols Lu%d+ + L L L Lx E$K88>>tDDDDDsxzz5;??EEdKKKKK  Ls A B ?B B Nc(g|]}|Sr+r+r.rrrs r0r1z%polymorphic_union..%;;;$SSu%%;;;r2)from_objc(g|]}|Sr+r+rs r0r1z%polymorphic_union..rr2)r OrderedSetr3rSelectaliasrOaddrctypeitemsroselectliteral_columnsql_util_quote_ddl_exprr union_all) table_map typecolname aliasnamercolnamesrcmrOresulttype_rrrrs ` @@@@r0polymorphic_unionrs,  HK E# eSZ ( ( #KKMME"IcN  " "A LL   AaeH6E!%LL ELLLLLLLF!)) u  " MM ;;;;;(;;;*$4U;;% ,, $W     MM ;;;;;(;;;ug     =& ! ' ' 2 22r2c|rd}t|}|dkrD|d} |d}nF#t$r|d}Yn%wxYw|dvr|\}}ntjd|z|dd}|r*tjd d |zt |}|)|tj || S| || S|d }|r/tjd d |j zt|}| |S) a)Generate "identity key" tuples, as are used as keys in the :attr:`.Session.identity_map` dictionary. This function has several call styles: * ``identity_key(class, ident, identity_token=token)`` This form receives a mapped class and a primary key scalar or tuple as an argument. E.g.:: >>> identity_key(MyClass, (1, 2)) (, (1, 2), None) :param class: mapped class (must be a positional argument) :param ident: primary key, may be a scalar or tuple argument. :param identity_token: optional identity token .. versionadded:: 1.2 added identity_token * ``identity_key(instance=instance)`` This form will produce the identity key for a given instance. The instance need not be persistent, only that its primary key attributes are populated (else the key will contain ``None`` for those missing values). E.g.:: >>> instance = MyClass(1, 2) >>> identity_key(instance=instance) (, (1, 2), None) In this form, the given instance is ultimately run though :meth:`_orm.Mapper.identity_key_from_instance`, which will have the effect of performing a database check for the corresponding row if the object is expired. :param instance: object instance (must be given as a keyword arg) * ``identity_key(class, row=row, identity_token=token)`` This form is similar to the class/tuple form, except is passed a database result row as a :class:`.RowProxy` object. E.g.:: >>> row = engine.execute("select * from table where a=1 and b=2").\ first() >>> identity_key(MyClass, row=row) (, (1, 2), None) :param class: mapped class (must be a positional argument) :param row: :class:`.RowProxy` row returned by a :class:`_engine.ResultProxy` (must be given as a keyword arg) :param identity_token: optional identity token .. versionadded:: 1.2 added identity_token Nrrrowident)rz1expected up to three positional arguments, got %sidentity_tokenzunknown keyword arguments: %sr))rinstance)lenpoprr9r:r;r identity_key_from_primary_keyrto_listidentity_key_from_rowkeysr identity_key_from_instance) argskwargsrlargsclass_rrmapperrs r0 identity_keyrs@ %;D  A::!WF ,jj'' , , , 7++ , f__ MFEE&FN  $4d;;  &/$))F2C2CC f%% ;77 U##N8 //N0 ::j))  &/$))FK2H2HH x((00:::s:AAc(eZdZdZ ddZdZdS) ORMAdapterzaColumnAdapter subclass which excludes adaptation of entities from non-matching mappers. NFTc tj|}|j|_|j}|j}|r||_nd|_t j|||||||j dS)N)adapt_requiredallow_label_resolveanonymize_labels include_fn) rinspectr selectableis_aliased_class aliased_classr ColumnAdapter__init__ _include_fn) rGentity equivalentsrrrinforrs r0rzORMAdapter.__init__os!&))k _ 0  &!'D  !%D ''   ) 3-' (     r2cr|jdd}| p||jS)N parentmapper) _annotationsgetisar)rGelemrs r0rzORMAdapter._include_fns5"&&~t<<z4VZZ 444r2)NFTF)rTrUrVrWrrr+r2r0rrisO      855555r2rc>eZdZdZ d dZdZdZdZdS) AliasedClassaRepresents an "aliased" form of a mapped class for usage with Query. The ORM equivalent of a :func:`~sqlalchemy.sql.expression.alias` construct, this object mimics the mapped class using a ``__getattr__`` scheme and maintains a reference to a real :class:`~sqlalchemy.sql.expression.Alias` object. A primary purpose of :class:`.AliasedClass` is to serve as an alternate within a SQL statement generated by the ORM, such that an existing mapped entity can be used in multiple contexts. A simple example:: # find all pairs of users with the same name user_alias = aliased(User) session.query(User, user_alias).\ join((user_alias, User.id > user_alias.id)).\ filter(User.name == user_alias.name) :class:`.AliasedClass` is also capable of mapping an existing mapped class to an entirely new selectable, provided this selectable is column- compatible with the existing mapped selectable, and it can also be configured in a mapping as the target of a :func:`_orm.relationship`. See the links below for examples. The :class:`.AliasedClass` object is constructed typically using the :func:`_orm.aliased` function. It also is produced with additional configuration when using the :func:`_orm.with_polymorphic` function. The resulting object is an instance of :class:`.AliasedClass`. This object implements an attribute scheme which produces the same attribute and method interface as the original mapped class, allowing :class:`.AliasedClass` to be compatible with any attribute technique which works on the original class, including hybrid attributes (see :ref:`hybrids_toplevel`). The :class:`.AliasedClass` can be inspected for its underlying :class:`_orm.Mapper`, aliased selectable, and other information using :func:`_sa.inspect`:: from sqlalchemy import inspect my_alias = aliased(MyClass) insp = inspect(my_alias) The resulting inspection object is an instance of :class:`.AliasedInsp`. .. seealso:: :func:`.aliased` :func:`.with_polymorphic` :ref:`relationship_aliased_class` :ref:`relationship_to_window_function` NFr+c t|} || j||}t|| |||r|n| j||n| j|| || |_d| jjz|_dS)N)rflatzAliasedClass_%s) r_with_polymorphic_selectabler AliasedInspwith_polymorphic_mapperspolymorphic_on _aliased_insprrT) rGrDrrradapt_on_namesrwith_polymorphic_discriminator base_aliasuse_mapper_pathrepresents_outer_joinrs r0rzAliasedClass.__init__s"#&& =7==>E)    ' 1 $ $0-9 + *&    !  "*FM,BB r2c |jd}|j}t||}n#t$rt wxYwt |dr*t |drt j|j|St |dr| d|}t |dr&| |}t||||S)Nr__call____self____get__adapt_to_entity) __dict___targetgetattrrAttributeErrorhasattrr MethodType__func__rrsetattr)rGrcrtargetattrs r0 __getattr__zAliasedClass.__getattr__s ( M/:M#*F63''DD  # # # "" " # 4 $ $ 9z)B)B 9#DM488 8 4 # # ,<<d++D 4* + + %'' 66D D#t $ $ $ s 'AcHdt||jjjfzS)Nz)idrrrTrKs r0rLzAliasedClass.__repr__s)+ tHH   & //   r2c*t|jSr^)strrrKs r0__str__zAliasedClass.__str__s4%&&&r2) NNFFr+NNFF)rTrUrVrWrrrLrr+r2r0rrs88z  !#'+#%C%C%C%CN:   '''''r2rceZdZdZdZedZdZ edZedZ dZ dZ d Z d Z ejd Zejd Zd ZdZdZdS)raProvide an inspection interface for an :class:`.AliasedClass` object. The :class:`.AliasedInsp` object is returned given an :class:`.AliasedClass` using the :func:`_sa.inspect` function:: from sqlalchemy import inspect from sqlalchemy.orm import aliased my_alias = aliased(MyMappedClass) insp = inspect(my_alias) Attributes on :class:`.AliasedInsp` include: * ``entity`` - the :class:`.AliasedClass` represented. * ``mapper`` - the :class:`_orm.Mapper` mapping the underlying class. * ``selectable`` - the :class:`_expression.Alias` construct which ultimately represents an aliased :class:`_schema.Table` or :class:`_expression.Select` construct. * ``name`` - the name of the alias. Also is used as the attribute name when returned in a result tuple from :class:`_query.Query`. * ``with_polymorphic_mappers`` - collection of :class:`_orm.Mapper` objects indicating all those mappers expressed in the select construct for the :class:`.AliasedClass`. * ``polymorphic_on`` - an alternate column or SQL expression which will be used as the "discriminator" for a polymorphic load. .. seealso:: :ref:`inspection_toplevel` c btj||_||_|x|_x|_|_||_||_tj|p||_ ||_ | |_ |r|d|_ ||_ g|_|j D]^} | |urXt| j||| |} t#|j| jj| |j| j_nd|_ |g|_ t-j||j| d|_| |_|j|_dS)NT)rrrF)rrr)weakrefref _weak_entityrrpersist_selectable local_tablerr _base_alias_use_mapper_pathr_is_with_polymorphicr_with_polymorphic_entitiesrrrrrTrorrr_equivalent_columns_adapter_adapt_on_namesr) rGrrrrrrrrrrpolyents r0rzAliasedInsp.__init__@se$K//  * * *  #   ,";{':d;; 0%:" # 5(,D %,DD ).0D +5 N Nv%%& "#''5(8 CDK)=sCCC3::3;LMMM N).D %-3HD ) . 2)!      .} r2c*|Sr^)rrKs r0rzAliasedInsp.entityws  """r2Tc|jjS)zUReturn the mapped class ultimately represented by this :class:`.AliasedInsp`.)rrrKs r0rzAliasedInsp.class_~s{!!r2cP|jr |jjStj|Sr^)rr_path_registryr per_mapperrKs r0r zAliasedInsp._path_registrys)   1;- -*400 0r2c |j|j|j|j|j|j|j||j|j d S)N) rrrrrrrrrr) rrrrrrrrrrrKs r0 __getstate__zAliasedInsp.__getstate__sRkk_I"2(,(E.2.A**,,#4%)%?   r2c ||d|d|d|d|d|d|d|d|d |d  dS) Nrrrrrrrrrr)r)rGras r0 __setstate__zAliasedInsp.__setstate__ss (O (O 'N &M , - 2 3 ,  # $ " # ) * r2cl|j|||jdS)N) parententityr)rtraverse _annotater)rGrs r0_adapt_elementzAliasedInsp._adapt_elements7}%%d++55!4; ? ?   r2c|j}||vr/||jur|St|j|jjjS||jr|SJd|d|)NFzmapper z doesn't correspond to )rrrrrrTrr)rGr self_polys r0_entity_for_mapperzAliasedInsp._entity_for_mappers1 Y  $$ K!7 ZZ $ $ PK O O&&&$$O O O Or2cjj\}}j|fd|DfS)NcLi|] \}}j||!Sr+)rr)r.rparamrGs r0 z+AliasedInsp._get_clause..s?   C &&s++U   r2)r _get_clauserrr)rGonclause replacemaps` r0rzAliasedInsp._get_clausesa#{6* M " "8 , ,    ","2"2"4"4     r2ciSr^r+rKs r0_memoized_valueszAliasedInsp._memoized_valuess r2cV||jvr |j|S||i|x|j|<}|Sr^)r#)rGrc callable_rkwrls r0_memozAliasedInsp._memosD $' ' '(- -1:D1GB1G1G GD !# &Lr2c|jr(ddd|jDz}nd}dt||jj|fzS)Nz(%s)r)c3.K|]}|jjVdSr^)rrTr.mps r0 z'AliasedInsp.__repr__..s8++') "++++++r2rPz)rr;rrrT)rG with_polys r0rLzAliasedInsp.__repr__su  ( ++-1-J+++""III, tHH K 0   r2cjr7djjddfdjDdSdjjdS)Nzwith_polymorphic(z, [r)c3BK|]}|ju |jjVdSr^)rrrT)r.r+rGs r0r,z&AliasedInsp.__str__..sA,,I&,,,,r2z])zaliased())rrrTr;rrKs`r0rzAliasedInsp.__str__s  $ < < %%% ";  <%)L$9$9$9; ;r2N)rTrUrVrWrpropertyrrrr rrrrrmemoized_propertyrr#r'rLrr+r2r0rrs3$$L5%5%5%n##X# ""X" 11X1           P P P          < < < < r5s &2Fr2c|Sr^r+r4s r0r5r5sr2Fct|tjr-|rtjd|||St |||||S)aProduce an alias of the given element, usually an :class:`.AliasedClass` instance. E.g.:: my_alias = aliased(MyClass) session.query(MyClass, my_alias).filter(MyClass.id > my_alias.id) The :func:`.aliased` function is used to create an ad-hoc mapping of a mapped class to a new selectable. By default, a selectable is generated from the normally mapped selectable (typically a :class:`_schema.Table`) using the :meth:`_expression.FromClause.alias` method. However, :func:`.aliased` can also be used to link the class to a new :func:`_expression.select` statement. Also, the :func:`.with_polymorphic` function is a variant of :func:`.aliased` that is intended to specify a so-called "polymorphic selectable", that corresponds to the union of several joined-inheritance subclasses at once. For convenience, the :func:`.aliased` function also accepts plain :class:`_expression.FromClause` constructs, such as a :class:`_schema.Table` or :func:`_expression.select` construct. In those cases, the :meth:`_expression.FromClause.alias` method is called on the object and the new :class:`_expression.Alias` object returned. The returned :class:`_expression.Alias` is not ORM-mapped in this case. :param element: element to be aliased. Is normally a mapped class, but for convenience can also be a :class:`_expression.FromClause` element. :param alias: Optional selectable unit to map the element to. This is usually used to link the object to a subquery, and should be an aliased select construct as one would produce from the :meth:`_query.Query.subquery` method or the :meth:`_expression.Select.alias` methods of the :func:`_expression.select` construct. :param name: optional string name to use for the alias, if not specified by the ``alias`` parameter. The name, among other things, forms the attribute name that will be accessible via tuples returned by a :class:`_query.Query` object. :param flat: Boolean, will be passed through to the :meth:`_expression.FromClause.alias` call so that aliases of :class:`_expression.Join` objects don't include an enclosing SELECT. This can lead to more efficient queries in many circumstances. A JOIN against a nested JOIN will be rewritten as a JOIN against an aliased SELECT subquery on backends that don't support this syntax. .. seealso:: :meth:`_expression.Join.alias` :param adapt_on_names: if True, more liberal "matching" will be used when mapping the mapped columns of the ORM entity to those of the given selectable - a name-based match will be performed if the given selectable doesn't otherwise have a column that corresponds to one on the entity. The use case for this is when associating an entity with some derived selectable such as one that uses aggregate functions:: class UnitPrice(Base): __tablename__ = 'unit_price' ... unit_id = Column(Integer) price = Column(Numeric) aggregated_unit_price = Session.query( func.sum(UnitPrice.price).label('price') ).group_by(UnitPrice.unit_id).subquery() aggregated_unit_price = aliased(UnitPrice, alias=aggregated_unit_price, adapt_on_names=True) Above, functions on ``aggregated_unit_price`` which refer to ``.price`` will return the ``func.sum(UnitPrice.price).label('price')`` column, as it is matched on the name "price". Ordinarily, the "price" function wouldn't have any "column correspondence" to the actual ``UnitPrice.price`` column as it is not a proxy of the original. z+adapt_on_names only applies to ORM elementsr)rrrr)r3r FromClauser9r:rr)elementrrrrs r0aliasedr;sxn':011   &= }}T}--- )     r2c nt|} |rZ|j| usJtj|}t d|jD} || kr|S|| }| |||\} }|s|r||}t||| ||| S)a Produce an :class:`.AliasedClass` construct which specifies columns for descendant mappers of the given base. Using this method will ensure that each descendant mapper's tables are included in the FROM clause, and will allow filter() criterion to be used against those tables. The resulting instances will also have those columns already loaded so that no "post fetch" of those columns will be required. .. seealso:: :ref:`with_polymorphic` - full discussion of :func:`_orm.with_polymorphic`. :param base: Base class to be aliased. :param classes: a single class or mapper, or list of class/mappers, which inherit from the base class. Alternatively, it may also be the string ``'*'``, in which case all descending mapped classes will be added to the FROM clause. :param aliased: when True, the selectable will be wrapped in an alias, that is ``(SELECT * FROM ) AS anon_1``. This can be important when using the with_polymorphic() to create the target of a JOIN on a backend that does not support parenthesized joins, such as SQLite and older versions of MySQL. However if the :paramref:`.with_polymorphic.selectable` parameter is in use with an existing :class:`_expression.Alias` construct, then you should not set this flag. :param flat: Boolean, will be passed through to the :meth:`_expression.FromClause.alias` call so that aliases of :class:`_expression.Join` objects don't include an enclosing SELECT. This can lead to more efficient queries in many circumstances. A JOIN against a nested JOIN will be rewritten as a JOIN against an aliased SELECT subquery on backends that don't support this syntax. Setting ``flat`` to ``True`` implies the ``aliased`` flag is also ``True``. .. versionadded:: 0.9.0 .. seealso:: :meth:`_expression.Join.alias` :param selectable: a table or select() statement that will be used in place of the generated FROM clause. This argument is required if any of the desired classes use concrete table inheritance, since SQLAlchemy currently cannot generate UNIONs among tables automatically. If used, the ``selectable`` argument must represent the full set of tables and columns mapped by every mapped class. Otherwise, the unaccounted mapped columns will result in their table being appended directly to the FROM clause which will usually lead to incorrect results. :param polymorphic_on: a column to be used as the "discriminator" column for the given selectable. If not given, the polymorphic_on attribute of the base classes' mapper will be used, if any. This is useful for mappings that don't have polymorphic loading behavior by default. :param innerjoin: if True, an INNER JOIN will be used. This should only be specified if querying for one specific subtype only cg|] }|j Sr+)rr*s r0r1z$with_polymorphic..s J J J2RY J J Jr2) innerjoinr8)rrrr) rrrto_setr6runion_with_polymorphic_argsrr) baseclassesrrrr;r>r_existing_aliasprimary_mapper new_classesmapperss r0with_polymorphicrHVsZ&d++N 1%7777+g&& J J!I J J J   k ! !" "mmK00G(??y@GZ1$1%%4%00  !('5("+m    r2c2tj|ddi|S)zDeep copy the given ClauseElement, annotating each element with the "_orm_adapt" flag. Elements within the exclude collection will be cloned but not annotated. _orm_adaptT)r_deep_annotate)r:excludes r0 _orm_annotaterMs  "7\4,@' J JJr2c.tj|dS)zRemove annotations that link a column to a particular mapping. Note this doesn't affect "remote" and "foreign" annotations passed by the :func:`_orm.foreign` and :func:`_orm.remote` annotators. )rJr)rFr_deep_deannotater:s r0_orm_deannotaterRs$  $6   r2c*tj|Sr^rOrQs r0_orm_full_deannotaterTs  $W - --r2cZeZdZdZejjZ ddZdZ d dZ d dZ dS) _ORMJoinz/Extend Join to support ORM constructs as input.NFctj|}t|d|} tj|} | j} | |_||_||_t|tj rt| j |}t|tj r!|j } |j} n&t|t r|} | jj} nd} | rt%j| |jr| }n|j}| || dd| jd\}}}}}}|5|rt-j|||}|}nt-j||||}|}n|}||_t2j||||||| s]t| ddrN| jjrD| jj}|8| jr| j |}|j!|z|_!dSdSdSdSdS)N_joined_from_infoT)source_selectabledest_selectablesource_polymorphicdest_polymorphicof_type_mapperalias_secondaryr)"rrrrrX _left_memo _right_memor3rr4rrQueryableAttribute comparator_source_selectabler1rparentrclause_is_present _create_joinsrrr;_target_adapterrJoinrsingle_single_table_criterionrrrr )rGleftrightr isouterfullr_r` left_info left_orm_info right_infoadapt_to on_selectableprop adapt_frompjsjsourcedest secondarytarget_adapter single_crits r0rz_ORMJoin.__init__sY&t,, &99EE '.. (!+$& h 1 2 2 ?}3X>>H h = > > $/BBDDM$DD . 1 1 D K2MMD  2)-9MNN 2* &1 """, (#'!%)0 $ # ~"HYr::E!HH8D)RAAD!HH#1D   tUHgtLLL < Hd33 <!( <%+CK&.L","5">">{"K"KK $ ;  < < < < < <'&r2cH|}t|tjr!|j}t|tj!|j|usJt |j|j|j|j|j|j}t ||j|j|j|j S)zlSplice a join into the center. Given join(a, b) and join(b, c), return join(a, b).join(c) )rmr_r`)rmr`) r3rrhrkrlrVr rmr_r`)rGotherleftmostrks r0_splice_into_centerz_ORMJoin._splice_into_center1s 38,, %}H38,, %zX%%%% I J ML(      K NM)     r2c*t|||||S)N)rnrmrV)rGrlr rmrn join_to_lefts r0r;z _ORMJoin.joinNseXD'JJJJr2c*t|||d|S)NT)rmrnr)rGrlr rnrs r0 outerjoinz_ORMJoin.outerjoinXseXt$GGGGr2)NFFNNNFFNNFN) rTrUrVrWrrh__visit_name__rrr;rr+r2r0rVrVs99_3N  Q<Q<Q<Q fn(A, A) -> True someoption(A).someoption(C.d) # -> fn(A, C) -> False a1 = aliased(A) someoption(a1).someoption(A.b) # -> fn(a1, A) -> False someoption(a1).someoption(a1.b) # -> fn(a1, a1) -> True wp = with_polymorphic(A, [A1, A2]) someoption(wp).someoption(A1.foo) # -> fn(wp, A1) -> False someoption(wp).someoption(wp.A1.foo) # -> fn(wp, wp.A1) -> True )rrrrrrrs r0$_entity_corresponds_to_use_path_implrs(    # P++ P&NEV-N$N  $ ""6=111  # 988 r2c|jr#||jvp|j|S|jr ||jvS||S)zedetermine if 'given' "is a" mapper, in terms of the given would load rows of type 'mapper'. )rrrr)rrs r0 _entity_isarsh  !77 5<;K;K < <    '!777yy   r2c|ddlm}m}m}m}ddlm}ddlm}|x|_ x|_ x|_ x|_ |_ dS)aZUse random-ordering sets within the unit of work in order to detect unit of work sorting issues. This is a utility function that can be used to help reproduce inconsistent unit of work sorting issues. For example, if two kinds of objects A and B are being inserted, and B has a foreign key reference to A - the A must be inserted first. However, if there is no relationship between A and B, the unit of work won't know to perform this sorting, and an operation may or may not fail, depending on how the ordering works out. Since Python sets and dictionaries have non-deterministic ordering, such an issue may occur on some runs and not on others, and in practice it tends to have a great dependence on the state of the interpreter. This leads to so-called "heisenbugs" where changing entirely irrelevant aspects of the test program still cause the failure behavior to change. By calling ``randomize_unitofwork()`` when a script first runs, the ordering of a key series of sets within the unit of work implementation are randomized, so that the script can be minimized down to the fundamental mapping and operation that's failing, while still reproducing the issue on at least some runs. This utility is also available when running the test suite via the ``--reversetop`` flag. r) unitofworksessionr dependency) topological) RandomSetN) sqlalchemy.ormrrrrsqlalchemy.utilrsqlalchemy.testing.utilrr6)rrrrrrs r0randomize_unitofworkrs6GFFFFFFFFFFF++++++1111115>>KO>> >j:>>>r2)rT)NNFF)FFNFFFNr^rr);rQrrrPrrBrrrrr r r r r rrr interfacesrr path_registryrrrr9rrrrrrArXr$rrrrrobjectrr _inspectsr;rHrMrRrTrhrVr;rrrrrrrrr+r2r0rs """""" %%%%%%!!!!!!&&&&&&&&&&&&''''''""""""y    ?????Y???D?D?D?DF=AF3F3F3F3Re;e;e;P$5$5$5$5$5'$5$5$5NF'F'F'F'F'6F'F'F'RO<O<O<O<O<.O<O<O!>!>!>!>r2