
    -h)             	          S SK r S SKrS SKrSSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SSKJ
r
  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ r   SSK!J"r"  SSKJr#  SSKJ$r$  SS KJ%r%  SS!KJ&r&  SS"KJ'r'  SSKJ r(  SS#KJ)r)  SS$K*J+r+  SS%K,J-r-  \." S&5      r/ " S' S(\.5      r0S) r1 SKS* jr2S+ r3 " S, S-\(Rh                  5      r5 " S. S/\65      r7 " S0 S1\\\#Rp                  \5      r9 " S2 S3\65      r: " S4 S5\5      r;\Rx                  " \75      " S6 5        \Rx                  " \95      " S7 5        SLS8 jr=        SMS9 jr>\R~                   " S: S;\\+\#Rp                  \5      5       r@SNS< jrAS= rBS> rC " S? S@\%R                  5      rE SOSA jrFSPSB jrGSNSC jrHSD rISE rJSF rKSG rLSH rMSI rNSJ rOg)Q    N   )
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)CriteriaOption)MapperProperty)ORMColumnsClauseRole)ORMEntityColumnsClauseRole)ORMFromClauseRole)PropComparator)PathRegistry   )event)exc)
inspection)sql)utilresult_tuple)base)	coercions)
expression)lambdas)roles)visitors)SupportsCloneAnnotations)ColumnCollection)deletedelete-orphanallmergeexpungesave-updaterefresh-expirenonec                   j    \ rS rSrSr\R                  / SQ5      r\r/ SQr	Sr
S rS r\S 5       rS	rg
)CascadeOptions@   zDKeeps track of the options sent to
:paramref:`.relationship.cascade`)r*   r/   r)   )r,   r*   r/   r.   r+   )save_updater(   refresh_expirer+   r,   delete_orphanc                 @   [        U[        R                  5      (       d  Uc  U R                  U5      $ [	        U5      nUR                  U R                  5      (       ad  [        R                  " SSR                  [        UR                  U R                  5      5       Vs/ s H  n[        U5      PM     sn5      -  5      eSU;   a  UR                  U R                  5        SU;   a  UR                  5         UR                  S5        [         R#                  [$        U5      nSU;   Ul        SU;   Ul        SU;   Ul        SU;   Ul        S	U;   Ul        S
U;   Ul        UR0                  (       a'  UR(                  (       d  [        R2                  " S5        U$ s  snf )NzInvalid cascade option(s): %s, r*   r/   r-   r(   r.   r+   r,   r)   z5The 'delete-orphan' cascade option requires 'delete'.)
isinstancer   string_typesfrom_stringset
difference_allowed_cascadessa_excArgumentErrorjoinsortedreprupdate_add_w_all_cascadescleardiscard	frozenset__new__r1   r3   r(   r4   r+   r,   r5   warn)cls
value_listvaluesxselfs        hC:\Users\ROHAN GUPTA\OneDrive\Desktop\mathbuddy-assessment\venv\Lib\site-packages\sqlalchemy/orm/util.pyrH   CascadeOptions.__new__T   sm   j$"3"344
8J??:..ZS2233&&/)) "("--c.C.CD""A Q"
 
 F?MM#112VLLNu  8(F2&(.&8&
 F*,6dkkIIJ 7s   !Fc                 f    SSR                  [        U 5       Vs/ s H  oPM     sn5      -  $ s  snf )NzCascadeOptions(%r),)r@   rA   )rN   rM   s     rO   __repr__CascadeOptions.__repr__y   s,    #sxxF4L0ILqL0I'JKK0Is   .
c                     [         R                  " SU=(       d    S5       Vs/ s H  o"(       d  M  UPM     nnU " U5      $ s  snf )Nz\s*,\s* )resplit)rJ   argcrL   s       rO   r:   CascadeOptions.from_string|   s9    XXj#)<B<!<B6{ Cs
   
AA)r(   r5   r,   r+   r4   r3   N)__name__
__module____qualname____firstlineno____doc__all_cascadesr<   rD   r=   _viewonly_cascades	__slots__rH   rS   classmethodr:   __static_attributes__     rO   r1   r1   @   sR    ) '11( %NI#JL  rg   r1   c                   ^^^^	 T(       d  U4S jm	U(       a%  U	UUU4S jnU	UUU4S jnU	UUU4S jnU	UUU4S jnOU	UUU4S jnU	UUU4S jnU	UUU4S jn[         R                  " U S	US
S
S9  [         R                  " U SUS
S9  [         R                  " U SUS
S
S9  U(       a  [         R                  " U SWS
S
S9  gg)zFRuns a validation method on an attribute value to be set or
appended.
c                 R   > U R                   T   R                  nUR                  UL$ N)managerimpl)state	initiatorrl   keys      rO   detect_is_backref,_validator_events.<locals>.detect_is_backref   s&    ==%**D>>--rg   c                    > UR                   [        R                  La-  T(       d  T" X5      (       d  T" U R                  5       TUS5      $ U$ NFopr   OP_BULK_REPLACEobjrm   valuern   rp   include_backrefsro   	validators      rO   append!_validator_events.<locals>.append   s?    ||:#=#== (9%(K(K c5%@@rg   c           	         > T(       d  T" X5      (       d0  U R                  5       nU Vs/ s H  nT" UTUS5      PM     snUS S & g g s  snf rs   rw   	rm   rL   rn   rw   ry   rp   rz   ro   r{   s	        rO   bulk_set#_validator_events.<locals>.bulk_set   sO    '8'J'JiikCICI%Ic3u56q	 (Ks   Ac                 b   > T(       d  T" X5      (       d  T" U R                  5       TUS5      $ U$ rs   r   rm   ry   oldvaluern   rp   rz   ro   r{   s       rO   set__validator_events.<locals>.set_   s-    '8'J'J c5%@@rg   c                 b   > T(       d  T" X5      (       d  T" U R                  5       TUS5        g g )NTr   rx   s      rO   remove!_validator_events.<locals>.remove   s+    '8'J'J%))+sE48 (Krg   c                    > UR                   [        R                  La,  T(       d  T" X5      (       d  T" U R                  5       TU5      $ U$ rj   rt   rx   s      rO   r|   r}      s=    ||:#=#== (9%(K(K c599rg   c                    > T(       d  T" X5      (       d/  U R                  5       nU Vs/ s H  nT" UTU5      PM     snUS S & g g s  snf rj   r   r   s	        rO   r   r      sF    '8'J'JiikEKLVEYsC7VLq	 (KLs   Ac                 `   > T(       d  T" X5      (       d  T" U R                  5       TU5      $ U$ rj   r   r   s       rO   r   r      s+    '8'J'J c599rg   r|   T)rawretvalbulk_replace)r   r;   r   N)r   listen)
descro   r{   include_removesrz   r|   r   r   r   rp   s
    `` `    @rO   _validator_eventsr      s    
 	. 	 		 		 		9 	9	 		M 	M
	 	 
LLxT$?	LL~xT:	LLudT:T8VdC rg   c                   ^^^ [         R                  " 5       n0 m0 mU  H  nX   n[        R                  " [        R
                  USS9nX`U'   0 nUR                   Ht  nUR                  U:X  a  [        R                  " SU< SU< S35      eUR                  UR                  5        XUR                  '   UR                  TUR                  '   Mv     UTU'   M     UUU4S jn	/ n
U R                  5        H  u  pUb  U
R                  [        R                  " U Vs/ s H
  o" X5      PM     sn[        R                   " ["        R$                  " U5      5      R'                  U5      /-   6 R)                  U5      5        M  U
R                  [        R                  " U Vs/ s H
  o" X5      PM     sn6 R)                  U5      5        M     [        R*                  " U
6 R-                  U5      $ s  snf s  snf )a  Create 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.

T)allow_selectzPolymorphic union can't use 'z3' as the discriminator column due to mapped column zn; please apply the 'typecolname' argument; this is available on ConcreteBase as '_concrete_discriminator_name'c                 8  >  TU   U    $ ! [          a    T(       a>  [        R                  " [        R                  " 5       TU    5      R	                  U 5      s $ [        R
                  " [        R                  " 5       TU    5      R	                  U 5      s $ f = frj   )KeyErrorr   castnulllabeltype_coerce)nametable
cast_nullscolnamemapstypess     rO   colpolymorphic_union.<locals>.col   sy    	Lu%d++ 	Lxx
E$K8>>tDDsxxz5;?EEdKK		Ls    AB<BB)r   
OrderedSetr!   expectr$   StrictFromClauseRolerZ   ro   r>   InvalidRequestErroraddtypeitemsr|   r   selectliteral_columnsql_util_quote_ddl_exprr   select_from	union_allalias)	table_maptypecolname	aliasnamer   colnamesro   r   mrZ   r   resulttype_r   r   r   s      `         @@rO   polymorphic_unionr      s   ,  HKE  &&D
 #Auu#00 #A'  LLaeeH66E!%%L  E- 0L F!)"MM

6>?hdT)h?.. ( 8 8 ?#eK0	 +e$ MM

3;<84c$&8<+e$ *( ==&!''	22 @ =s   G0"G5c                     U (       a  Sn[        U 5      nUS:X  a  U S   n UR                  S5      nO$US;   a  U u  pEO[        R                  " SU-  5      eUR                  SS5      nU(       a(  [        R                  " S	S
R                  U5      -  5      e[        U5      nUc$  UR                  [        R                  " W5      US9$ UR                  X&S9$ UR                  S5      nU(       a2  [        R                  " S	S
R                  UR                  5      -  5      e[        U5      nUR                  U5      $ ! [         a    UR                  S5      n GNf = f)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))
    (<class '__main__.MyClass'>, (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)
    (<class '__main__.MyClass'>, (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:`.Row` object.

  E.g.::

    >>> row = engine.execute(\
        text("select * from table where a=1 and b=2")\
        ).first()
    >>> identity_key(MyClass, row=row)
    (<class '__main__.MyClass'>, (1, 2), None)

  :param class: mapped class (must be a positional argument)
  :param row: :class:`.Row` row returned by a :class:`_engine.CursorResult`
   (must be given as a keyword arg)
  :param identity_token: optional identity token

    .. versionadded:: 1.2 added identity_token

Nr   r   rowident)r      z1expected up to three positional arguments, got %sidentity_tokenzunknown keyword arguments: %sr7   )r   instance)lenpopr   r>   r?   r@   r	   identity_key_from_primary_keyr   to_listidentity_key_from_rowkeysr   identity_key_from_instance)	argskwargsr   largsclass_r   r   mapperr   s	            rO   identity_keyr     sk   @ D	A:!WF,jj' f_ MFE&&FN   $4d;&&/$))F2CC  f%;77U#N 8   // 0   ::j)&&/$))FKK2HH  x(00::=  ,

7+,s   D? ?EEc                   0    \ rS rSrSr    SS jrS rSrg)
ORMAdapteri~  zYColumnAdapter subclass which excludes adaptation of entities from
non-matching mappers.

Nc           
         [         R                  " U5      nUR                  U l        UR                  nUR                  nU(       a  Xl        OS U l        [        R                  R                  U UUUUUU R                  S9  g )N)adapt_requiredallow_label_resolveanonymize_labels
include_fn)
r   inspectr   
selectableis_aliased_classaliased_classr   ColumnAdapter__init___include_fn)	rN   entityequivalentsr   r   r   infor   r   s	            rO   r   ORMAdapter.__init__  sy     !!&)kk__
00!'!%D'') 3-'' 	( 	
rg   c                     UR                   R                  SS 5      nU(       + =(       d=    UR                  U R                  5      =(       d    U R                  R                  U5      $ )Nparentmapper)_annotationsgetisar   )rN   elemr   s      rO   r   ORMAdapter._include_fn  sF    ""&&~t<zOVZZ4O8OOrg   )r   r   )NFTF)r\   r]   r^   r_   r`   r   r   re   rf   rg   rO   r   r   ~  s       
8Prg   r   c                   \    \ rS rSrSr         SS jr\S 5       rS rS r	S r
S	 rS
rg)AliasedClassi  aD  Represents 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`


Nc                    [         R                  " U5      nUR                  nSnUcb  UR                  (       a6  UR                  R
                  (       a  UR                  R                  5       nO.UR                  R                  UUS9nOUR                  (       a  Sn[        U UUUU(       a  UOUR                  Ub  UOUR                  UU	UU
U5      U l        SUR                  R                  -  U l        g )NFr   flatTAliasedClass_%s)r   r   r   r   r   _is_subqueryr   _with_polymorphic_selectable_anonymous_fromclauseAliasedInspwith_polymorphic_mapperspolymorphic_on_aliased_inspr   r\   )rN   mapped_class_or_acr   r   r   adapt_on_namesr   with_polymorphic_discriminator
base_aliasuse_mapper_pathrepresents_outer_joininspr   nest_adapterss                 rO   r   AliasedClass.__init__  s     !!"45=$$)E)E--/ 77MM!! N   "" M(' %00-9 +&&!
$ *FMM,B,BBrg   c                 B   U R                  U 5      nSUR                  R                  R                  -  Ul        Xl        UR
                  (       aN  UR                   H>  nX1Ld  M	  [        R                  U5      n[        X#R                  R                  U5        M@     U$ )Nr   )
rH   r   r   r\   r   _is_with_polymorphic_with_polymorphic_entitiesr   _reconstitute_from_aliased_inspsetattr)rJ   aliased_insprw   sub_aliased_inspents        rO   r   ,AliasedClass._reconstitute_from_aliased_insp  s    kk#(<+>+>+E+E+N+NN(,,$0$K$K #7&FF(C C!8!8!A!A3G %L 
rg   c                     U R                   S   nUR                  n[        X15      n[        US5      (       a2  [        US5      (       a!  [        R                  " UR                  U 5      $ [        US5      (       a  UR                  S U 5      n[        US5      (       a  UR                  U5      n[        XU5        U$ ! [         a    [	        5       ef = f)Nr   __call____self____get__adapt_to_entity)__dict___targetgetattrr   AttributeErrorhasattrr   
MethodType__func__r  r	  r   )rN   ro   r   targetattrs        rO   __getattr__AliasedClass.__getattr__%  s    	( MM/:M #**F6'D
 4$$z)B)B##DMM488 4##<<d+D 4*++''6DDt$1  	# ""	#s   B> >Cc                 z   [        X!5      n[        US5      (       a2  [        US5      (       a!  [        R                  " UR                  U 5      $ [        US5      (       a  UR                  S U 5      n[        US5      (       a8  [        R                  " U 5      Ul        UR                  U5      n[        XU5        U$ )Nr  r  r  r	  )r  r  r   r  r  r  weakrefref_weak_entityr	  r   )rN   ro   mapped_classr  r  s        rO   _get_from_serialized!AliasedClass._get_from_serializedB  s     |)4$$z)B)B##DMM488 4##<<d+D 4*++(/D(9L%''5DDt$rg   c                 ^    S[        U 5      U R                  R                  R                  4-  $ )Nz<AliasedClass at 0x%x; %s>)idr   r  r\   rN   s    rO   rS   AliasedClass.__repr__W  s0    +tH&&///
 
 	
rg   c                 ,    [        U R                  5      $ rj   )strr   r  s    rO   __str__AliasedClass.__str__]  s    4%%&&rg   )r\   r   )	NNFFrf   NNFF)r\   r]   r^   r_   r`   r   rd   r   r  r  rS   r"  re   rf   rg   rO   r   r     sT    8z !#'+#2Ch  :*
'rg   r   c                   h   \ rS rSrSrS\R                  R                  4S\R                  R                  4S\R                  R                  4S\R                  R                  4S\R                  R                  4S\R                  R                  4S	\R                  R                  4/rS
 r\S 5       rSr \R&                  S 5       r\S 5       r\S 5       r\S 5       rS rS rSS jrS r\R8                  S 5       r\R8                  S 5       r\R8                  S 5       rS r S r!S r"Sr#g)r   ia  a  Provide 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`

r   _adapt_on_names_use_mapper_pathr  r   r   r   c           
         UR                   nUR                  n[        R                  " U5      U l        Xl        U=U l        =U l        U l        X@l        X`l	        [        R                  " U=(       d    U 5      U l
        Xl        Xl        Xl        U(       a  SU l        XPl        / U l        U R                   Hp  nXLd  M	  [#        UR$                  UU U	US9n['        U R                   UR$                  R(                  U5        U R                   R+                  UR,                  5        Mr     OSU l        U/U l        [.        R0                  " UUR2                  U	SU R                   Vs1 s H  nU	(       a  M  UR
                  iM     snS9U l        U(       a*  UR4                  R7                  U R4                  5      U l        Xl        Xl        g s  snf )NT)r   r   r   F)r   r   r   adapt_from_selectables)r   r   r  r  r  r   persist_selectablelocal_tabler   r   _base_aliasr&  r   _nest_adaptersr   r   r   r   r   r   r\   r|   r   r   r   _equivalent_columns_adapterwrapr%  r  )rN   r   	inspectedr   r   r   r   r+  r&  r   r   r   r   r   polyr  r   s                    rO   r   AliasedInsp.__init__  s    '--!!#KK/  *	* 	*#	,";;{':d; 0%:"+#(,D%,D).0D+55%&"#''5(8C DKK)=)=sC33::3;L;LM 6 ).D%-3HD) ..22)! 66$6A% 6$
 %..33DMMBDM-)$s   (G7Gc                     U R                  5       nUc0  [        R                  U 5      n[        R                  " U5      U l         U$ rj   )r  r   r   r  r  )rN   r  s     rO   r   AliasedInsp.entity  s=     !;>>tDC 'C 0D
rg   Tc                 x    U R                   R                  U R                  U U S.5      R                  SU S.5      $ )N)r   parententityentity_namespaceormcompile_state_pluginplugin_subject)r   	_annotater   _set_propagate_attrsr  s    rO   __clause_element__AliasedInsp.__clause_element__  s@    (( $ $$(
 
%*dC
	
rg   c                     U R                   $ rj   )r   r  s    rO   r7  AliasedInsp.entity_namespace   s    {{rg   c                 .    U R                   R                  $ )zMReturn the mapped class ultimately represented by this
:class:`.AliasedInsp`.)r   r   r  s    rO   r   AliasedInsp.class_  s     {{!!!rg   c                 |    U R                   (       a  U R                  R                  $ [        R                  " U 5      $ rj   )r&  r   _path_registryr   
per_mapperr  s    rO   rE  AliasedInsp._path_registry
  s,      ;;---**400rg   c                    U R                   U R                  U R                  U R                  U R                  U R
                  U R                  U R                  5       U R                  U R                  U R                  S.$ )N)r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r%  r   r   r+  r&  r   r,  r  s    rO   __getstate__AliasedInsp.__getstate__  sj    kkkk__II"22(,(E(E.2.A.A**,#44%)%?%?!00
 	
rg   c                 |    U R                  US   US   US   US   US   US   US   US   US	   US
   US   5        g )Nr   r   r   r   r   r   r   r   r   r   r   )r   )rN   rm   s     rO   __setstate__AliasedInsp.__setstate__   sg    (O(O'N&M,-23,#$"#)*/"	
rg   Nc                     U U R                   S.nU(       a  X#S'   U R                  R                  U5      R                  U5      R	                  SU S.5      $ )N)r6  r   	proxy_keyr8  r9  )r   r.  traverser<  r=  )rN   r   ro   ds       rO   _adapt_elementAliasedInsp._adapt_element/  sR      KK
  kNMM""4(Yq\!!).$G	
rg   c                    U R                   nX;   aD  XR                  L a  U $ [        U R                  UR                  R
                  5      R                  $ UR                  U R                  5      (       a  U $  SU< SU < 35       e)Nzmapper z doesn't correspond to )r   r   r  r   r   r\   r   r   )rN   r   	self_polys      rO   _entity_for_mapperAliasedInsp._entity_for_mapper>  sp    11	$KK!7!7-  ZZ$$KO&$OO5rg   c                     U R                   R                  u  pU R                  R                  U5      UR	                  5        VVs0 s H!  u  p4U R                  R                  U5      U_M#     snn4$ s  snnf rj   )r   _get_clauser.  rP  r   )rN   onclause
replacemapr   params        rO   rY  AliasedInsp._get_clauseL  sq    #{{66MM""8, #-"2"2"4"4JC &&s+U2"4
 	
s   (A3c                     0 $ rj   rf   r  s    rO   _memoized_valuesAliasedInsp._memoized_valuesW  s    	rg   c                 P   U R                   (       a@  U R                  R                  U R                   Vs/ s H  oR                  PM     sn5      nOU R                  R                  5       nU VVs/ s H  u  p4X0R	                  U5      4PM     nnn[        U5      $ s  snf s  snnf rj   )r   r   _columns_plus_keysr   rR  r'   )rN   r  cols_plus_keysro   r   s        rO   _all_column_expressions#AliasedInsp._all_column_expressions[  s    $$![[;;'+'F'FG'F'FGN "[[;;=N =K
<JS%%c*+N 	 
  // H

s   B1B"c                 p    XR                   ;   a  U R                   U   $ U" U0 UD6=U R                   U'   nU$ rj   )r_  )rN   ro   	callable_r   kwry   s         rO   _memoAliasedInsp._memoj  sC    '''((--1:D1GB1GGD!!#&Lrg   c                     U R                   (       a&  SSR                  S U R                    5       5      -  nOSnS[        U 5      U R                  R                  U4-  $ )Nz(%s)r7   c              3   L   #    U  H  oR                   R                  v   M     g 7frj   )r   r\   ).0mps     rO   	<genexpr>'AliasedInsp.__repr__.<locals>.<genexpr>s  s      +-Jr		""-Js   "$rV   z<AliasedInsp at 0x%x; %s%s>)r   r@   r  r   r\   )rN   	with_polys     rO   rS   AliasedInsp.__repr__q  sc    (( +-1-J-J+ " I I,tHKK  0
 
 	
rg   c                    ^  T R                   (       aB  ST R                  R                  < SSR                  U 4S jT R                   5       5      < S3$ ST R                  R                  < S3$ )Nzwith_polymorphic(z, [r7   c              3   r   >#    U  H,  nUTR                   Ld  M  UR                  R                  v   M.     g 7frj   )r   r   r\   )rm  rn  rN   s     rO   ro  &AliasedInsp.__str__.<locals>.<genexpr>  s0      ;, 'BII&&;s   77z])zaliased())r   r  r\   r@   r   r  s   `rO   r"  AliasedInsp.__str__~  s_    $$$%%		 ";;   % %)LL$9$9;;rg   )r%  r.  r+  r   r,  r  r&  r  r   r*  r   r   r)  r   r   r   r   rj   )$r\   r]   r^   r_   r`   r%   ExtendedInternalTraversal	dp_string
dp_booleandp_inspectabledp_clauseelementInternalTraversaldp_has_cache_key_list_cache_key_traversalr   propertyr   r   r   memoized_instancemethodr>  r7  r   rE  rI  rL  rR  rV  memoized_propertyrY  r_  rd  ri  rS   r"  re   rf   rg   rO   r   r   a  s   $N 
33==>	H>>IIJ	X??JJK	H66EEF	x99JJK&&&<<	
 
855FFGF*R   	!!	
 "	
   " "
 1 1


P 

 
 
  
0 0
<rg   r   c                   R    \ rS rSrSrSrS r\R                  " S5      S 5       r	Sr
g)_WrapUserEntityi  zA wrapper used within the loader_criteria lambda caller so that
we can bypass declared_attr descriptors on unmapped mixins, which
normally emit a warning for such use.

might also be useful for other per-lambda instrumentations should
the need arise.

subjectc                     Xl         g rj   r  )rN   r  s     rO   r   _WrapUserEntity.__init__  s    rg   zsqlalchemy.orm.decl_apic                 6   [         R                  R                  R                  n[        R                  U S5      nXR                  ;   aF  [        UR                  U   UR                  5      (       a  UR                  U   R                  U5      $ [        X15      $ )Nr  )r   	preloadedr8  decl_apiobject__getattribute__r
  r8   declared_attrfgetr  )rN   r   r  r  s       rO   r   _WrapUserEntity.__getattribute__  s    >>%%..))$	:###
T"H$:$:)
 )
 ##D)..w777))rg   N)r\   r]   r^   r_   r`   rc   r   r   preload_moduler  re   rf   rg   rO   r  r    s3     I 
23	* 4	*rg   r  c                   N   \ rS rSrSrS\R                  R                  4S\R                  R                  4S\R                  R                  4S\R                  R                  4S\R                  R                  4/r    SS jr\S	 5       rS
 rS rS rS rS rS rS rSrg)LoaderCriteriaOptioni  zAdd additional WHERE criteria to the load for all occurrences of
a particular entity.

:class:`_orm.LoaderCriteriaOption` is invoked using the
:func:`_orm.with_loader_criteria` function; see that function for
details.

.. versionadded:: 1.4

root_entityr   where_criteriainclude_aliasespropagate_to_loadersc           	      
   [         R                  " US5      nUc  Xl        SU l        OSU l        Xpl        X l        [        U5      (       a{  SU l        [        R                  " U[        R                  [        U R                  b  U R                  OU R                  R                  5      4[        R                  " US9S9U l        O1SU l        [        R                  " [        R                  U5      U l        X@l        XPl        g)a  Add additional WHERE criteria to the load for all occurrences of
a particular entity.

.. versionadded:: 1.4

The :func:`_orm.with_loader_criteria` option is intended to add
limiting criteria to a particular kind of entity in a query,
**globally**, meaning it will apply to the entity as it appears
in the SELECT query as well as within any subqueries, join
conditions, and relationship loads, including both eager and lazy
loaders, without the need for it to be specified in any particular
part of the query.    The rendering logic uses the same system used by
single table inheritance to ensure a certain discriminator is applied
to a table.

E.g., using :term:`2.0-style` queries, we can limit the way the
``User.addresses`` collection is loaded, regardless of the kind
of loading used::

    from sqlalchemy.orm import with_loader_criteria

    stmt = select(User).options(
        selectinload(User.addresses),
        with_loader_criteria(Address, Address.email_address != 'foo'))
    )

Above, the "selectinload" for ``User.addresses`` will apply the
given filtering criteria to the WHERE clause.

Another example, where the filtering will be applied to the
ON clause of the join, in this example using :term:`1.x style`
queries::

    q = session.query(User).outerjoin(User.addresses).options(
        with_loader_criteria(Address, Address.email_address != 'foo'))
    )

The primary purpose of :func:`_orm.with_loader_criteria` is to use
it in the :meth:`_orm.SessionEvents.do_orm_execute` event handler
to ensure that all occurrences of a particular entity are filtered
in a certain way, such as filtering for access control roles.    It
also can be used to apply criteria to relationship loads.  In the
example below, we can apply a certain set of rules to all queries
emitted by a particular :class:`_orm.Session`::

    session = Session(bind=engine)

    @event.listens_for("do_orm_execute", session)
    def _add_filtering_criteria(execute_state):

        if (
            execute_state.is_select
            and not execute_state.is_column_load
            and not execute_state.is_relationship_load
        ):
            execute_state.statement = execute_state.statement.options(
                with_loader_criteria(
                    SecurityRole,
                    lambda cls: cls.role.in_(['some_role']),
                    include_aliases=True
                )
            )

In the above example, the :meth:`_orm.SessionEvents.do_orm_execute`
event will intercept all queries emitted using the
:class:`_orm.Session`. For those queries which are SELECT statements
and are not attribute or relationship loads a custom
:func:`_orm.with_loader_criteria` option is added to the query.    The
:func:`_orm.with_loader_criteria` option will be used in the given
statement and will also be automatically propagated to all relationship
loads that descend from this query.

The criteria argument given is a ``lambda`` that accepts a ``cls``
argument.  The given class will expand to include all mapped subclass
and need not itself be a mapped class.

.. tip::

   When using :func:`_orm.with_loader_criteria` option in
   conjunction with the :func:`_orm.contains_eager` loader option,
   it's important to note that :func:`_orm.with_loader_criteria` only
   affects the part of the query that determines what SQL is rendered
   in terms of the WHERE and FROM clauses. The
   :func:`_orm.contains_eager` option does not affect the rendering of
   the SELECT statement outside of the columns clause, so does not have
   any interaction with the :func:`_orm.with_loader_criteria` option.
   However, the way things "work" is that :func:`_orm.contains_eager`
   is meant to be used with a query that is already selecting from the
   additional entities in some way, where
   :func:`_orm.with_loader_criteria` can apply it's additional
   criteria.

   In the example below, assuming a mapping relationship as
   ``A -> A.bs -> B``, the given :func:`_orm.with_loader_criteria`
   option will affect the way in which the JOIN is rendered::

        stmt = select(A).join(A.bs).options(
            contains_eager(A.bs),
            with_loader_criteria(B, B.flag == 1)
        )

   Above, the given :func:`_orm.with_loader_criteria` option will
   affect the ON clause of the JOIN that is specified by
   ``.join(A.bs)``, so is applied as expected. The
   :func:`_orm.contains_eager` option has the effect that columns from
   ``B`` are added to the columns clause::

        SELECT
            b.id, b.a_id, b.data, b.flag,
            a.id AS id_1,
            a.data AS data_1
        FROM a JOIN b ON a.id = b.a_id AND b.flag = :flag_1


   The use of the :func:`_orm.contains_eager` option within the above
   statement has no effect on the behavior of the
   :func:`_orm.with_loader_criteria` option. If the
   :func:`_orm.contains_eager` option were omitted, the SQL would be
   the same as regards the FROM and WHERE clauses, where
   :func:`_orm.with_loader_criteria` continues to add its criteria to
   the ON clause of the JOIN. The addition of
   :func:`_orm.contains_eager` only affects the columns clause, in that
   additional columns against ``b`` are added which are then consumed
   by the ORM to produce ``B`` instances.

.. warning:: The use of a lambda inside of the call to
  :func:`_orm.with_loader_criteria` is only invoked **once per unique
  class**. Custom functions should not be invoked within this lambda.
  See :ref:`engine_lambda_caching` for an overview of the "lambda SQL"
  feature, which is for advanced use only.

:param entity_or_base: a mapped class, or a class that is a super
 class of a particular set of mapped classes, to which the rule
 will apply.

:param where_criteria: a Core SQL expression that applies limiting
 criteria.   This may also be a "lambda:" or Python function that
 accepts a target class as an argument, when the given class is
 a base with many different mapped subclasses.

 .. note:: To support pickling, use a module-level Python function to
    produce the SQL expression instead of a lambda or a fixed SQL
    expression, which tend to not be picklable.

:param include_aliases: if True, apply the rule to :func:`_orm.aliased`
 constructs as well.

:param propagate_to_loaders: defaults to True, apply to relationship
 loaders such as lazy loaders.  This indicates that the
 option object itself including SQL expression is carried along with
 each loaded instance.  Set to ``False`` to prevent the object from
 being assigned to individual instances.

.. seealso::

    :ref:`examples_session_orm_events` - includes examples of using
    :func:`_orm.with_loader_criteria`.

    :ref:`do_orm_execute_global_criteria` - basic example on how to
    combine :func:`_orm.with_loader_criteria` with the
    :meth:`_orm.SessionEvents.do_orm_execute` event.

:param track_closure_variables: when False, closure variables inside
 of a lambda expression will not be used as part of
 any cache key.    This allows more complex expressions to be used
 inside of a lambda expression but requires that the lambda ensures
 it returns the identical SQL every time given a particular class.

 .. versionadded:: 1.4.0b2

FNT)track_closure_variables)lambda_argsopts)r   r   r  r   _where_crit_origcallabledeferred_where_criteriar#   DeferredLambdaElementr$   WhereHavingRoler  LambdaOptionsr  r!   r   r  r  )rN   entity_or_baser  loader_onlyr  r  r  r   s           rO   r   LoaderCriteriaOption.__init__  s    h ##NE:>-DK#D K .N##+/D(")"?"?%%#++7 ((![[// **,C#D ,1D("+"2"2%%~#D  /$8!rg   c                     [        UUUUS9$ )N)r  r  )r  )rJ   r   r  r  r  s        rO   	_unreduceLoaderCriteriaOption._unreduce  s     $+!5	
 	
rg   c                     [         R                  U R                  (       a  U R                  R                  OU R                  U R
                  U R                  U R                  44$ rj   )r  r  r   r   r  r  r  r  r  s    rO   
__reduce__LoaderCriteriaOption.__reduce__  sP     **&*kk""t7G7G%%$$))	
 	
rg   c              #     #    U R                   (       a,  U R                   R                  R                   H  nUv   M	     g [        U R                  R                  5       5      nU(       ax  UR                  S5      n[        R                  " USS9nU(       a"  UR                  R                   H  nUv   M	     OUR                  UR                  5       5        U(       a  Mw  g g 7f)Nr   F)raiseerr)
r   r   self_and_descendantslistr  __subclasses__r   r   r   extend)rN   r  stacksubclassrn  s        rO   _all_mappers!LoaderCriteriaOption._all_mappers  s     ;;{{))>>	 ? ))88:;E 99Q< ((EB!jj==  > LL!8!8!:; %s   CC#!C#c                 X    UR                   R                  R                  SS 5      U L a  gg)Nfor_loader_criteriaFT)select_statementr   r   rN   compile_states     rO   _should_include$LoaderCriteriaOption._should_include  s3    **77;;%t 
 rg   c                     U R                   (       a&  U R                  R                  UR                  5      nOU R                  n[        R
                  " USU 0SS9$ )Nr  T)detect_subquery_cols)r  r  _resolve_with_argsr   r   _deep_annotate)rN   ext_infocrits      rO   _resolve_where_criteria,LoaderCriteriaOption._resolve_where_criteria  sP    ''&&99(//JD&&D&&($/d
 	
rg   c                 $    U R                  U5      $ rj   )process_compile_state)rN   r  mapper_entitiess      rO   'process_compile_state_replaced_entities<LoaderCriteriaOption.process_compile_state_replaced_entities  s     ))-88rg   c                     UR                   R                  (       a  [        R                  " S5        U R	                  UR
                  5        g)z7Apply a modification to a given :class:`.CompileState`.zThe with_loader_criteria() function may not work correctly with the legacy Query.with_polymorphic() feature.  Please migrate code to use the with_polymorphic() standalone function before using with_loader_criteria().N)compile_options_with_polymorphic_adapt_mapr   rI   get_global_criteriaglobal_attributesr  s     rO   r  *LoaderCriteriaOption.process_compile_state  s;     ((DDII@ 	  !@!@Arg   c                 ~    U R                  5        H)  nUR                  " SU4/ 5      nUR                  U 5        M+     g )Nadditional_entity_criteria)r  
setdefaultr|   )rN   r   rn  load_criterias       rO   r  (LoaderCriteriaOption.get_global_criteria  s?    ##%B&11-r2BM   & &rg   )r  r  r   r  r  r  r  N)FFTT)r\   r]   r^   r_   r`   r%   rx  dp_plain_objdp_has_cache_keyr}  r|  rz  _traverse_internalsr   rd   r  r  r  r  r  r  r  r  re   rf   rg   rO   r  r    s    	 
::GGH	855FFG	855FFG	H66AAB	!;!;!F!FG ! $T9l 
 
	
< 
9
B'rg   r  c                     U R                   $ rj   )r   r  s    rO   <lambda>r    s
    &2F2Frg   c                     U $ rj   rf   r  s    rO   r  r    s    rg   c                    [        U [        R                  5      (       aV  U(       a  [        R                  " S5      eU(       a  U R                  X#S9$ [        R                  " [        R                  XS9$ [        U UUUUS9$ )a  Produce 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.

.. seealso::

    :ref:`tutorial_orm_entity_aliases` - in the :ref:`unified_tutorial`

    :ref:`orm_queryguide_orm_aliases` - in the :ref:`queryguide_toplevel`

: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.subquery` or
 :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.  Not supported when creating aliases
 of :class:`_sql.Join` objects.

:param flat: Boolean, will be passed through to the
 :meth:`_expression.FromClause.alias` call so that aliases of
 :class:`_expression.Join` objects will alias the individual tables
 inside the join, rather than creating a subquery.  This is generally
 supported by all modern databases with regards to right-nested joins
 and generally produces more efficient queries.

: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   r   )r   r   r   r   )r8   r"   
FromClauser>   r?   r   r!   r   r$   AnonymizedFromClauseRoler   )elementr   r   r   r   s        rO   aliasedr    s    x ':0011&&=  ==d=66##..  )
 	
rg   c
           
         [        U 5      n
US;  a  U(       a  [        R                  " S5      eU	(       an  U	R                  U
L d   e[        R
                  " U5      n[        U	R                   Vs/ s H  oR                  PM     sn5      nX:X  a  U	$ UR                  U5      nU
R                  XUS9u  pU(       d  U(       a  UR                  US9n[        U UUUUUU(       + S9$ s  snf )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 aliased.   For a
    JOIN, this means the JOIN will be SELECTed from inside of a subquery
    unless the :paramref:`_orm.with_polymorphic.flat` flag is set to
    True, which is recommended for simpler use cases.

:param flat: Boolean, will be passed through to the
 :meth:`_expression.FromClause.alias` call so that aliases of
 :class:`_expression.Join` objects will alias the individual tables
 inside the join, rather than creating a subquery.  This is generally
 supported by all modern databases with regards to right-nested joins
 and generally produces more efficient queries.  Setting this flag is
 recommended as long as the resulting SQL is functional.

:param selectable: a table or subquery 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.

    When left at its default value of ``False``, the polymorphic
    selectable assigned to the base mapper is used for selecting rows.
    However, it may also be passed as ``None``, which will bypass the
    configured polymorphic selectable and instead construct an ad-hoc
    selectable for the target classes given; for joined table inheritance
    this will be a join that includes all target mappers and their
    subclasses.

: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

:param adapt_on_names: Passes through the
  :paramref:`_orm.aliased.adapt_on_names`
  parameter to the aliased object.  This may be useful in situations where
  the given selectable is not directly related to the existing mapped
  selectable.

  .. versionadded:: 1.4.33

rs   z[the 'flat' and 'selectable' arguments cannot be passed simultaneously to with_polymorphic())	innerjoinr  )r   r   r   r   r   )r   r>   r?   r   r   to_setr;   r   r   union_with_polymorphic_argsr   r   )r    classesr   r   r   r  r   r  r&  _existing_aliasprimary_mapperrn  new_classesmapperss                 rO   with_polymorphicr  ]  s    d &d+N&4""3
 	

 %%777++g&!0!I!IJ!I2YY!IJ
 !""mmK0G(??y @ G $5545@
%!('5("+m  Ks   0C'c                       \ rS rSrSrSr SrSrSrSr	\
R                  " 5       rS rS r\S 5       r\S 5       r\S	 5       rS
r S
r S rS r\S 5       rS rS rSrg
)Bundlei  a  A grouping of SQL expressions that are returned by a :class:`.Query`
under one namespace.

The :class:`.Bundle` essentially allows nesting of the tuple-based
results returned by a column-oriented :class:`_query.Query` object.
It also
is extensible via simple subclassing, where the primary capability
to override is that of how the set of expressions should be returned,
allowing post-processing as well as custom return types, without
involving ORM identity-mapped classes.

.. versionadded:: 0.9.0

.. seealso::

    :ref:`bundles`


FTc           
      |   U=U l         U l        U Vs/ s H&  n[        R                  " [        R
                  X@S9PM(     sn=U l        n[        S U Vs/ s H  oUR                  R                  SU5      PM      sn 5       5      =U l
        U l        UR                  SU R                  5      U l        gs  snf s  snf )a  Construct a new :class:`.Bundle`.

e.g.::

    bn = Bundle("mybundle", MyClass.x, MyClass.y)

    for row in session.query(bn).filter(
            bn.c.x == 5).filter(bn.c.y == 4):
        print(row.mybundle.x, row.mybundle.y)

:param name: name of the bundle.
:param \*exprs: columns or SQL expressions comprising the bundle.
:param single_entity=False: if True, rows for this :class:`.Bundle`
 can be returned as a "single entity" outside of any enclosing tuple
 in the same manner as a mapped entity.

)apply_propagate_attrsc              3   T   #    U  H  n[        US UR                  5      U4v   M      g7f)ro   N)r  _label)rm  r   s     rO   ro  "Bundle.__init__.<locals>.<genexpr>  s)      1
G S%,c2Gs   &(bundlesingle_entityN)r   r  r!   r   r$   ColumnsClauseRoleexprsr'   r   r   rZ   columnsr   r  )rN   r   r  rh  expres         rO   r   Bundle.__init__  s    $ #'&	DK
 	
  '' 	
 	

U !1 1
AFGA**8Q7G1
 !
 	
  VVOT5G5GH
 Hs   -B4%B9
c           
          U R                   U R                  U R                  4[        U R                   Vs/ s H  o3R                  X5      PM     sn5      -   $ s  snf rj   )	__class__r   r  tupler  _gen_cache_key)rN   anon_map
bindparamsr  s       rO   r  Bundle._gen_cache_key  sN    		4+=+=>CG::N:4  6:NB
 
 	
Ns   A
c                 T    U R                   S   R                  R                  SS 5      $ )Nr   r   r  r   r   r  s    rO   r   Bundle.mapper  #    zz!}))--ndCCrg   c                 T    U R                   S   R                  R                  SS 5      $ )Nr   r6  r  r  s    rO   r   Bundle.entity#  r  rg   c                     U R                   $ rj   )rZ   r  s    rO   r7  Bundle.entity_namespace'  s    vvrg   Nc                     U R                   R                  U R                   5      nUR                  R                  U R                  5        U$ rj   )r  rH   r
  rC   )rN   cloneds     rO   _cloneBundle._cloneG  s5    ''7t}}-rg   c           	         X S.nUR                  U R                  5        U R                  S   R                  R	                  SU R
                  5      n[        R                  " U R                   Vs/ s H  o3R                  R	                  SU5      PM      sn[        R                  SS.6R                  U5      R                  SUS.5      $ s  snf )	N)r  r7  r   r;  r  F)_literal_as_text_rolegroupr8  r9  )rC   r   r  _propagate_attrsr   r   r"   
ClauseListr$   r  r<  r=  )rN   annotationsr;  r  s       rO   r>  Bundle.__clause_element__L  s    !%@4,,-A77;;dkk
 !! <@::F:a..$$Xq1:F ',&=&=
 Y{#!! -2&4	
 Gs   1%Cc                 6    U R                  5       R                  $ rj   )r>  clausesr  s    rO   r  Bundle.clausese  s    &&(000rg   c                 2    U R                  5       nXl        U$ )z<Provide a copy of this :class:`.Bundle` passing a new label.)r  r   )rN   r   r  s      rO   r   Bundle.labeli  s     rg   c                 Z   ^^ [        X3 Vs/ s H  nSPM     sn5      mUU4S jnU$ s  snf )zProduce the "row processing" function for this :class:`.Bundle`.

May be overridden by subclasses.

.. seealso::

    :ref:`bundles` - includes an example of subclassing.

rf   c                 J   > T" T Vs/ s H
  o" U 5      PM     sn5      $ s  snf rj   rf   )r   prockeyed_tupleprocss     rO   r  )Bundle.create_row_processor.<locals>.proc|  s$    e<edS	e<==<s    r   )rN   queryr  labelslr  r  s     `   @rO   create_row_processorBundle.create_row_processorp  s2     #6+?1B+?@	>  ,@s   (
)r  rZ   r  r  r   r  )r\   r]   r^   r_   r`   r  is_clause_element	is_mapperr   	is_bundler   immutabledictr  r   r  r  r   r   r7  r  rZ   r  r>  r  r   r#  re   rf   rg   rO   r  r    s    ( M< II))+I@

 D D D D   G0 	A/

2 1 1rg   r  c                 6    [         R                  " U SS0U5      $ )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   r  )r  excludes     rO   _orm_annotater,    s     ""7\4,@'JJrg   c                 ,    [         R                  " U SS9$ )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.

)r*  r6  )rL   r   _deep_deannotater  s    rO   _orm_deannotater1    s     $$6 rg   c                 .    [         R                  " U 5      $ rj   r.  r0  s    rO   _orm_full_deannotater3    s    $$W--rg   c                       \ rS rSrSr\R                  R                  rSr      S
S jr	S r
    SS jrSS jrS	rg)_ORMJoini  z/Extend Join to support ORM constructs as input.TNc	           	      :   [         R                  " U5      n	[         R                  " U5      n
U
R                  nX`l        Xpl        [        USU	5      nXl        [        U[        R                  5      (       a  [        UR                  U5      n[        U[        R                  5      (       a5  UR                  R                  5       nUR                  nXR                   -  nO0[        U["        5      (       a  UnUR$                  R                  nOS nU	R                  nU(       a  [&        R(                  " WU5      (       a  UnOUnUR+                  UUSU
SUS9u  nnnnnnUb>  U(       a  [,        R.                  " UUU5      nUnO[,        R.                  " UUUU5      nUnOUnUU l        U	R2                  (       a  UR4                  R7                  SS 5      nO'U	R8                  (       d  U	R:                  (       a  U	nOS nUb"  U R4                  R=                  SU05      U l        [?        U5      =(       a    U(       + n[@        RB                  RE                  XX#XE5        U(       a&  U =RF                  [,        RH                  " U6 -  sl#        U(       d  [        U
SS 5      (       aw  U
RJ                  RL                  (       a[  U
RJ                  RN                  nUbA  U
R:                  (       a  U
RP                  RS                  U5      nU RF                  U-  U l#        g g g g g )N_joined_from_infoT)source_selectabledest_selectablesource_polymorphicof_type_entityalias_secondaryextra_criteriar6  r   )*r   r   r   
_left_memo_right_memor  r7  r8   r   r9   r   r   QueryableAttribute
comparator_source_selectabler  _extra_criteriar   parentr   clause_is_present_create_joinsr   r@   _target_adapteris_selectabler   r   r&  r   r  boolr"   Joinr   rZ  and_r   single_single_table_criterionr.  rP  )rN   leftrightrZ  isouterfullr>  r?  rC  	left_info
right_infoadapt_toleft_orm_infoon_selectablepropleft_selectable
adapt_frompjsjsourcedest	secondarytarget_adapterr6  augment_onclausesingle_crits                             rO   r   _ORMJoin.__init__  s    &&t,	''.
(( %&  &99E!+h 1 122}33X>H h
 = =>>$//BBDM$$D777O.11D KK22MD#..))-II*
,
 """, (#') $. #  ~HHYr:E!H88D)RAD!H#1D  ""*77;;L   I$>$>$LL# $ 1 1 7 7.!D  0=X  UgLMMSXX77M 
Hd33!!((
 %++CCK&..","5"5">">{"KK $ ; ' ) 4 rg   c           	         Un[        U[        R                  5      (       a-  UR                  n[        U[        R                  5      (       a  M-  U R                  UL d   e[        U R                  UR                  U R                  U R                  U R                  UR                  S9n[        UUR                  UR                  UR                  UR                  S9$ )z\Splice a join into the center.

Given join(a, b) and join(b, c), return join(a, b).join(c)

)rP  r>  r?  )rP  r?  )
r8   r   rJ  rN  rO  r5  rZ  rP  r>  r?  )rN   otherleftmostrN  s       rO   _splice_into_center_ORMJoin._splice_into_center  s     388,,}}H 388,, zzX%%%IIJJMMLL((
 KKNNMM))
 	
rg   c                     [        XX$US9$ )N)rQ  rP  r5  )rN   rO  rZ  rP  rQ  join_to_lefts         rO   r@   _ORMJoin.join3  s     X'JJrg   c                     [        XUSUS9$ )NT)rP  rQ  ri  )rN   rO  rZ  rQ  rj  s        rO   	outerjoin_ORMJoin.outerjoin=  s    Xt$GGrg   )r   r7  r>  r?  rG  rZ  )NFFNNrf   NFFNNFN)r\   r]   r^   r_   r`   r"   rJ  __visit_name__inherit_cacher   rf  r@   rm  re   rf   rg   rO   r5  r5    sT    9__33NM o<b
@ KHrg   r5  c                     [        XX#U5      $ )aV  Produce an inner join between left and right clauses.

:func:`_orm.join` is an extension to the core join interface
provided by :func:`_expression.join()`, where the
left and right selectables may be not only core selectable
objects such as :class:`_schema.Table`, but also mapped classes or
:class:`.AliasedClass` instances.   The "on" clause can
be a SQL expression or an ORM mapped attribute
referencing a configured :func:`_orm.relationship`.

.. deprecated:: 1.4 using a string relationship name for the "onclause"
   is deprecated and will be removed in 2.0; the onclause may be only
   an ORM-mapped relationship attribute or a SQL expression construct.

:func:`_orm.join` is not commonly needed in modern usage,
as its functionality is encapsulated within that of the
:meth:`_sql.Select.join` and :meth:`_query.Query.join`
methods. which feature a
significant amount of automation beyond :func:`_orm.join`
by itself.  Explicit use of :func:`_orm.join`
with ORM-enabled SELECT statements involves use of the
:meth:`_sql.Select.select_from` method, as in::

    from sqlalchemy.orm import join
    stmt = select(User).\
        select_from(join(User, Address, User.addresses)).\
        filter(Address.email_address=='foo@bar.com')

In modern SQLAlchemy the above join can be written more
succinctly as::

    stmt = select(User).\
            join(User.addresses).\
            filter(Address.email_address=='foo@bar.com')

.. warning:: using :func:`_orm.join` directly may not work properly
   with modern ORM options such as :func:`_orm.with_loader_criteria`.
   It is strongly recommended to use the idiomatic join patterns
   provided by methods such as :meth:`.Select.join` and
   :meth:`.Select.join_from` when creating ORM joins.

.. seealso::

    :ref:`orm_queryguide_joins` - in the :ref:`queryguide_toplevel` for
    background on idiomatic ORM join patterns

ri  )rN  rO  rZ  rP  rQ  rj  s         rO   r@   r@   A  s    d DD99rg   c                     [        XUSU5      $ )zProduce a left outer join between left and right clauses.

This is the "outer join" version of the :func:`_orm.join` function,
featuring the same behavior except that an OUTER JOIN is generated.
See that function's documentation for other usage details.

Tri  )rN  rO  rZ  rQ  rj  s        rO   rm  rm  v  s     D466rg   c                 r   [        U[        R                  5      (       aB  [        R                  " S5        [	        U 5      n[        UR                  U5      R                  nOH[        U[        R                  5      (       a)  UR                  (       a  UR                  nUR                  nUR                  XS9$ )a<  Create filtering criterion that relates this query's primary entity
to the given related instance, using established
:func:`_orm.relationship()`
configuration.

E.g.::

    stmt = select(Address).where(with_parent(some_user, User.addresses))


The SQL rendered is the same as that rendered when a lazy loader
would fire off from the given parent on that attribute, meaning
that the appropriate state is taken from the parent object in
Python without the need to render joins to the parent table
in the rendered statement.

The given property may also make use of :meth:`_orm.PropComparator.of_type`
to indicate the left side of the criteria::


    a1 = aliased(Address)
    a2 = aliased(Address)
    stmt = select(a1, a2).where(
        with_parent(u1, User.addresses.of_type(a2))
    )

The above use is equivalent to using the
:func:`_orm.with_parent.from_entity` argument::

    a1 = aliased(Address)
    a2 = aliased(Address)
    stmt = select(a1, a2).where(
        with_parent(u1, User.addresses, from_entity=a2)
    )

:param instance:
  An instance which has some :func:`_orm.relationship`.

:param property:
  String property name, or class-bound attribute, which indicates
  what relationship from the instance should be used to reconcile the
  parent/child relationship.

  .. deprecated:: 1.4 Using strings is deprecated and will be removed
     in SQLAlchemy 2.0.  Please use the class-bound attribute directly.

:param from_entity:
  Entity in which to consider as the left side.  This defaults to the
  "zero" entity of the :class:`_query.Query` itself.

  .. versionadded:: 1.2

zUsing strings to indicate relationship names in the ORM with_parent() function is deprecated and will be removed SQLAlchemy 2.0.  Please use the class-bound attribute directly.)from_entity)r8   r   r9   warn_deprecated_20r   r  r   r  r   r@  _of_type_with_parent)r   rW  rv  r   s       rO   with_parentrz    s    l $))**N	

 x(v}}d+44	D*77	8	8==--K}}X??rg   c                 F    [         R                  " U 5      nUR                  $ )zReturn True if the given object has a database
identity.

This typically corresponds to the object being
in either the persistent or detached state.

.. seealso::

    :func:`.was_deleted`

)r   instance_statehas_identityobject_rm   s     rO   r}  r}    s      %%g.Erg   c                 F    [         R                  " U 5      nUR                  $ )zReturn True if the given object was deleted
within a session flush.

This is regardless of whether or not the object is
persistent or detached.

.. seealso::

    :attr:`.InstanceState.was_deleted`

)r   r|  was_deletedr~  s     rO   r  r    s      %%g.Erg   c                    UR                   (       a4  U R                   (       a"  UR                  5       U R                  5       L a  ggU R                   (       a"  U R                  (       a  XR                  ;   $ XL $ UR	                  U 5      $ )zdetermine if 'given' corresponds to 'entity', in terms
of an entity passed to Query that would match the same entity
being referred to elsewhere in the query.

TF)r   r+  r&  r   common_parentgivenr   s     rO   _entity_corresponds_tor    sp     !!!!#u'8'8'::			!!;;;;?"&&rg   c                 D   U R                   (       aC  UR                   =(       a0    UR                  (       + =(       a    XL =(       d    XR                  ;   $ UR                   (       d  U R                  UR                  5      $ UR                  =(       a    XR
                  ;   $ )aO  determine if 'given' corresponds to 'entity', in terms
of a path of loader options where a mapped attribute is taken to
be a member of a parent entity.

e.g.::

    someoption(A).someoption(A.b)  # -> 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


)r   r&  r   r  r   r   r  s     rO   $_entity_corresponds_to_use_path_implr    s    ( ## P+++PNE-N-N$N	

 $$""6==11 ## 9888	
rg   c                     U R                   (       a0  XR                  ;   =(       d    U R                  R                  U5      $ U R                  (       a  XR                  ;   $ U R                  U5      $ )z]determine if 'given' "is a" mapper, in terms of the given
would load rows of type 'mapper'.

)r   r   r   r   )r  r   s     rO   _entity_isar    s`    
 777 
5<<;K;K<
 	
 
	'	'7777yy  rg   c                  z    SSK Jn JnJnJn  SSKJn  SSKJn  U=Ul	        =U l	        =Ul	        =Ul	        Ul	        g)a  Use 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   )
unitofworksessionr   
dependency)topological)	RandomSetN)
sqlalchemy.ormr  r  r   r  sqlalchemy.utilr  sqlalchemy.testing.utilr  r;   )r  r  r   r  r  r  s         rO   randomize_unitofworkr  .  sA    6 GF+1 5>>KO >>>j:>rg   c                 :  ^ U4S jn[        U[        5      (       a  [        R                  " U5      u  pEn[        U[        5      (       a  [        U[        5      (       a
  XT-
  S::  a  / $ [        U[        5      (       a  US:  d  [        U[        5      (       a  US:  a  U" 5         [        U 5      U   $ U R                  XE5      nUb  [        U5      SSUR                  2   $ [        U5      $ US:X  a  U" 5         [        U 5      S   $ [        XUS-    5      S   $ )z\calculate __getitem__ in terms of an iterable query object
that also has a slice() method.

c                  V   > T (       d  [        S5      e[        R                  " S5        g )Nz@negative indexes are not accepted by SQL index / slice operatorszSupport for negative indexes for SQL index / slice operators will be removed in 2.0; these operators fetch the complete result and do not work efficiently.)
IndexErrorr   rw  )allow_negatives   rO   _no_negative_indexes&_getitem.<locals>._no_negative_indexesX  s-    * 
 ##/rg   r   Nr   )r8   slicer   decode_sliceintr  step)iterable_queryitemr  r  startstopr  ress     `     rO   _getitemr  R  s    $ --d3T tS!!5#&&!I$$tS!!dQh "'--""5/9TD49945592: "'++dQh78;;rg   )p_unionT)NNFF)FFNFFFFNrj   ro  rp  )PrW   r   r  rV   r   r    r   r   r   r   r	   r
   r   r   r   r   r   r   
interfacesr   r   r   r   r   r   path_registryr   r   r   r>   r   r   r   engine.resultr   sql_baser!   r"   r#   r$   r   r%   sql.annotationr&   sql.baser'   rG   ra   r1   r   r   r   r   r   r  r   MemoizedHasCacheKeyr   r  r  	_inspectsr  r  _self_inspectsr  r,  r1  r3  rJ  r5  r@   rm  rz  r}  r  r  r  r  r  r  rf   rg   rO   <module>r     s   
    "          % !  & & , 2 ) & '      ( "     "  5 ' 	?Y ?D?DF =AO3de;P%P'' %PPx'6 x'vh<  	h<V	*f *8}'> }'@
   \ "#F G 
  [ !"7 8n
h 	qh m  	m m`K.`Hz `HH IM2:j7C@L "'( 
F!!>H.<rg   