
    hlE                   "
   d dl mZ d dlZd dlZd dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dlm
Z
 d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlZddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddlm!Z! ddlm"Z" ddl#m$Z$ ddl#m%Z% ddl#m&Z& ddl#m'Z' dd l#m(Z( dd!l#m)Z) dd"l#m*Z* dd#l#m+Z+ dd$l#m,Z, dd%l#m-Z- dd&l#m.Z. dd'l#m/Z/ dd(l#m0Z0 dd)l#m1Z1 dd*l#m2Z2 dd+l#m3Z3 dd,l#m4Z4 dd-l#m5Z5 dd.l#m6Z6 dd/l7m8Z8 dd0l7m9Z9 dd1l7m:Z: dd2l7m;Z; dd3l7m<Z< dd4l=m>Z> d5d6lm?Z? d5dlmZ@ d5d7lmAZA d5d8lmBZB d5d9lmCZC d5d:lDmEZE d5d;lBmFZF d5d<lBmGZG d5d=lBmHZH d5d>lBmIZI d5d9lBmCZJ d5d?lBmKZK d5d@lLmMZM d5dAlNmOZO d5dBlPmQZQ d5dClRmSZS d5dDlRmTZT d5dElUmVZV d5dFlUmWZW d5dGlXmYZY d5dHlZm[Z[ d5dIl\m]Z^ d5dJl\m_Z` d5dKl\maZa d5dLl\mbZb d5dMl\mcZc d5dNl\mdZd d5dOl\meZe ej,                  rddPlmfZf ddQlmgZg ddRlmhZh ddSlmiZi ddTljmkZk ddUljmlZl ddVlmmnZn ddWl=moZo ddXlpmqZq ddYlrmsZs d5dZltmuZu d5d[ltmvZv d5d\lLmwZw d5d]lLmxZx d5d^lLmyZy d5d_lLmzZz d5d`lLm{Z{ d5dalLm|Z| d5dblNm}Z} d5dclPm~Z~ d5ddlUmZ d5delXmZ d5dflXmZ d5dglXmZ d5dhlmZ d5dil\mZ  edjek      Z edl      Z ej                  ej                   eCj                  e.e6e+dm      n      Z G do dpee      Z e
e ee^            Z] G dq dree      Z e
e ee`            Z_ G ds dtee         Zdu Z	 ddvZ	 	 dddddw	 	 	 	 	 	 	 	 	 	 	 ddxZ G dy dzej&                        Z G d{ d|eJj*                        Z G d} d~eJj*                        Z G d deAj0                  d   e:e         ZeAj4                   G d de;e   e<eSe,e[eAj0                  d   ee   	             Z G d d      Z G d de8      Z  eAj<                  e      d         eAj<                  e      	 	 	 	 dd       Z eee         Z eAj<                  e      	 	 	 	 dd       ZeAj4                   G d de:e   eOeTeAj0                  d   e,             ZdddZddZddZ G d deGjN                        Z	 d	 	 	 	 	 	 	 ddZddZddZ	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZddZddZ	 	 	 	 	 	 	 	 ddZ G d de      Z	 	 	 	 	 	 ddZ	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZy)    )annotationsN)AbstractSet)Any)Callable)cast)Dict)	FrozenSet)Generic)Iterable)Iterator)List)Match)Optional)Sequence)Tuple)Type)TYPE_CHECKING)TypeVar)Union   )
attributes)exc)_O)insp_is_aliased_class)insp_is_mapper)prop_is_relationship)_class_to_mapper)_MappedAnnotationBase)
_never_set)_none_only_set)	_none_set)attribute_str)class_mapper)DynamicMapped)InspectionAttr)instance_str)Mapped)object_mapper)object_state)opt_manager_of_class)ORMDescriptor)state_attribute_str)state_class_str)	state_str)WriteOnlyMapped)CriteriaOption)MapperProperty)ORMColumnsClauseRole)ORMEntityColumnsClauseRole)ORMFromClauseRole)PathRegistry   )event)
inspection)sql)utilresult_tuple)	coercions)
expression)lambdas)roles)visitors)is_selectable)SupportsCloneAnnotations)ColumnCollection)HasCacheKey)MemoizedHasCacheKey)ColumnElement)KeyedColumnElement)
FromClause)MemoizedSlots)de_stringify_annotation)eval_name_only)fixup_container_fwd_refs)
get_origin)is_origin_of_cls)Literal)Protocol)_EntityType)_IdentityKeyType)_InternalEntityType)_ORMCOLEXPR)_MapperEntity)ORMCompileState)Mapper)AbstractEntityRegistry)Query)RelationshipProperty)Row)
RowMapping)_CE)_ColumnExpressionArgument)_EquivalentColumnMap)_FromClauseArgument)_OnClauseArgument)_PropagateAttrsType)_SA)ReadOnlyColumnCollection)BindParameter)_ColumnsClauseElement)Select)
Selectable)anon_map)_AnnotationScanType_T)bound)deletedelete-orphanallmergeexpungesave-updaterefresh-expirenone)r'   r/   r$   )locals_c                  2    e Zd Zddd	 	 	 	 	 	 	 	 	 	 	 ddZy)_DeStringifyAnnotationNF)str_cleanup_fninclude_genericc                    y N )selfcls
annotationoriginating_modulery   rz   s         <D:\EasyAligner\venv\Lib\site-packages\sqlalchemy/orm/util.py__call__z_DeStringifyAnnotation.__call__   s         )r   	Type[Any]r   rk   r   strry   z#Optional[Callable[[str, str], str]]rz   boolreturnr   __name__
__module____qualname__r   r}   r   r   rx   rx      sJ     ?C % (  	 <  
r   rx   c                      e Zd ZddZy)_EvalNameOnlyc                     y r|   r}   )r~   namemodule_names      r   r   z_EvalNameOnly.__call__   s    Cr   N)r   r   r   r   r   r   r   r}   r   r   r   r      s    ?r   r   c                       e Zd ZU dZej                  g d      ZeZg dZdZ	de
d<   de
d<   de
d<   de
d	<   de
d
<   de
d<   	 	 	 	 d fdZd Zed        Z xZS )CascadeOptionszHKeeps track of the options sent to
    :paramref:`.relationship.cascade`)rp   ru   ro   )rr   rp   ru   rt   rq   )save_updatern   refresh_expirerq   rr   delete_orphanr   r   rn   r   rq   rr   r   c                   t        |t              s|| j                  |      S t        |      }|j	                  | j
                        r`t        j                  ddj                  t        |j	                  | j
                              D cg c]  }t        |       c}      z        d|v r|j                  | j                         d|v r|j                          |j                  d       t        | A  | |      }d|v |_        d|v |_        d|v |_        d|v |_        d	|v |_        d
|v |_        |j,                  r!|j$                  st/        j0                  d       |S c c}w )NzInvalid cascade option(s): %s, rp   ru   rs   rn   rt   rq   rr   ro   z5The 'delete-orphan' cascade option requires 'delete'.)
isinstancer   from_stringset
difference_allowed_cascadessa_excArgumentErrorjoinsortedreprupdate_add_w_all_cascadescleardiscardsuper__new__r   rn   r   rq   rr   r   r:   warn)r   
value_listvaluesxr~   	__class__s        r   r   zCascadeOptions.__new__   s^    j#&**<??:..ZS223&&/)) "("--c.C.CD""A Q"
 
 F?MM#112VLLNuwsF+(F2&(.&8&
 F*,6dkkIIMN3s   E$c                b    ddj                  t        |       D cg c]  }| c}      z  S c c}w )NzCascadeOptions(%r),)r   r   )r~   r   s     r   __repr__zCascadeOptions.__repr__   s,    #sxxF4L0ILqL0I'JKK0Is   	,
c                p    t        j                  d|xs d      D cg c]  }|s|	 }} | |      S c c}w )Nz\s*,\s* )resplit)r   argcr   s       r   r   zCascadeOptions.from_string   s9    XXj#)<B<!<B6{ Cs   33)r   z#Optional[Union[Iterable[str], str]]r   r   )r   r   r   __doc__all_cascadesr   r   r   _viewonly_cascades	__slots____annotations__r   r   classmethodr   __classcell__r   s   @r   r   r      s    ) '11( %NI LKM#<#	#JL  r   r   c                d  	 sfd	|r!	fd}	fd}	fd}	fd}n	fd}	fd}	fd}t        j                  | d	|d
d
       t        j                  | d|d
       t        j                  | d|d
d
       |rt        j                  | dd
d
       yy)zNRuns a validation method on an attribute value to be set or
    appended.
    c                R    | j                      j                  }|j                  |uS r|   )managerimpl)state	initiatorr   keys      r   detect_is_backrefz,_validator_events.<locals>.detect_is_backref  s&    ==%**D>>--r   c                    |j                   t        j                  ur$s	 | |      s | j                         |d      S |S NFopr   OP_BULK_REPLACEobjr   valuer   r   include_backrefsr   	validators      r   appendz!_validator_events.<locals>.append	  s>    ||:#=#== (9%(K c5%@@r   c           	         s	 | |      s-| j                         }|D cg c]  } ||d       c}|d d  y y c c}w r   r   	r   r   r   r   r   r   r   r   r   s	        r   bulk_setz#_validator_events.<locals>.bulk_set  sN    '8	'JiikCICI%Ic3u56q	 (Ks   ;c                P    s	 | |      s | j                         |d      S |S r   r   r   r   oldvaluer   r   r   r   r   s       r   set_z_validator_events.<locals>.set_  s,    '8	'J c5%@@r   c                P    s	 | |      s | j                         |d       y y )NTr   r   s      r   removez!_validator_events.<locals>.remove  s*    '8	'J%))+sE48 (Kr   c                    |j                   t        j                  ur#s	 | |      s | j                         |      S |S r|   r   r   s      r   r   z!_validator_events.<locals>.append$  s<    ||:#=#== (9%(K c599r   c                ~    s	 | |      s,| j                         }|D cg c]  } ||       c}|d d  y y c c}w r|   r   r   s	        r   r   z#_validator_events.<locals>.bulk_set,  sE    '8	'JiikEKLVEYsC7VLq	 (KLs   :c                N    s	 | |      s | j                         |      S |S r|   r   r   s       r   r   z_validator_events.<locals>.set_1  s*    '8	'J c599r   r   T)rawretvalbulk_replace)r   r   r   N)r7   listen)
descr   r   include_removesr   r   r   r   r   r   s
    `` `    @r   _validator_eventsr      s    
 	. 				9 	9		M
	 
LLxT$?	LL~xT:	LLudT:T8VdC r   c                   t        j                         }i i | D ]  }| |   }t        j                  t        j
                  |d      }|| |<   i }|j                  D ]p  }|j                  |k(  rt        j                  d|d|d      |j                  |j                         |||j                  <   |j                  |j                  <   r ||<    fd}	g }
| j                         D ]  \  }}||
j                  t        j                  |D cg c]  } |	||       c}t        j                   t#        j$                  |            j'                  |      gz    j)                  |             |
j                  t        j                  |D cg c]  } |	||       c} j)                  |              t        j*                  |
 j-                  |      S c c}w c c}w )a0  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                $   	 |   |    S # t         $ r{ r<t        j                  t        j                         |          j	                  |       cY S t        j
                  t        j                         |          j	                  |       cY S w xY wr|   )KeyErrorr9   r   nulllabeltype_coerce)r   table
cast_nullscolnamemapstypess     r   colzpolymorphic_union.<locals>.colo  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@   StrictFromClauseRoler   r   r   InvalidRequestErroraddtypeitemsr   r9   selectliteral_columnsql_util_quote_ddl_exprr   select_from	union_allalias)	table_maptypecolname	aliasnamer   colnamesr   r   mr   r   resulttype_r   r   r   s      `         @@r   polymorphic_unionr  >  s   , &*__%6HKE#  &&D
 	#Auu#00 #A'  LLAaeeH66E!%%L  E- 0L F!)u"MM

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

3;<84c$&8<+e$ *( ==&!''	22 @ =s   G!G&)instancerowidentity_tokenc               8   | ft        |       }|F|t        j                  d      |j                  t	        t        j                  |            |      S |j                  ||      S |t        |      }|j                  |      S t        j                  d      )a5  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` or :class:`.RowMapping` 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

    zident or row is required)r
  zclass or instance is required)
r#   r   r   identity_key_from_primary_keytupler:   to_listidentity_key_from_rowr(   identity_key_from_instance)class_identr  r	  r
  mappers         r   identity_keyr    s    J f%;}**+EFF77dll5)*> 8   //N 0   
	x(00::""#BCCr   c                     e Zd ZdZ ej
                         Z ej
                         Z ej
                         Z ej
                         Z	 ej
                         Z
 ej
                         Z ej
                         Z ej
                         Z ej
                         Z ej
                         Z ej
                         Zy)_TraceAdaptRolea  Enumeration of all the use cases for ORMAdapter.

    ORMAdapter remains one of the most complicated aspects of the ORM, as it is
    used for in-place adaption of column expressions to be applied to a SELECT,
    replacing :class:`.Table` and other objects that are mapped to classes with
    aliases of those tables in the case of joined eager loading, or in the case
    of polymorphic loading as used with concrete mappings or other custom "with
    polymorphic" parameters, with whole user-defined subqueries. The
    enumerations provide an overview of all the use cases used by ORMAdapter, a
    layer of formality as to the introduction of new ORMAdapter use cases (of
    which none are anticipated), as well as a means to trace the origins of a
    particular ORMAdapter within runtime debugging.

    SQLAlchemy 2.0 has greatly scaled back ORM features which relied heavily on
    open-ended statement adaption, including the ``Query.with_polymorphic()``
    method and the ``Query.select_from_entity()`` methods, favoring
    user-explicit aliasing schemes using the ``aliased()`` and
    ``with_polymorphic()`` standalone constructs; these still use adaption,
    however the adaption is applied in a narrower scope.

    N)r   r   r   r   enumautoALIASED_INSPJOINEDLOAD_USER_DEFINED_ALIAS JOINEDLOAD_PATH_WITH_POLYMORPHICJOINEDLOAD_MEMOIZED_ADAPTERMAPPER_POLYMORPHIC_ADAPTERWITH_POLYMORPHIC_ADAPTER#WITH_POLYMORPHIC_ADAPTER_RIGHT_JOIN DEPRECATED_JOIN_ADAPT_RIGHT_SIDEADAPT_FROM_STATEMENTCOMPOUND_EAGER_STATEMENTLEGACY_SELECT_FROM_ALIASr}   r   r   r  r    s    0 499;L %.DIIK!'0tyy{$"+$))+ "+(tyy{*3$))+''0tyy{$
 %499;  )tyy{  )tyy{r   r  c                  V     e Zd ZdZdZddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZ xZS )	ORMStatementAdapterz.ColumnAdapter which includes a role attribute.)roleNFTequivalentsadapt_requiredallow_label_resolveanonymize_labelsadapt_on_namesadapt_from_selectablesc          	     @    || _         t        	| 	  |||||||       y )Nr'  )r&  r   __init__)
r~   r&  
selectabler(  r)  r*  r+  r,  r-  r   s
            r   r/  zORMStatementAdapter.__init__)  s3     	#) 3-)#9 	 	
r   )r&  r  r0  ri   r(  Optional[_EquivalentColumnMap]r)  r   r*  r   r+  r   r,  r   r-  !Optional[AbstractSet[FromClause]])r   r   r   r   r   r/  r   r   s   @r   r%  r%  $  sx    8I 7;$$(!&$DH

 

 4
 
 "
 
 
 !B
 
r   r%  c            	      ~     e Zd ZU dZdZded<   ded<   ddd	ddd	ddd
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZd Z xZS )
ORMAdapterzaColumnAdapter subclass which excludes adaptation of entities from
    non-matching mappers.

    )r&  r  is_aliased_classaliased_inspr   r5  Optional[AliasedInsp[Any]]r6  NFT)r(  r)  r*  r+  r0  limit_on_entityr,  r-  c          
         || _         |j                  | _        ||j                  }t        |      rd| _        || _        nd| _        d | _        t        |   ||||||r| j                  nd |	|
       y )NTF)r)  r*  r+  
include_fnr,  r-  )	r&  r  r0  r   r5  r6  r   r/  _include_fn)r~   r&  entityr(  r)  r*  r+  r0  r8  r,  r-  r   s              r   r/  zORMAdapter.__init__L  s     	mm**J ($(D! &D$)D! $D) 3-+:t'')#9 	 		
r   c                    |j                   j                  dd       }| xs8 |j                  | j                        xs | j                  j                  |      S )Nparentmapper)_annotationsgetisar  )r~   elemr<  s      r   r;  zORMAdapter._include_fnp  sF    ""&&~t<zOVZZ4O8OOr   )r&  r  r<  _InternalEntityType[Any]r(  r1  r)  r   r*  r   r+  r   r0  zOptional[Selectable]r8  r   r,  r   r-  r2  )	r   r   r   r   r   r   r/  r;  r   r   s   @r   r4  r4  A  s    
 GI,, 7;$$(!&+/ $$DH"
"
 )"

 4"
 "
 ""
 "
 )"
 "
 "
 !B"
HPr   r4  c                      e Zd ZU dZded<   	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZe	 	 	 	 dd       ZddZ	 	 	 	 	 	 	 	 ddZ	dd	Z
dd
Zy)AliasedClassa  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`


    r   r   Nc                   t        dt        j                  |            }|j                  }d}|[|j                  r1|j
                  j                  r|j
                  j                         }n,|j                  j                  ||      }n|j                  rd}|J t        | ||||r|n|j                  ||n|j                  ||	||
|      | _        d|j                  j                   d| _        y )N_InternalEntityType[_O]Fr   flatTaliased())r   r8   inspectr  r5  r0  _is_subqueryr   _with_polymorphic_selectable_anonymous_fromclauseAliasedInspwith_polymorphic_mapperspolymorphic_on_aliased_inspr  r   )r~   mapped_class_or_acr   r   rI  r,  rQ  with_polymorphic_discriminator
base_aliasuse_mapper_pathrepresents_outer_joininspr  nest_adapterss                 r   r/  zAliasedClass.__init__  s    %z'9'9:L'M
 =$$)E)E--/ 77MM!! N   "" M   ( , )44 2= /**!'
, #6==#9#9":!<r   c                8   | j                  |       }d|j                  j                  j                   d|_        ||_        |j
                  rL|j                  D ]=  }||ust        j                  |      }t        ||j                  j                  |       ? |S )NrJ  rK  )
r   r  r  r   rS  _is_with_polymorphic_with_polymorphic_entitiesrE  _reconstitute_from_aliased_inspsetattr)r   r6  r   sub_aliased_inspents        r   r^  z,AliasedClass._reconstitute_from_aliased_insp  s     kk#!,"5"5"<"<"E"E!FaH(,,$0$K$K #<7&FF(C C!1!8!8!A!A3G %L 
r   c                   	 | j                   d   }|j                  }t        ||      }t        |d      r,t        |d      r t        j                  |j                  |       S t        |d      r|j                  d |       }t        |d      r|j                  |      }t        | ||       |S # t        $ r t	               w xY w)NrS  r   __self____get__adapt_to_entity)__dict___targetgetattrr   AttributeErrorhasattrr   
MethodType__func__rd  re  r_  )r~   r   rS  targetattrs        r   __getattr__zAliasedClass.__getattr__  s    	( MM/:M #**F63'D
 4$z)B##DMM488 4#<<d+D 4*+''6DD#t$1  	# ""	#s   B+ +B?c                R   t        ||      }t        |d      r,t        |d      r t        j                  |j                  |       S t        |d      r|j                  d |       }t        |d      r8t        j                  |       |_        |j                  |      }t        | ||       |S )Nr   rc  rd  re  )rh  rj  r   rk  rl  rd  weakrefref_weak_entityre  r_  )r~   r   mapped_classr6  rn  s        r   _get_from_serializedz!AliasedClass._get_from_serialized  s    
 |S)4$z)B##DMM488 4#<<d+D 4*+(/D(9L%''5DD#t$r   c                ^    dt        |       | j                  j                  j                  fz  S )Nz<AliasedClass at 0x%x; %s>)idrS  rg  r   r~   s    r   r   zAliasedClass.__repr__6  s0    +tH&&///
 
 	
r   c                ,    t        | j                        S r|   )r   rS  rx  s    r   __str__zAliasedClass.__str__<  s    4%%&&r   )	NNFFNNNFF)rT  z_EntityType[_O]r   Optional[FromClause]r   Optional[str]rI  r   r,  r   rQ  Optional[Sequence[Mapper[Any]]]rU  Optional[ColumnElement[Any]]rV  r7  rW  r   rX  r   )r6  AliasedInsp[_O]r   AliasedClass[_O])r   r   r   r   )r   r   rt  r   r6  r  r   r   )r   r   )r   r   r   r   r   r/  r   r^  ro  ru  r   rz  r}   r   r   rE  rE  v  s    9v M
 '+"$DHGK15 %&+8=+8= $8= 	8=
 8= 8= #B8= )E8= /8= 8=  $8=t *	 ":&(8G	.
'r   rE  r  c                  (   e Zd ZU dZdZdej                  j                  fdej                  j                  fdej                  j                  fdej                  j                  fdej                  j                  fdej                  j                  fd	ej                  j                  fgZd
ed<   ded<   ded<   ded<   ded<   ded<   	 ded<   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d+dZe	 	 	 	 d,	 	 	 	 	 	 	 	 	 	 	 d-d       Ze	 	 	 	 	 	 	 	 d.	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d/d       Zed0d       ZdZ	 d1dZed0d       Zed2d       Zed3d       Zd4dZd5d Zd6d!Z	 d7	 	 	 	 	 d8d"Zer	 d7	 	 	 	 	 d9d#ZneZd$ Z d% Z!d& Z"d' Z#d( Z$d) Z%d* Z&y):rP  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`

    )__weakref__rs  r  r0  r   _adapt_on_namesrQ  rR  _use_mapper_path_base_aliasrX  persist_selectablelocal_tabler\  r]  _adapterrg  __clause_element___memoized_values_all_column_expressions_nest_adaptersr   r  r  rg  r0  rQ  rR  z
Mapper[_O]r  rI   r4  r  zSequence[Mapper[Any]]zSequence[AliasedInsp[Any]]r]  zweakref.ref[AliasedClass[_O]]rs  z!Union[Type[_O], AliasedClass[_O]]c                   |j                   }|j                  }t        j                  |      | _        || _        |x| _        x| _        | _        || _        || _	        t        j                  |xs |       | _
        || _        |
| _        || _        |rd| _        || _        g | _        | j                  D ]q  }||ust#        |j$                  || |	|      }t'        | j                   |j$                  j(                  |       | j                   j+                  |j,                         s nd| _        |g| _        t/        t0        j2                  |||j4                  |	d| j                  D ch c]  }|	s|j
                   c}d      | _        |r<t9        |t:              sJ |j6                  j=                  | j6                        | _        |	| _        || _         y c c}w )NT)rV  r,  rW  F)r0  r(  r,  r+  r-  r8  )!r<  r  rq  rr  rs  r0  r  r  r   rR  r  r  rX  r  r\  rQ  r]  rE  r  r_  r   r   rS  r4  r  r  _equivalent_columnsr  r   rP  wrapr  rg  )r~   r<  	inspectedr0  r   rQ  rR  r  r  r,  rX  rZ  rT  r  polyra  r  s                    r   r/  zAliasedInsp.__init__  s    '--!!#KK/	
 	
$1D4D 	,";;{':d; 0%:"+#(,D%,DD).0D+55v%&"#''5(8C DKK)=)=sC33::3;L;LM 6 ).D%-3HD)"((!22)! 66$6A% 6$
 "
$ i555%..33DMMBDM-)$s   (GNc                    t        |t              rR|rt        j                  d      |r|j	                  ||      S t        j                  t        j                  ||      S t        |||||      S )Nz+adapt_on_names only applies to ORM elementsrH  rI  )r   rI  r   r,  )
r   rI   r   r   r   r=   r   r@   AnonymizedFromClauseRolerE  )r   elementr   r   rI  r,  s         r   _alias_factoryzAliasedInsp._alias_factory  s}     gz***A  }}$T}:: ''22G$   - r   c           
         t        |      }|dvr|rt        j                  d      |j                  |||      \  }}|s|r|J |j	                  |      }t        |||	||||
|       S )Nr   z[the 'flat' and 'selectable' arguments cannot be passed simultaneously to with_polymorphic()	innerjoinr  )r   rQ  r,  rU  rW  rX  )r   r   r   _with_polymorphic_argsrO  rE  )r   baseclassesr0  rI  rR  aliasedr  r,  r   r  primary_mappermapperss                r   _with_polymorphic_factoryz%AliasedInsp._with_polymorphic_factory  s     *$/]*t&&7 
 -CCZ9 D 
 d)))#99t9DJ%,)+9,&/-	
 		
r   c                    | j                         }|/t        j                  |       }t        j                  |      | _         |S r|   )rs  rE  r^  rq  rr  )r~   ra  s     r   r<  zAliasedInsp.entity7  s=     !;>>tDC 'C 0D
r   Tc                x    | j                   j                  | j                  | | d      j                  d| d      S )N)r>  parententityentity_namespaceormcompile_state_pluginplugin_subject)r0  	_annotater  _set_propagate_attrsrx  s    r   #_memoized_method___clause_element__z/AliasedInsp._memoized_method___clause_element__H  s@    (( $ $$(
 
%*dC
	
r   c                    | j                   S r|   )r<  rx  s    r   r  zAliasedInsp.entity_namespaceS  s    {{r   c                .    | j                   j                  S )zUReturn the mapped class ultimately represented by this
        :class:`.AliasedInsp`.)r  r  rx  s    r   r  zAliasedInsp.class_W  s     {{!!!r   c                p    | j                   r| j                  j                  S t        j                  |       S r|   )r  r  _path_registryr5   
per_mapperrx  s    r   r  zAliasedInsp._path_registry]  s,      ;;---**400r   c                   | j                   | j                  | j                  | j                  | j                  | j
                  | j                  | j                         | j                  | j                  | j                  dS )N)r<  r  r   r   r,  rQ  rU  rV  rW  rX  rZ  )r<  r  r0  r   r  rQ  rR  r  r  rX  r  rx  s    r   __getstate__zAliasedInsp.__getstate__d  sj    kkkk__II"22(,(E(E.2.A.A**,#44%)%?%?!00
 	
r   c                |    | j                  |d   |d   |d   |d   |d   |d   |d   |d   |d	   |d
   |d          y )Nr<  r  r   r   rQ  rU  rV  rW  r,  rX  rZ  )r/  )r~   r   s     r   __setstate__zAliasedInsp.__setstate__s  sg    (O(O'N&M,-23,#$"#)*/"	
r   c                   |j                   }| j                   |u sJ t        j                  d | j                  D              }|j                  D ch c]  }|j                   }}||k(  r|S |j                  |      }|j                  |d |j                         \  }}|j                  d      }t        ||||j                  |j                  |j                        j                  S c c}w )Nc              3  4   K   | ]  }|j                     y wr|   )r  .0mps     r   	<genexpr>z*AliasedInsp._merge_with.<locals>.<genexpr>  s      "
 ="BII =s   r  Tr  )rQ  rU  rW  rX  )r  r:   to_setrQ  r  unionr  rX  rO  rE  rR  r  rS  )	r~   otherr  our_classesr  new_classesr  r  r0  s	            r   _merge_withzAliasedInsp._merge_with  s     {{n,,,kk "
 $ = ="
 
 ,1+I+IJ+IRryy+IJ+%L!''4G,CCT)D)D%D D 
  5545@
%,+0+?+?!22"'"="=
 -	 Ks   C+c                    t        |t              sJ | | j                  d}|r||d<   | j                  j	                  |      j                  |      j                  d| d      S )N)r  r>  	proxy_keyr  r  )r   rG   r  r  traverser  r  )r~   exprr   ds       r   _adapt_elementzAliasedInsp._adapt_element  sh     $...  KK
  AkN
 MM""4(Yq\!!).$G	
r   c                     y r|   r}   )r~   r   r   s      r   _orm_adapt_elementzAliasedInsp._orm_adapt_element  s     r   c                    | j                   }||v rD|| j                  u r| S t        | j                  |j                  j
                        j                  S |j                  | j                        r| S J d|d|        )Nzmapper z doesn't correspond to )rQ  r  rh  r<  r  r   rS  rA  )r~   r  	self_polys      r   _entity_for_mapperzAliasedInsp._entity_for_mapper  sq    11	Y$KK!7!7-  ZZ$KO&$OO5r   c                    | j                   j                  \  }}| j                  j                  |      |j	                         D ci c]!  \  }}| j                  j                  |      |# c}}fS c c}}w r|   )r  _get_clauser  r  r   )r~   onclause
replacemapr   params        r   _memoized_attr__get_clausez&AliasedInsp._memoized_attr__get_clause  su    #{{66*MM""8, #-"2"2"4"4JC &&s+U2"4
 	
s   &A2c                    i S r|   r}   rx  s    r   _memoized_attr__memoized_valuesz+AliasedInsp._memoized_attr__memoized_values  s    	r   c                @   | j                   r>| j                  j                  | j                  D cg c]  }|j                   c}      }n| j                  j                         }|D cg c]  \  }}|| j	                  |      f }}}t        |      S c c}w c c}}w r|   )r\  r  _columns_plus_keysr]  r  rD   )r~   ra  cols_plus_keysr   r   s        r   &_memoized_attr__all_column_expressionsz2AliasedInsp._memoized_attr__all_column_expressions  s    $$![[;;'+'F'FG'F'FGN "[[;;=N =K
<JSS$%%c*+N 	 
  // H

s   B*Bc                n    || j                   v r| j                   |   S  ||i |x| j                   |<   }|S r|   )r  )r~   r   	callable_argskwr   s         r   _memozAliasedInsp._memo  sE    $'''((--1:D1GB1GGD!!#&Lr   c                    | j                   r&ddj                  d | j                   D              z  }nd}dt        |       | j                  j                  |fz  S )Nz(%s)r   c              3  H   K   | ]  }|j                   j                    y wr|   )r  r   r  s     r   r  z'AliasedInsp.__repr__.<locals>.<genexpr>  s      +-Jr		""-Js    "r   z<AliasedInsp at 0x%x; %s%s>)rQ  r   rw  r  r   )r~   	with_polys     r   r   zAliasedInsp.__repr__  sc    (( +-1-J-J+ " I I,tHKK  0
 
 	
r   c                      j                   r?d j                  j                  ddj                   fd j                  D              dS d j                  j                  dS )Nzwith_polymorphic(z, [r   c              3  f   K   | ](  }|j                   ur|j                  j                   * y wr|   )r  r  r   )r  r  r~   s     r   r  z&AliasedInsp.__str__.<locals>.<genexpr>  s/      ;, II&&;s   .1z])rJ  rK  )r\  rg  r   r   rQ  rx  s   `r   rz  zAliasedInsp.__str__  s\    $$%%		 ";;   % %)LL$9$9;;r   )r<  r  r  rG  r0  rI   r   r|  rQ  r}  rR  r~  r  r7  r  r   r,  r   rX  r   rZ  r   )NNFF)r  z"Union[_EntityType[_O], FromClause]r   r{  r   r|  rI  r   r,  r   r   z#Union[AliasedClass[_O], FromClause])FFNFFFNF)r  zUnion[Type[_O], Mapper[_O]]r  z/Union[Literal['*'], Iterable[_EntityType[Any]]]r0  z'Union[Literal[False, None], FromClause]rI  r   rR  r~  r  r   r  r   r,  r   r   r|  r  r   r   r  )r   r  )r   rI   )r   Type[_O])r   rY   )r   Dict[str, Any])r   r  r   None)r  r  r   r  r|   )r  rU   r   r|  r   rU   )r   r^   r   r|  r   r^   )'r   r   r   r   r   rA   ExtendedInternalTraversal	dp_string
dp_booleandp_inspectabledp_clauseelementInternalTraversaldp_has_cache_key_list_cache_key_traversalr   r/  r   r  r  propertyr<  r5  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r   rz  r}   r   r   rP  rP  @  s>   $LI2 
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 33 :://:..J* J* +J* 	J*
 J* #BJ* 5J* 0J* J* J*  $J* J*X  '+"$3 $ 	
   
- 8 
 ?D7;$"!&%
)%
 A%
 <	%

 %
 5%
 %
 %
 %
 %
 %
 
%
 %
N   	
   " "
 1 1

> 7;

&3
	
*  "&		 	 		 ,P
0
<r   rP  c                  J    e Zd ZdZdZd Z ej                  d      d        Zy)_WrapUserEntitya  A 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                    || _         y r|   r  )r~   r  s     r   r/  z_WrapUserEntity.__init__  s	    r   zsqlalchemy.orm.decl_apic                ,   t         j                  j                  j                  }t        j                  | d      }||j                  v rAt        |j                  |   |j                        r|j                  |   j                  |      S t        ||      S )Nr  )r:   	preloadedr  decl_apiobject__getattribute__rf  r   declared_attrfgetrh  )r~   r   r  r  s       r   r  z _WrapUserEntity.__getattribute__  s    >>%%..))$	:7###
T"H$:$:)
 ##D)..w777D))r   N)	r   r   r   r   r   r/  r:   preload_moduler  r}   r   r   r  r    s5     I T23	* 4	*r   r  c                     e Zd ZU dZdZdej                  j                  fdej                  j                  fdej                  j                  fdej                  j                  fdej                  j                  fgZded<   d	ed<   d
ed<   ded<   ded<   ded<   ded<   	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZed        Zd ZddZddZ	 	 	 	 ddZ	 	 	 	 	 	 ddZddZd dZy)!LoaderCriteriaOptiona
  Add 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<  deferred_where_criteriawhere_criteria_where_crit_originclude_aliasespropagate_to_loadersr  r<  r  r  r  zOptional[Type[Any]]"Optional[_InternalEntityType[Any]]z9Union[ColumnElement[bool], lambdas.DeferredLambdaElement]r   r  r   r   c                ,   t        dt        j                  |d            }|t        d|      | _        d | _        nd | _        || _        || _        t        |      r{| j                  | j                  }n|J |j                  }d| _        t        j                  |t        j                  t        |      ft        j                  |            | _        n0d| _        t        j                   t        j                  |      | _        || _        || _        y )NrC  Fr   T)track_closure_variables)lambda_argsopts)r   r8   rL  r  r<  r   callabler  r?   DeferredLambdaElementr@   WhereHavingRoler  LambdaOptionsr  r=   r   r  r  )	r~   entity_or_baser  loader_onlyr  r  r  r<  wrap_entitys	            r   r/  zLoaderCriteriaOption.__init__P  s    &~u5
 >#K@DDK#D DK .N#+"..)))$mm+/D(")"?"?%%,[9;**,C	#D ,1D("+"2"2%%~#D  /$8!r   c                     t        ||||      S )N)r  r  )r  )r   r<  r  r  r  s        r   	_unreducezLoaderCriteriaOption._unreduce  s     $+!5	
 	
r   c                    t         j                  | j                  r| j                  j                  n| j                  | j
                  | j                  | j                  ffS r|   )r  r  r<  r  r  r   r  r  rx  s    r   
__reduce__zLoaderCriteriaOption.__reduce__  sP     **&*kk""t7G7G%%$$))	
 	
r   c              #    K   | j                   r)| j                   j                  j                  E d {    y | j                  sJ t	        | j                  j                               }|rv|j                  d      }t        dt        j                  |d            }|r|j                  j                  E d {    n|j                  |j                                |ruy y 7 7 +w)Nr   rC  F)raiseerr)r<  r  self_and_descendantsr  list__subclasses__popr   r8   rL  extend)r~   stacksubclassra  s       r   _all_mappersz!LoaderCriteriaOption._all_mappers  s     ;;{{))>>>>####))88:;E 99Q<.&&x%@ "zz>>>>LL!8!8!:; 	 ? ?s(   0C&C"BC&8C$9&C& C&$C&c                V    |j                   j                  j                  dd       | u ryy)Nfor_loader_criteriaFT)select_statementr?  r@  r~   compile_states     r   _should_includez$LoaderCriteriaOption._should_include  s3    **77;;%t 
 r   c                    | j                   r0t        d| j                  j                  |j                              }n| j                  }t        |t              sJ t        j                  |d| idd      S )NColumnElement[bool]r  T)detect_subquery_colsind_cols_on_fromclause)	r  r   r  _resolve_with_argsr<  r   rG   r   _deep_annotate)r~   ext_infocrits      r   _resolve_where_criteriaz,LoaderCriteriaOption._resolve_where_criteria  ss     ''%##66xGD
 &&D$...&&"D)!%#'	
 	
r   c                &    | j                  |       y r|   )process_compile_state)r~   r!  mapper_entitiess      r   'process_compile_state_replaced_entitiesz<LoaderCriteriaOption.process_compile_state_replaced_entities  s    
 	""=1r   c                :    | j                  |j                         y)z7Apply a modification to a given :class:`.CompileState`.N)get_global_criteriaglobal_attributesr   s     r   r-  z*LoaderCriteriaOption.process_compile_state  s     	  !@!@Ar   c                z    | j                         D ](  } |j                  d|fg       }|j                  |        * y )Nadditional_entity_criteria)r  
setdefaultr   )r~   r   r  load_criterias       r   r1  z(LoaderCriteriaOption.get_global_criteria  sA    ##%B1J11-r2BM   & &r   N)FFTT)r  z_EntityType[Any]r  zXUnion[_ColumnExpressionArgument[bool], Callable[[Any], _ColumnExpressionArgument[bool]]]r  r   r  r   r  r   r  r   )r   zIterator[Mapper[Any]])r!  rW   r   r   )r)  rC  r   r$  )r!  rW   r.  zIterable[_MapperEntity]r   r  )r!  rW   r   r  )r   zDict[Any, Any]r   r  )r   r   r   r   r   rA   r  dp_plain_objdp_has_cache_keyr  r  r  _traverse_internalsr   r/  r   r  r  r  r"  r+  r/  r-  r1  r}   r   r   r  r  )  sZ   	I 
::GGH	855FFG	855FFG	H66AAB	!;!;!F!FG %$..MM!! " %%)(,/9(/9
/9 /9 /9 #/9 "&/9b 
 
	
<"
0
	
$2&2 12 
	2B'r   r  c                    | j                   S r|   )rS  )rm  s    r   <lambda>r;    s
    &2F2Fr   c                    	 t        |       }||j                  sy |j                  }|S # t        j                  $ r Y y w xY wr|   )r*   	is_mappedr  r   NO_STATE)r  class_managerr  s      r   _inspect_mcr@    sL    ,V4 (?(?%%  << s   * * A A c                B    t        dt        |             }t        |      S )Nr  )r   rN   r@  )r  origins     r   _inspect_generic_aliasrC    s      *j01Fvr   c                  *   e Zd ZU dZdZ	 dZdZdZdZ e	j                         Zded<   e	j                  Zded<   	 	 	 	 	 	 ddZ	 	 	 	 	 	 dd	Zedd
       Zedd       Ze	 	 dd       Zded<   	 ded<   	 d Zd Zed        Zd Z	 	 	 	 	 	 	 	 ddZy)Bundlea+  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.

    .. seealso::

        :ref:`bundles`


    FTrc   _propagate_attrszList[_ColumnsClauseElement]exprsc           
        |x| _         | _        |D cg c](  }t        j                  t        j
                  ||       * }}|| _        t        d |D cg c]  }|j                  j                  d|        c}D              j                         x| _        | _        |j                  d| j                        | _        yc c}w c c}w )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  N   K   | ]  }t        |d |j                        |f  yw)r   N)rh  _label)r  r   s     r   r  z"Bundle.__init__.<locals>.<genexpr>A  s*      1
O S%,c2Os   #%bundlesingle_entityN)r   rK  r=   r   r@   ColumnsClauseRolerG  rD   r?  r@  as_readonlyr   columnsr  rM  )r~   r   rG  r  r  coerced_exprses          r   r/  zBundle.__init__%  s    & #'&	DK
 	
  ''T 	 	 
 #
 0 1
ANOA**8Q7O1
 !
 +-	  VVOT5G5GH
 Ps   -B?#C
c           
         | j                   | j                  | j                  ft        | j                  D cg c]  }|j                  ||       c}      z   S c c}w r|   )r   r   rM  r  rG  _gen_cache_key)r~   rj   
bindparamsr  s       r   rT  zBundle._gen_cache_keyG  sT     		4+=+=>CG::N:4T  :6:NB
 
 	
Ns   A
c                X    | j                   d   j                  j                  dd       }|S )Nr   r>  rG  r?  r@  )r~   r  s     r   r  zBundle.mapperN  s,    $(JJqM$>$>$B$BD%
 	r   c                X    | j                   d   j                  j                  dd       }|S )Nr   r  rW  )r~   ies     r   r<  zBundle.entityU  s-    152

,ss>40 	 	r   6ReadOnlyColumnCollection[str, KeyedColumnElement[Any]]c                    | j                   S r|   )r   rx  s    r   r  zBundle.entity_namespace\  s     vvr   rP  r   c                    | j                   j                  | j                         }|j                  j                  | j                         |S r|   )r   r   rf  r   )r~   r  cloneds      r   _clonezBundle._clone  s5    ''7t}}-r   c           	        | | d} |j                   | j                         | j                  d   j                  j	                  d| j
                        }t        j                  | j                  D cg c]  }|j                  j	                  d|        c}t        j                  ddj                  |      j                  d|d      S c c}w )	N)rL  r  r   r  rL  F)_literal_as_text_rolegroupr  r  )r   r?  rG  rF  r@  r<  r>   
ClauseListr@   rN  r  r  )r~   r   r  rR  s       r   r  zBundle.__clause_element__  s    !%4@4,,-A77;;dkk
 !! <@::F:a!..$$Xq1:F ',&=&=
 Y{#!! -2&4	
 Gs   2#Cc                6    | j                         j                  S r|   )r  clausesrx  s    r   rd  zBundle.clauses  s    &&(000r   c                4    | j                         }||_        |S )z<Provide a copy of this :class:`.Bundle` passing a new label.)r^  r   )r~   r   r]  s      r   r   zBundle.label  s     r   c                V    t        ||D cg c]  }d c}      dfd}|S c c}w )a  Produce the "row processing" function for this :class:`.Bundle`.

        May be overridden by subclasses to provide custom behaviors when
        results are fetched. The method is passed the statement object and a
        set of "row processor" functions at query execution time; these
        processor functions when given a result row will return the individual
        attribute value, which can then be adapted into any kind of return data
        structure.

        The example below illustrates replacing the usual :class:`.Row`
        return structure with a straight Python dictionary::

            from sqlalchemy.orm import Bundle


            class DictBundle(Bundle):
                def create_row_processor(self, query, procs, labels):
                    "Override create_row_processor to return values as dictionaries"

                    def proc(row):
                        return dict(zip(labels, (proc(row) for proc in procs)))

                    return proc

        A result from the above :class:`_orm.Bundle` will return dictionary
        values::

            bn = DictBundle("mybundle", MyClass.data1, MyClass.data2)
            for row in session.execute(select(bn)).where(bn.c.data1 == "d1"):
                print(row.mybundle["data1"], row.mybundle["data2"])

        r}   c                F     D cg c]
  } ||        c}      S c c}w r|   r}   )r	  prockeyed_tupleprocss     r   rh  z)Bundle.create_row_processor.<locals>.proc  s$    e<edS	e<==<s   )r	  zRow[Any]r   r   r;   )r~   queryrj  labelslrh  ri  s     `   @r   create_row_processorzBundle.create_row_processor  s3    L #6+?1B+?@	>  ,@s   	&
N)r   r   rG  z_ColumnExpressionArgument[Any]r  r   )rj   rj   rU  zList[BindParameter[Any]]r   zTuple[Any, ...])r   zOptional[Mapper[Any]])r   r  )r   rZ  )rk  zSelect[Any]rj  z#Sequence[Callable[[Row[Any]], Any]]rl  zSequence[str]r   zCallable[[Row[Any]], Any])r   r   r   r   rM  is_clause_element	is_mapperr5  	is_bundler:   immutabledictrF  r   	EMPTY_SET	proxy_setr/  rT  r  r  r<  r  r^  r  rd  r   rn  r}   r   r   rE  rE    s;   $ M< II,>D,>,>,@)@I&& I I!? IGJ ID
 
.F
	
     	? 
 DC0 >=/

2 1 1++ 3+ 	+
 
#+r   rE  z
Bundle[_T]c                4    t        j                  | ddi|      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   r(  )r  excludes     r   _orm_annotaterx    s     ""7\4,@'JJr   c                0    t        j                  | d      S )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.

    )rv  r  )r   r   _deep_deannotater  s    r   _orm_deannotater}    s     $$6 r   c                ,    t        j                  |       S r|   rz  r|  s    r   _orm_full_deannotater    s    $$W--r   c                      e Zd ZdZej
                  j                  ZdZ	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d	dZd Z		 	 	 d
	 	 	 	 	 	 	 	 	 ddZ
	 	 d	 	 	 	 	 	 	 ddZy)_ORMJoinz/Extend Join to support ORM constructs as input.TNc	                   t        dt        j                  |            }	t        dt        j                  |            }
|
j                  }|| _        || _        t        |t        j                        rbt        r&t        |j                  t        j                        sJ |j                  j                         }|j                  }||j                  z  }n-t        |t               r|}|j"                  j                  }nd }d }|	j                  }|rt%        j&                  ||      r|}nt        |t(              sJ |}|j+                  ||d|
d|      \  }}}}}}|7|rt-        j.                  |||      }|}nt-        j.                  ||||      }|}n|}|| _        t3        |	      r|j4                  j7                  dd       }nt9        |	      st;        |	      r|	}nd }|"| j4                  j=                  d|i      | _        t?        |      xr | }t@        jB                  jE                  | |||||       | jF                  J |r%| xjF                  t-        jH                  | z  c_#        |stK        |
dd       rw|
jL                  jN                  r`t        d|
      }
|
jL                  jP                  }|;t;        |
      r|
jR                  jU                  |      }| jF                  |z  | _#        y y y y y )Nz+Union[FromClause, _InternalEntityType[Any]]T)source_selectabledest_selectablesource_polymorphicof_type_entityalias_secondaryextra_criteriar  r  rC  )+r   r8   rL  r0  
_left_memo_right_memor   r   QueryableAttributer   
comparatorr[   
Comparator_source_selectabler  _extra_criteriar1   parentr   clause_is_presentrI   _create_joinsr9   r   _target_adapterrB   r?  r@  r   r   r  r   r>   Joinr/  r  and_rh  r  single_single_table_criterionr  r  )r~   leftrightr  isouterfullr  r  r  	left_info
right_infoadapt_toon_selectablepropleft_selectable
adapt_frompjsjsourcedest	secondarytarget_adapterr  augment_onclausesingle_crits                            r   r/  z_ORMJoin.__init__  s    9t$
	
 9u%

 (( %&h
 = =>!'')=)H)H   %//BBDM$$Dx777O.1D KK22MD M#..))-I*
!/:>>>,
 """, (#') $. #  ~HHYr:E!H88D)RAD!H#1D  #*77;;L I&*?	*J$LL# $ 1 1 7 7.!D  0=X  tUHgtL}}(((MMSXX77M 
Hd3!!((8*EJ %++CCK&(4","5"5">">{"KK $ ; ' ) 4 r   c                   |}t        |t        j                        r'|j                  }t        |t        j                        r'| j                  |u sJ t        | j                  |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)

        )r  r  r  )r  r  )r   r9   r  r  r  r  r  r  r  r  r  )r~   r  leftmostr  s       r   _splice_into_centerz_ORMJoin._splice_into_centerr  s     388,}}H 388, zzX%%%IIJJMMLL((77
 KKNNMM))
 	
r   c                "    t        | ||||      S )N)r  r  r  )r~   r  r  r  r  s        r   r   z_ORMJoin.join  s     eXD'JJr   c                "    t        | ||d|      S )NT)r  r  r  )r~   r  r  r  s       r   	outerjoinz_ORMJoin.outerjoin  s     eXt$GGr   )NFFNNr}   )r  ra   r  ra   r  Optional[_OnClauseArgument]r  r   r  r   r  Optional[Any]r  r  r  zTuple[ColumnElement[bool], ...])NFF)
r  ra   r  r  r  r   r  r   r   r  r   )r  ra   r  r  r  r   r   r  )r   r   r   r   r>   r  __visit_name__inherit_cacher/  r  r   r  r}   r   r   r  r    s   9__33NM 15$(%);=w<!w< #w< .	w<
 w< w< "w< #w< 9w<r
@ 15K"K .K 	K
 K 
K 15	H"H .H 	H
 
Hr   r  c                B   t        |t              rt        j                  d      t        |t        j
                        rL|j                  r|j                  }|j                  }|t        |      st        j                  d|       |}n|}|j                  | |      S )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:
      Class-bound attribute, which indicates
      what relationship from the instance should be used to reconcile the
      parent/child relationship.

    :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

    z@with_parent() accepts class-bound mapped attributes, not stringsz6Expected relationship property for with_parent(), got )from_entity)
r   r   r   r   r   r  _of_typer  r   _with_parent)r  r  r  mapper_propertyprop_ts        r   with_parentr    s    l $""N
 	
 
D*77	8==--K--"*>+
 &&&')  !x[AAr   c                D    t        j                  |       }|j                  S )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_r   s     r   r  r    s      %%g.Er   c                D    t        j                  |       }|j                  S )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     r   r  r    s      %%g.Er   c                    t        |      r-t        |       r!|j                         | j                         u ryyt        |       r| j                  r|| j                  v S || u S t	        |       sJ |j                  |       S )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  rQ  r   common_parentgivenr<  s     r   _entity_corresponds_tor    s     V$ '!!#u'8'8'::	u	%!!U;;;;U?"%   &&r   c                    t        |       r0t        |      xr# |j                   xr | |u xs || j                  v S t        |      s| j                  |j                        S |j                  xr | |j
                  v S )a  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]  rA  r  rQ  r  s     r   $_entity_corresponds_to_use_path_implr  %  s    * U#!&) P+++P&NFe.N.N$N	

 #6*yy'' ## 9888	
r   c                    | j                   r+|| j                  v xs | j                  j                  |      S | j                  r!|| j                  v xs | j                  |      S | j                  |      S )zedetermine if 'given' "is a" mapper, in terms of the given
    would load rows of type 'mapper'.

    )r5  rQ  r  rA  )r  r  s     r   _entity_isar  I  sr    
 777 
5<<;K;K<
 	
 
	'	'777L599V;LLyy  r   c                   d }t        |t              rt        j                  |      \  }}}t        |t              rt        |t              r
||z
  dk  rg S t        |t              r|dk  st        |t              r|dk  r |        | j                  ||      }|t        |      dd|j                     S t        |      S |dk(  r |        yt        | ||dz          d   S )zdcalculate __getitem__ in terms of an iterable query object
    that also has a slice() method.

    c                     t        d      )Nz@negative indexes are not accepted by SQL index / slice operators)
IndexErrorr}   r   r   _no_negative_indexesz&_getitem.<locals>._no_negative_indexes^  s    &
 	
r   r   Nr   )r   slicer:   decode_sliceintr  step)iterable_queryitemr  startstopr  ress          r   _getitemr  X  s    
 $ --d3tT tS!5#&u!I$tS!dQh """5$/9TD49945592: "tdQh78;;r   c                p    	 t        || |j                        }t        |t              S # t        $ r Y yw xY wr   )rK   r   rO   r   	NameError)raw_annotationr   originating_cls	annotateds       r   _is_mapped_annotationr    sE    
B+!;!;
	  	+@AA   s   ) 	55c                      e Zd Zy)_CleanupErrorN)r   r   r   r}   r   r   r  r    s    r   r  c           	     B  	 t        j                  d|       }|s| S 	 t        |j                  d      |      }|t        j                  u rd}n!	 t        |t              r|j                  }n| S 	 g }|}	 |j                  ||u r|n|j                  d             |j                  d      }t        j                  d|      }||j                  |       nbt        j                  d|d	         smt        j                  d
|d	         sTd	dj                  	fd|d	   j                  d      D              |d	<   dj                  |      dt!        |      dz
  z  z   } | S # t        $ r'}t        d|  d|j                  d       d      |d }~ww xY w# t        $ r | cY S w xY w)Nz^([^ \|]+?)\[(.+)\]$r   zFor annotation "z%", could not resolve container type "z[".  Please ensure this type is imported at the module level outside of TYPE_CHECKING blocksClassVarr6   z^["'].*["']$r  z[\[\]]z"' r   c              3  H   K   | ]  }d |j                         d   yw)"N)strip)r  rB  
stripcharss     r   r  z1_cleanup_mapped_str_annotation.<locals>.<genexpr>  s)      
6Jda

:&'q)6Js   "r   [])r   matchrL   ra  r  r  typingr  
issubclassr   r   	TypeErrorr   searchr   r   len)
r   r   mmr   nereal_symbolr  innerg2r  s
            @r   _cleanup_mapped_str_annotationr    s    
):	6BRXXa[*<= foo 	#45!ll!!  EE
B%K[U[[^D[[^0"5=LL . HH(%)4
 		)U2Y/
II 
6;Biooc6J
 
b	 XXe_s5zA~(>?
C  zl +!xx{m ,..

 	   		s)   E F 	F&"FFFFc	           	     "   | 6|r3t        j                  d|j                   d| d|j                   d      y	 t        || |t              }	|r|	dfS t        |	d
      rt        |	t              sr|rl|syt        |	d
d      }|t        j                  u ryt        |t              rt        |t               ryt        j                  d|j                   d| dd      |	dfS t#        |	j$                        dk7  rt        j                  d      t'        |	j$                  d         |	j(                  fS # t
        $ r}
t        j                  d|  d      |
d}
~
wt        $ r-}|rd	| v rt        j                  d|  d      || }	Y d}~<d}~ww xY w)zgiven an annotation, figure out if it's ``Mapped[something]`` and if
    so, return the ``something`` part.

    Includes error raise scenarios and other options.

    Nz4Python typing annotation is required for attribute ".z " when primary argument(s) for "z#" construct are None or not present)ry   zCould not interpret annotation zt.  Check that it uses names that are correctly imported at the module level. See chained stack trace for more hints.zMapped[
__origin__zType annotation for "a  " can't be correctly interpreted for Annotated Declarative Table form.  ORM annotations should normally make use of the ``Mapped[]`` generic type, or other ORM-compatible generic type, as a container for the actual type, which indicates the intent that the attribute is mapped. Class variables that are not intended to be mapped by the ORM should use ClassVar[].  To allow Annotated Declarative to disregard legacy annotations which don't use Mapped[] to pass, set "__allow_unmapped__ = True" on the class or a superclass this class.zlpr)coder   z)Expected sub-type for Mapped[] annotationr   )orm_excMappedAnnotationErrorr   rK   r  r  r  rj  rO   r   rh  r  r  r   r   r  r+   r  __args__rM   r  )r  r   r   r   attr_clsrequiredis_dataclass_fieldexpect_mappedr  r  cer  rB  s                r   _extract_mapped_subtyper    s   $ //LL>3% (%%&&IK 
 # ,9	
	, $y,/7G,8
  L$?V__,  -*M3  33+CLL>3% @- -   $ !$&y!!"a'//;  %Y%7%7%:;  
 	
}  ++-n-= >D D
 		
  #	^3//1.1A BH H 	 #	#s#   D2 2	F;EF!"F		Fc                l    t        | d      r| j                         }nd }t        j                  | |      S )N_mapper_property_name)rj  r  r:   clsname_as_plain_name)r  r   s     r   _mapper_property_as_plain_namer	  ^	  s3    t,-))+%%dD11r   )p_unionT)NN)r  zOptional[Type[_T]]r  zUnion[Any, Tuple[Any, ...]]r  zOptional[_T]r	  z%Optional[Union[Row[Any], RowMapping]]r
  r  r   z_IdentityKeyType[_T])r  r  r   zOptional[Mapper[_O]]r|   )r  rd   rw  r  r   rd   )r  rd   r   rd   )r  r  r  z"attributes.QueryableAttribute[Any]r  zOptional[_EntityType[Any]]r   r$  )r  r  r   r   )r  rC  r<  rC  r   r   )r  rC  r  zMapper[Any]r   r   )r  z
Query[Any]r  r   r   r   )r  rk   r   r   r  r   r   r   )r   r   r   r   r   r   )TT)r  zOptional[_AnnotationScanType]r   r   r   r   r   r   r   r   r  r   r  r   r  r   r  r   r   z@Optional[Tuple[Union[_AnnotationScanType, str], Optional[type]]])r  r   r   r   )
__future__r   r  	functoolsr   r   r  r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   rq  r   r   r   r  _typingr   r   r   r   r  r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   
interfacesr0   r1   r2   r3   r4   path_registryr5   r7   r   r8   r9   r:   engine.resultr<   r=   r>   r?   r@   r   rA   sql._typingrB   sql.annotationrC   sql.baserD   sql.cache_keyrE   rF   sql.elementsrG   rH   sql.selectablerI   util.langhelpersrJ   util.typingrK   _de_stringify_annotationrL   _eval_name_onlyrM   rN   rO   rP   rQ   rR   rS   rT   rU   contextrV   rW   r  rX   rY   rk  rZ   relationshipsr[   enginer\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   sql.visitorsrj   rk   rl   	frozensetr   partialrr  _de_stringify_partialrx   r   r   r   r   r  r  Enumr  ColumnAdapterr%  r4  InspectablerE  _self_inspectsrP  r  r  	_inspectsr   r@  GenericAliasrC  rE  rx  r}  r  r  r  r  r  r  r  r  r  r  r  	Exceptionr  r  r  r	  r}   r   r   <module>r)     s   #   	                           * # ) 6 ' * 2 ( 0 .  2 .  0 . &  < 4 ( ! & 8 , 2 ) 7      (     "  ' 5 ' ' / ( - ' , M ; 2 $ * ! "	$),$&(53#!721/1$3,6'+'1T	 *	))D.*	
	 	X 	 12JK 
@H @ m%:?%KLFYs^ FR?DF =AO3f "&)-UD "15$(UDUD&UD 	UD
 
/UD "UD UDp9+dii 9+x
(00 
:2P'' 2PjG',-/CB/GG'T I<r",-BKI< I<X* *8p'> p'f # 
  \ "#F G d  DI l# $ Y<(Y YxK.lHz lHd /3IBIB
,IB ,IB 	IBX "'#'-E'	'.!
#!
-E!
	!
H!$<NB'B	B B 
	B*	I 	WW),WWD i
1i
	i
 i
 
	i

 i
 i
 i
 i
 i
 Fi
X2r   