
    \f]M                      U d 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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+l2m3Z3 d"d,l4m5Z5 d"d-l4m6Z6 d"d.l4m7Z7 d/Z8d0e9d1<   d2Z:d3e9d4<    ed5d67      Z;ejx                  rTdd8lm=Z= dd9lm>Z> dd:l?m@Z@ dd;l?mAZA dd<l?mBZB dd=lmCZC dd>lmDZD dd?lmEZE dd@lFmGZG ddAlmHZH d"dBlImJZJ d"dClImKZK d"dDlLmMZM d"dElLmNZN ee6dF   dGf   ZOe6dH   ZPeeQef   ZReeQef   ZSeeOdIf   ZT G dJ dKe0j                  e      ZV G dL dMeV      ZW G dN dOeV      ZX G dP dQe-j                  e0j                  e1j                        Z\ G dR dSe\      Z] G dT dUe\      Z^ G dV dWe\      Z_	 	 	 	 	 	 	 	 	 	 dndXZ`	 	 	 	 dodYZadpdZZbebdqd[       Zcebd\d]drd^       Zdebdqd_       Zeebdsd`       Zfebdda	 	 	 	 	 dtdb       Zgebdsdc       Zhebdda	 	 	 	 	 dtdd       Ziebdsde       Zjebdqdf       Zkebdsdg       Zlebd\d]	 	 	 	 	 	 	 dudh       Zmebdvdi       Znebdwdj       Zoeb	 	 	 	 	 	 dxdk       Zpeb	 	 	 	 	 	 dydl       Zqdm Zry)zz

    )annotationsN)Any)Callable)cast)Dict)Iterable)Optional)overload)Sequence)Tuple)Type)TypeVar)Union   )util)insp_is_aliased_class)insp_is_attribute)insp_is_mapper)insp_is_mapper_property)QueryableAttribute)InspectionAttr)LoaderOption)_DEFAULT_TOKEN)_StrPathToken)_WILDCARD_TOKEN)AbstractEntityRegistry)path_is_property)PathRegistry)TokenRegistry)_orm_full_deannotate)AliasedInsp   )excinspect)and_)	cache_key)	coercions)roles)
traversals)visitors)_generative)Final)Literal)SelfrelationshipzFinal[Literal['relationship']]_RELATIONSHIP_TOKENcolumnzFinal[Literal['column']]_COLUMN_TOKEN_FNzCallable[..., Any])bound)_EntityType)_InternalEntityType)_MapperEntity)ORMCompileState)QueryContext)_StrategyKey)MapperProperty)	ORMOption)Mapper)_PathRepresentation)_ColumnExpressionArgument)_FromClauseArgument)_CacheKeyTraversalType)CacheKey*zQueryableAttribute[Any])r0   r2   .c                  `   e Zd ZU dZdZded<   	 	 	 d%	 	 	 	 	 	 	 	 	 d&dZddd'd	Z	 d(	 	 	 	 	 d)d
Zd*dZ		 d(	 	 	 	 	 d+dZ
d*dZ	 d(	 	 	 	 	 d+dZd*dZd,d-dZd*dZd,d.dZd/dZd0dZ	 	 	 	 	 	 d1dZd2dZed3d       Zed4d       Z	 	 	 	 d5dZe	 	 	 d6	 	 	 	 	 	 	 	 	 	 	 d7d       Ze	 	 d8	 	 	 	 	 	 	 	 	 d9d       Ze	 d(	 	 	 	 	 	 	 d:d       Ze	 	 	 	 	 	 d;d       Zd<dZd=dZ	 	 	 	 	 d>	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d?d Z	 	 	 	 	 	 d@d!ZdAd"Z 	 	 	 	 	 	 	 	 dBd#Z!e"	 d,	 	 	 	 	 	 	 dCd$       Z#y)D_AbstractLoad)propagate_to_loadersTboolrG   NFc                r   |Ot        |t              s%t        j                  t        j
                  |      }nat        j                  dd       |}nGt        |dd      r8t        |t              sJ t        |j                        }|J |j                  }nd}| j                  |ddi|d|i|rd	nd
      }|S )a,  Indicate that the given attribute should be eagerly loaded from
        columns stated manually in the query.

        This function is part of the :class:`_orm.Load` interface and supports
        both method-chained and standalone operation.

        The option is used in conjunction with an explicit join that loads
        the desired rows, i.e.::

            sess.query(Order).join(Order.user).options(
                contains_eager(Order.user)
            )

        The above query would join from the ``Order`` entity to its related
        ``User`` entity, and the returned ``Order`` objects would have the
        ``Order.user`` attribute pre-populated.

        It may also be used for customizing the entries in an eagerly loaded
        collection; queries will normally want to use the
        :ref:`orm_queryguide_populate_existing` execution option assuming the
        primary collection of parent objects may already have been loaded::

            sess.query(User).join(User.addresses).filter(
                Address.email_address.like("%@aol.com")
            ).options(contains_eager(User.addresses)).populate_existing()

        See the section :ref:`contains_eager` for complete usage details.

        .. seealso::

            :ref:`loading_toplevel`

            :ref:`contains_eager`

        NzPassing a string name for the 'alias' argument to 'contains_eager()` is deprecated, and will not work in a future release.  Please use a sqlalchemy.alias() or sqlalchemy.orm.aliased() construct.1.4version_of_typelazyjoinedeager_from_aliasT)rG   opts_reconcile_to_other)
isinstancestrr(   expectr)   FromClauseRoler   warn_deprecatedgetattrr   r%   rM   
selectable_set_relationship_strategy)selfattralias	_is_chain_propagate_to_loaderscoerced_aliasotcloneds           X/var/www/highground/venv/lib/python3.12/site-packages/sqlalchemy/orm/strategy_options.pycontains_eagerz_AbstractLoad.contains_eager`   s    T eS) ) 0 01E1Eu M$$: " !&T:t,d$67775<T]]5KB>!>MMM M00X!6$m4(1t 1 
     	raiseloadc               l    | j                  |ddd      }ddd}|rd|d<   |j                  d|      }|S )a  Indicate that for a particular entity, only the given list
        of column-based attribute names should be loaded; all others will be
        deferred.

        This function is part of the :class:`_orm.Load` interface and supports
        both method-chained and standalone operation.

        Example - given a class ``User``, load only the ``name`` and
        ``fullname`` attributes::

            session.query(User).options(load_only(User.name, User.fullname))

        Example - given a relationship ``User.addresses -> Address``, specify
        subquery loading for the ``User.addresses`` collection, but on each
        ``Address`` object load only the ``email_address`` attribute::

            session.query(User).options(
                subqueryload(User.addresses).load_only(Address.email_address)
            )

        For a statement that has multiple entities,
        the lead entity can be
        specifically referred to using the :class:`_orm.Load` constructor::

            stmt = (
                select(User, Address)
                .join(User.addresses)
                .options(
                    Load(User).load_only(User.name, User.fullname),
                    Load(Address).load_only(Address.email_address),
                )
            )

        When used together with the
        :ref:`populate_existing <orm_queryguide_populate_existing>`
        execution option only the attributes listed will be refreshed.

        :param \*attrs: Attributes to be loaded, all others will be deferred.

        :param raiseload: raise :class:`.InvalidRequestError` rather than
         lazy loading a value when a deferred attribute is accessed. Used
         to prevent unwanted SQL from being emitted.

         .. versionadded:: 2.0

        .. seealso::

            :ref:`orm_queryguide_column_deferral` - in the
            :ref:`queryguide_toplevel`

        :param \*attrs: Attributes to be loaded, all others will be deferred.

        :param raiseload: raise :class:`.InvalidRequestError` rather than
         lazy loading a value when a deferred attribute is accessed. Used
         to prevent unwanted SQL from being emitted.

         .. versionadded:: 2.0

        FTdeferred
instrumentrg   )rD   _set_column_strategy)r[   rg   attrsrb   wildcard_strategys        rc   	load_onlyz_AbstractLoad.load_only   sX    x **d3

 *.TB-1k*,,
 re   c                Z    | j                  |ddi|d|int        j                        }|S )a;  Indicate that the given attribute should be loaded using joined
        eager loading.

        This function is part of the :class:`_orm.Load` interface and supports
        both method-chained and standalone operation.

        examples::

            # joined-load the "orders" collection on "User"
            select(User).options(joinedload(User.orders))

            # joined-load Order.items and then Item.keywords
            select(Order).options(
                joinedload(Order.items).joinedload(Item.keywords)
            )

            # lazily load Order.items, but when Items are loaded,
            # joined-load the keywords collection
            select(Order).options(
                lazyload(Order.items).joinedload(Item.keywords)
            )

        :param innerjoin: if ``True``, indicates that the joined eager load
         should use an inner join instead of the default of left outer join::

            select(Order).options(joinedload(Order.user, innerjoin=True))

        In order to chain multiple eager joins together where some may be
        OUTER and others INNER, right-nested joins are used to link them::

            select(A).options(
                joinedload(A.bs, innerjoin=False).joinedload(
                    B.cs, innerjoin=True
                )
            )

        The above query, linking A.bs via "outer" join and B.cs via "inner"
        join would render the joins as "a LEFT OUTER JOIN (b JOIN c)". When
        using older versions of SQLite (< 3.7.16), this form of JOIN is
        translated to use full subqueries as this syntax is otherwise not
        directly supported.

        The ``innerjoin`` flag can also be stated with the term ``"unnested"``.
        This indicates that an INNER JOIN should be used, *unless* the join
        is linked to a LEFT OUTER JOIN to the left, in which case it
        will render as LEFT OUTER JOIN.  For example, supposing ``A.bs``
        is an outerjoin::

            select(A).options(
                joinedload(A.bs).joinedload(B.cs, innerjoin="unnested")
            )


        The above join will render as "a LEFT OUTER JOIN b LEFT OUTER JOIN c",
        rather than as "a LEFT OUTER JOIN (b JOIN c)".

        .. note:: The "unnested" flag does **not** affect the JOIN rendered
            from a many-to-many association table, e.g. a table configured as
            :paramref:`_orm.relationship.secondary`, to the target table; for
            correctness of results, these joins are always INNER and are
            therefore right-nested if linked to an OUTER join.

        .. note::

            The joins produced by :func:`_orm.joinedload` are **anonymously
            aliased**. The criteria by which the join proceeds cannot be
            modified, nor can the ORM-enabled :class:`_sql.Select` or legacy
            :class:`_query.Query` refer to these joins in any way, including
            ordering. See :ref:`zen_of_eager_loading` for further detail.

            To produce a specific SQL JOIN which is explicitly available, use
            :meth:`_sql.Select.join` and :meth:`_query.Query.join`. To combine
            explicit JOINs with eager loading of collections, use
            :func:`_orm.contains_eager`; see :ref:`contains_eager`.

        .. seealso::

            :ref:`loading_toplevel`

            :ref:`joined_eager_loading`

        rN   rO   	innerjoinrQ   )rZ   r   
EMPTY_DICT)r[   r\   rr   loaders       rc   
joinedloadz_AbstractLoad.joinedload   sE    n 00X ( i(__ 1 
 re   c                *    | j                  |ddi      S )a  Indicate that the given attribute should be loaded using
        subquery eager loading.

        This function is part of the :class:`_orm.Load` interface and supports
        both method-chained and standalone operation.

        examples::

            # subquery-load the "orders" collection on "User"
            select(User).options(subqueryload(User.orders))

            # subquery-load Order.items and then Item.keywords
            select(Order).options(
                subqueryload(Order.items).subqueryload(Item.keywords)
            )

            # lazily load Order.items, but when Items are loaded,
            # subquery-load the keywords collection
            select(Order).options(
                lazyload(Order.items).subqueryload(Item.keywords)
            )


        .. seealso::

            :ref:`loading_toplevel`

            :ref:`subquery_eager_loading`

        rN   subqueryrZ   r[   r\   s     rc   subqueryloadz_AbstractLoad.subqueryloadU  s    > ..tfj5IJJre   c                2    | j                  |ddid|i      S )a  Indicate that the given attribute should be loaded using
        SELECT IN eager loading.

        This function is part of the :class:`_orm.Load` interface and supports
        both method-chained and standalone operation.

        examples::

            # selectin-load the "orders" collection on "User"
            select(User).options(selectinload(User.orders))

            # selectin-load Order.items and then Item.keywords
            select(Order).options(
                selectinload(Order.items).selectinload(Item.keywords)
            )

            # lazily load Order.items, but when Items are loaded,
            # selectin-load the keywords collection
            select(Order).options(
                lazyload(Order.items).selectinload(Item.keywords)
            )

        :param recursion_depth: optional int; when set to a positive integer
         in conjunction with a self-referential relationship,
         indicates "selectin" loading will continue that many levels deep
         automatically until no items are found.

         .. note:: The :paramref:`_orm.selectinload.recursion_depth` option
            currently supports only self-referential relationships.  There
            is not yet an option to automatically traverse recursive structures
            with more than one relationship involved.

            Additionally, the :paramref:`_orm.selectinload.recursion_depth`
            parameter is new and experimental and should be treated as "alpha"
            status for the 2.0 series.

         .. versionadded:: 2.0 added
            :paramref:`_orm.selectinload.recursion_depth`


        .. seealso::

            :ref:`loading_toplevel`

            :ref:`selectin_eager_loading`

        rN   selectinrecursion_depthrs   ry   )r[   r\   r~   s      rc   selectinloadz_AbstractLoad.selectinloadv  s0    h ..Z #_5 / 
 	
re   c                *    | j                  |ddi      S )a<  Indicate that the given attribute should be loaded using "lazy"
        loading.

        This function is part of the :class:`_orm.Load` interface and supports
        both method-chained and standalone operation.

        .. seealso::

            :ref:`loading_toplevel`

            :ref:`lazy_loading`

        rN   selectry   rz   s     rc   lazyloadz_AbstractLoad.lazyload  s     ..tfh5GHHre   c                6    | j                  |ddid|i      }|S )a  Indicate that the given attribute should be loaded using
        an immediate load with a per-attribute SELECT statement.

        The load is achieved using the "lazyloader" strategy and does not
        fire off any additional eager loaders.

        The :func:`.immediateload` option is superseded in general
        by the :func:`.selectinload` option, which performs the same task
        more efficiently by emitting a SELECT for all loaded objects.

        This function is part of the :class:`_orm.Load` interface and supports
        both method-chained and standalone operation.

        :param recursion_depth: optional int; when set to a positive integer
         in conjunction with a self-referential relationship,
         indicates "selectin" loading will continue that many levels deep
         automatically until no items are found.

         .. note:: The :paramref:`_orm.immediateload.recursion_depth` option
            currently supports only self-referential relationships.  There
            is not yet an option to automatically traverse recursive structures
            with more than one relationship involved.

         .. warning:: This parameter is new and experimental and should be
            treated as "alpha" status

         .. versionadded:: 2.0 added
            :paramref:`_orm.immediateload.recursion_depth`


        .. seealso::

            :ref:`loading_toplevel`

            :ref:`selectin_eager_loading`

        rN   	immediater~   rs   ry   )r[   r\   r~   ru   s       rc   immediateloadz_AbstractLoad.immediateload  s4    T 00[!#_5 1 

 re   c                *    | j                  |ddi      S )a  Indicate that the given relationship attribute should remain
        unloaded.

        The relationship attribute will return ``None`` when accessed without
        producing any loading effect.

        This function is part of the :class:`_orm.Load` interface and supports
        both method-chained and standalone operation.

        :func:`_orm.noload` applies to :func:`_orm.relationship` attributes
        only.

        .. legacy:: The :func:`_orm.noload` option is **legacy**.  As it
           forces collections to be empty, which invariably leads to
           non-intuitive and difficult to predict results.  There are no
           legitimate uses for this option in modern SQLAlchemy.

        .. seealso::

            :ref:`loading_toplevel`

        rN   noloadry   rz   s     rc   r   z_AbstractLoad.noload  s    0 ..tfh5GHHre   c                <    | j                  |d|rdi      S di      S )a  Indicate that the given attribute should raise an error if accessed.

        A relationship attribute configured with :func:`_orm.raiseload` will
        raise an :exc:`~sqlalchemy.exc.InvalidRequestError` upon access. The
        typical way this is useful is when an application is attempting to
        ensure that all relationship attributes that are accessed in a
        particular context would have been already loaded via eager loading.
        Instead of having to read through SQL logs to ensure lazy loads aren't
        occurring, this strategy will cause them to raise immediately.

        :func:`_orm.raiseload` applies to :func:`_orm.relationship` attributes
        only. In order to apply raise-on-SQL behavior to a column-based
        attribute, use the :paramref:`.orm.defer.raiseload` parameter on the
        :func:`.defer` loader option.

        :param sql_only: if True, raise only if the lazy load would emit SQL,
         but not if it is only checking the identity map, or determining that
         the related value should just be None due to missing keys. When False,
         the strategy will raise for all varieties of relationship loading.

        This function is part of the :class:`_orm.Load` interface and supports
        both method-chained and standalone operation.

        .. seealso::

            :ref:`loading_toplevel`

            :ref:`prevent_lazy_with_raiseload`

            :ref:`orm_queryguide_deferred_raiseload`

        rN   raise_on_sqlraisery   )r[   r\   sql_onlys      rc   rg   z_AbstractLoad.raiseload  s4    D ..6X>C
 	
;BC
 	
re   c                &    | j                  |d      S )a  Indicate an attribute should load using its predefined loader style.

        The behavior of this loading option is to not change the current
        loading style of the attribute, meaning that the previously configured
        one is used or, if no previous style was selected, the default
        loading will be used.

        This method is used to link to other loader options further into
        a chain of attributes without altering the loader style of the links
        along the chain.  For example, to set joined eager loading for an
        element of an element::

            session.query(MyClass).options(
                defaultload(MyClass.someattribute).joinedload(
                    MyOtherClass.someotherattribute
                )
            )

        :func:`.defaultload` is also useful for setting column-level options on
        a related class, namely that of :func:`.defer` and :func:`.undefer`::

            session.scalars(
                select(MyClass).options(
                    defaultload(MyClass.someattribute)
                    .defer("some_column")
                    .undefer("some_other_column")
                )
            )

        .. seealso::

            :ref:`orm_queryguide_relationship_sub_options`

            :meth:`_orm.Load.options`

        Nry   rz   s     rc   defaultloadz_AbstractLoad.defaultload1  s    J ..tT::re   c                @    ddd}|rd|d<   | j                  |f|      S )a  Indicate that the given column-oriented attribute should be
        deferred, e.g. not loaded until accessed.

        This function is part of the :class:`_orm.Load` interface and supports
        both method-chained and standalone operation.

        e.g.::

            from sqlalchemy.orm import defer

            session.query(MyClass).options(
                defer(MyClass.attribute_one),
                defer(MyClass.attribute_two)
            )

        To specify a deferred load of an attribute on a related class,
        the path can be specified one token at a time, specifying the loading
        style for each link along the chain.  To leave the loading style
        for a link unchanged, use :func:`_orm.defaultload`::

            session.query(MyClass).options(
                defaultload(MyClass.someattr).defer(RelatedClass.some_column)
            )

        Multiple deferral options related to a relationship can be bundled
        at once using :meth:`_orm.Load.options`::


            select(MyClass).options(
                defaultload(MyClass.someattr).options(
                    defer(RelatedClass.some_column),
                    defer(RelatedClass.some_other_column),
                    defer(RelatedClass.another_column)
                )
            )

        :param key: Attribute to be deferred.

        :param raiseload: raise :class:`.InvalidRequestError` rather than
         lazy loading a value when the deferred attribute is accessed. Used
         to prevent unwanted SQL from being emitted.

        .. versionadded:: 1.4

        .. seealso::

            :ref:`orm_queryguide_column_deferral` - in the
            :ref:`queryguide_toplevel`

            :func:`_orm.load_only`

            :func:`_orm.undefer`

        Tri   rg   rl   )r[   keyrg   strategys       rc   deferz_AbstractLoad.deferX  s1    n !%D9$(H[!((#::re   c                .    | j                  |fddd      S )a  Indicate that the given column-oriented attribute should be
        undeferred, e.g. specified within the SELECT statement of the entity
        as a whole.

        The column being undeferred is typically set up on the mapping as a
        :func:`.deferred` attribute.

        This function is part of the :class:`_orm.Load` interface and supports
        both method-chained and standalone operation.

        Examples::

            # undefer two columns
            session.query(MyClass).options(
                undefer(MyClass.col1), undefer(MyClass.col2)
            )

            # undefer all columns specific to a single class using Load + *
            session.query(MyClass, MyOtherClass).options(
                Load(MyClass).undefer("*")
            )

            # undefer a column on a related object
            select(MyClass).options(
                defaultload(MyClass.items).undefer(MyClass.text)
            )

        :param key: Attribute to be undeferred.

        .. seealso::

            :ref:`orm_queryguide_column_deferral` - in the
            :ref:`queryguide_toplevel`

            :func:`_orm.defer`

            :func:`_orm.undefer_group`

        FTri   rl   )r[   r   s     rc   undeferz_AbstractLoad.undefer  s$    P ((Fd;
 	
re   c                <    | j                  t        fdd| di      S )a$  Indicate that columns within the given deferred group name should be
        undeferred.

        The columns being undeferred are set up on the mapping as
        :func:`.deferred` attributes and include a "group" name.

        E.g::

            session.query(MyClass).options(undefer_group("large_attrs"))

        To undefer a group of attributes on a related entity, the path can be
        spelled out using relationship loader options, such as
        :func:`_orm.defaultload`::

            select(MyClass).options(
                defaultload("someattr").undefer_group("large_attrs")
            )

        .. seealso::

            :ref:`orm_queryguide_column_deferral` - in the
            :ref:`queryguide_toplevel`

            :func:`_orm.defer`

            :func:`_orm.undefer`

        Nundefer_group_T)rm   r   )r[   names     rc   undefer_groupz_AbstractLoad.undefer_group  s-    : ((v'>&E
 	
re   c                    t        t        j                  t        j                  |            }| j                  |fddi|f      S )a  Apply an ad-hoc SQL expression to a "deferred expression"
        attribute.

        This option is used in conjunction with the
        :func:`_orm.query_expression` mapper-level construct that indicates an
        attribute which should be the target of an ad-hoc SQL expression.

        E.g.::

            stmt = select(SomeClass).options(
                with_expression(SomeClass.x_y_expr, SomeClass.x + SomeClass.y)
            )

        .. versionadded:: 1.2

        :param key: Attribute to be populated

        :param expr: SQL expression to be applied to the attribute.

        .. seealso::

            :ref:`orm_queryguide_with_expression` - background and usage
            examples

        query_expressionT)extra_criteria)r    r(   rU   r)   LabeledColumnExprRolerm   )r[   r   
expressions      rc   with_expressionz_AbstractLoad.with_expression  sO    > *U88*E

 ((F'.
} ) 
 	
re   c           
     r    | j                  ddidt        t        d |D        t                    i      } | S )a  Indicate an eager load should take place for all attributes
        specific to a subclass.

        This uses an additional SELECT with IN against all matched primary
        key values, and is the per-query analogue to the ``"selectin"``
        setting on the :paramref:`.mapper.polymorphic_load` parameter.

        .. versionadded:: 1.2

        .. seealso::

            :ref:`polymorphic_selectin`

        selectinload_polymorphicTentitiesc              3  2   K   | ]  }t        |        y wNr$   ).0clss     rc   	<genexpr>z5_AbstractLoad.selectin_polymorphic.<locals>.<genexpr>  s     <SGCL<   )r   rs   )_set_class_strategytuplesortedid)r[   classess     rc   selectin_polymorphicz"_AbstractLoad.selectin_polymorphic  sG     '''.E<G<"E ( 
 re   c                     y r    r[   r   s     rc   _coerce_stratz_AbstractLoad._coerce_strat!  s    FIre   c                     y r   r   r   s     rc   r   z_AbstractLoad._coerce_strat$  s    >Are   c                V    |$t        t        |j                                     }|S d }|S r   )r   r   items)r[   r   strategy_keys      rc   r   z_AbstractLoad._coerce_strat'  s5      (8!9:L   Lre   c                `    | j                  |      }| j                  |f|t        |||       | S )N)rQ   rG   reconcile_to_other)r   _clone_for_bind_strategyr1   )r[   r\   r   rG   rQ   rR   r   s          rc   rZ   z(_AbstractLoad._set_relationship_strategy0  sB     ))(3%%G!52 	& 	
 re   c                ^    | j                  |      }| j                  ||t        |||       | S )N)rQ   
attr_groupr   )r   r   r3   )r[   rn   r   rQ   r   r   s         rc   rm   z"_AbstractLoad._set_column_strategyE  s@     ))(3%%) 	& 	
 re   c                T    | j                  |      }| j                  ||d d|       | S )NT)rG   r   r   r   )r[   rn   r   rR   r   s        rc   _set_generic_strategyz#_AbstractLoad._set_generic_strategyY  s=     ))(3%%!%2 	& 	
 re   c                R    | j                  |      }| j                  d |d |       | S )Nrs   r   )r[   r   rQ   r   s       rc   r   z!_AbstractLoad._set_class_strategyj  s0     ))(3%%dL$T%Jre   c                    t               )zapply this :class:`_orm._AbstractLoad` object as a sub-option o
        a :class:`_orm.Load` object.

        Implementation is provided by subclasses.

        NotImplementedErrorr[   parents     rc   _apply_to_parentz_AbstractLoad._apply_to_parents       "##re   c                    t               )zApply a series of options as sub-options to this
        :class:`_orm._AbstractLoad` object.

        Implementation is provided by subclasses.

        r   r[   rQ   s     rc   optionsz_AbstractLoad.options|  r   re   c	                    t               r   r   )	r[   rn   r   wildcard_keyrQ   r   rG   r   r   s	            rc   r   z&_AbstractLoad._clone_for_bind_strategy  s     "##re   c                    |j                   j                  sy | j                  ||t        |j                                y r   )compile_options_enable_eagerloads_processrH   current_path)r[   compile_statemapper_entitiess      rc   'process_compile_state_replaced_entitiesz5_AbstractLoad.process_compile_state_replaced_entities  s;    
 ,,??
 	]//00	
re   c                    |j                   j                  sy | j                  ||j                  t	        |j
                         xr |j                   j                          y r   )r   r   r   _lead_mapper_entitiesrH   r   _for_refresh_state)r[   r   s     rc   process_compile_statez#_AbstractLoad.process_compile_state  sU    ,,??//]//00 E!11DDD		
re   c                    t               )zimplemented by subclassesr   )r[   r   r   raiseerrs       rc   r   z_AbstractLoad._process  r   re   c                   d}t        t        ||j                              D ]  \  }\  }}t        |t              r\|dk(  r4|j                  dt               s|j                  dt               r|c S |t         dt         k7  r||j                  k7  r y ||u rzt        |t              r(t        |      rt        |      r|j                  |      r y  ||dz   d  S )Nr   :r   )	enumeratezipnatural_pathrS   rT   endswithr   r   r1   r   r   r   isa)r   to_choppathdebugic_tokenp_tokens          rc   
_chop_pathz_AbstractLoad._chop_path  s     %.**+&
 	!A! '3'6$$q(8%9:''!O+<(=>"N"5!6a7HII7;;.'!7N3"7+"7+KK( 5	6 q1uwre   )NFF)
r\   	_AttrTyper]   zOptional[_FromClauseArgument]r^   rH   r_   rH   returnr/   )rn   r   rg   rH   r   r/   r   )r\   r   rr   Optional[bool]r   r/   )r\   r   r   r/   )r\   r   r~   Optional[int]r   r/   )F)r\   r   r   rH   r   r/   )r   r   rg   rH   r   r/   )r   r   r   r/   )r   rT   r   r/   )r   r   r   _ColumnExpressionArgument[Any]r   r/   )r   Iterable[Type[Any]]r   r/   )r   _StrategySpecr   r;   )r   zLiteral[None]r   None)r   Optional[_StrategySpec]r   Optional[_StrategyKey])TNN)r\   r   r   r   rG   rH   rQ   Optional[_OptsType]rR   r   r   r/   )NN)
rn   Tuple[_AttrType, ...]r   r   rQ   r   r   Optional[Tuple[Any, ...]]r   r/   )rn   r   r   r   rR   r   r   r/   )r   r   rQ   	_OptsTyper   r/   r   Loadr   r   rQ   rF   r   r/   NNTNNrn   zOptional[Tuple[_AttrType, ...]]r   r   r   Optional[_WildcardKeyType]rQ   r   r   Optional[_AttrGroupType]rG   rH   r   r   r   r   r   r/   )r   r9   r   Sequence[_MapperEntity]r   r   )r   r9   r   r   r   r9   r   r   r   rH   r   r   )r   r?   r   r   r   rH   r   zOptional[_PathRepresentation])$__name__
__module____qualname__	__slots___is_strategy_option__annotations__rd   rp   rv   r{   r   r   r   r   rg   r   r   r   r   r   r   r
   r   r,   rZ   rm   r   r   r   r   r   r   r   r   classmethodr   r   re   rc   rF   rF   Z   s   )I
 04&+FF -F 	F
  $F 
FP >C I\ %)`` "` 
	`DKH *.8
8
 '8
 
	8
tI& *.// '/ 
	/bI4$
L%;N:;x*
X
B%
%
 3%
 
	%
N2 I IA A/	 
 &*$(.2 * #	
 " , 
 ( 
 %)48$ * "	
 2 
 & 
 /3	$   ,	
 
   %-6	 $$ %)/3%)-148$.$ )$ 1	$
 "$ -$ #$ +$ 2$ 
$
&
 1
 
	
"	
$&$ 1$ 	$
 
$ 
 	# $#  #  	# 
 
'#  # re   rF   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gZdZded<   d	ed<   d
ed<   ddZddZe	 	 	 	 dd       Z	 	 	 	 	 	 ddZddZddZd Z	 	 	 	 	 	 	 	 ddZddZed d       Z	 	 	 	 	 d!	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d"dZd Zd Zy)#r   a  Represents loader options which modify the state of a
    ORM-enabled :class:`_sql.Select` or a legacy :class:`_query.Query` in
    order to affect how various mapped attributes are loaded.

    The :class:`_orm.Load` object is in most cases used implicitly behind the
    scenes when one makes use of a query option like :func:`_orm.joinedload`,
    :func:`_orm.defer`, or similar.   It typically is not instantiated directly
    except for in some very specific cases.

    .. seealso::

        :ref:`orm_queryguide_relationship_per_entity_wildcard` - illustrates an
        example where direct use of :class:`_orm.Load` may be useful

    )r   contextadditional_source_entitiesr   r  rG   r  Nr   zTuple[_LoadElement, ...]z$Tuple[_InternalEntityType[Any], ...]c                    t        dt        |            }|j                   |j                  | _        d| _        d| _        d| _        y )Nz$Union[Mapper[Any], AliasedInsp[Any]]r   F)r   r%   _post_inspect_path_registryr   r  rG   r  )r[   entityinsps      rc   __init__zLoad.__init__  s@    :GFOL''	$)!*,'re   c                (    d| j                   d    dS )NLoad(r   ))r   r[   s    rc   __str__zLoad.__str__  s    tyy|nA&&re   c                `    | j                  |       }||_        d|_        d|_        d|_        |S )Nr   F)__new__r   r  rG   r  )r   r   loads      rc   _construct_for_existing_pathz!Load._construct_for_existing_path  s5     {{3	$)!*,'re   c                0    || u r| S | j                  |      S r   )_adjust_for_extra_criteria)r[   r  uncached_opts      rc   '_adapt_cached_option_to_uncached_optionz,Load._adapt_cached_option_to_uncached_option  s"     4K..w77re   c                n    | j                         }t        fd| j                  D              |_        |S )Nc              3  @   K   | ]  }|j                          y wr   )_prepend_path)r   elementr   s     rc   r   z%Load._prepend_path.<locals>.<genexpr>'  s!      
,3G!!$'
   )_cloner   r  r[   r   rb   s    ` rc   r  zLoad._prepend_path%  s2     
7;||
 
 re   c                `   | j                   D ]  }|j                  s n | S |j                  j                         | S |j                  j
                  }|j                         J 	 	 	 	 	 	 	 	 dd| j                         }t        fd| j                   D              |_         |S )zApply the current bound parameters in a QueryContext to all
        occurrences "extra_criteria" stored within this ``Load`` object,
        returning a new instance of this ``Load`` object.

        c                r    | j                         }t        fd|j                  D              |_        |S )Nc              3  B   K   | ]  }j                  |        y wr   )_apply_params_to_element)r   critorig_cache_keyreplacement_cache_keys     rc   r   zCLoad._adjust_for_extra_criteria.<locals>.process.<locals>.<genexpr>L  s+      /  &>>"D/s   )r   r   _extra_criteria)optr(  r'  
cloned_opts    `` rc   processz0Load._adjust_for_extra_criteria.<locals>.processE  s:    
 J). / '66	/ *J& re   c              3  N   K   | ]  }|j                   r
 |      n|  y wr   )r)  )r   valuer'  r,  r(  s     rc   r   z2Load._adjust_for_extra_criteria.<locals>.<genexpr>V  s8      
  (( 4nE
s   "%)r*  _LoadElementr(  rC   r'  rC   r   r/  )r  r)  query_generate_cache_keyr   select_statementr   r   )r[   r  r.  
orig_queryrb   r'  r,  r(  s        @@@rc   r  zLoad._adjust_for_extra_criteria,  s     \\ 	E$$	 K ' A A C (K**;;
#779)))		#+	 %	 		   
 
 
 re   c           	         | j                   }d}|D ]8  }|j                  }|st        j                  |t	        d|d               s6|c S  y)zocalled at process time to allow adjustment of the root
        entity inside of _LoadElement objects.

        Nz_InternalEntityType[Any]r   )r   entity_zeroorm_util_entity_corresponds_tor   )r[   r   r   r   ezeroents         rc   !_reconcile_query_entities_with_usz&Load._reconcile_query_entities_with_us`  sZ    
 yy" 	COOE88 /a9	 	 re   c                    | j                  ||      }t        |j                  j                        }| j                  D ]&  }|r|j
                  s|j                  | ||||       ( y r   )r:  rH   r   _current_pathr  rG   r   )r[   r   r   r   reconciled_lead_entityhas_current_pathru   s          rc   r   zLoad._processt  ss     "&!G!GX"

   = = K KLll 	F  (C(C((&	re   c                   | j                         j                  | j                  k(  sJ t        fdj                  j	                  d      fj
                  z   D              slt        j                        dkD  rj                  d   }j                  d   }nj                  d   }j                  d   }t        j                  ||       t        j                  j                  dd j                  dd z         _        | j                  r#t        fd| j                  D              _
        j                  r?xj                  j                  z  c_
        xj
                  j
                  z  c_        yy)zapply this :class:`_orm.Load` object as a sub-option of another
        :class:`_orm.Load` object.

        This method is used by the :meth:`_orm.Load.options` method.

        c              3  |   K   | ]3  }t        j                  |j                  j                  d              5 ywr   Nr6  $_entity_corresponds_to_use_path_implr   odd_element)r   elemrb   s     rc   r   z(Load._apply_to_parent.<locals>.<genexpr>  s:      
  99fkk--a0
   9<r   r   r   Nc              3  @   K   | ]  }|j                          y wr   )_prepend_path_from)r   r.  r   s     rc   r   z(Load._apply_to_parent.<locals>.<genexpr>  s!      #5:((0#r  )	_generaterG   anyr   rD  r  len_raise_for_does_not_linkr   coercer  r   )r[   r   attrnameparent_entityrb   s    `  @rc   r   zLoad._apply_to_parent  sA    !**d.G.GGGG 
  0046//0	
 
 6;;!#!;;q> &A!;;q> &A$V[[(MJ"))&++a*;fkk!n*LM<<" #>Bll# FN >>NNfnn,N--11- re   c                    |D ]  }	 |j                  |         | S # t        $ r0}t        |t              st	        j
                  d| d      | d}~ww xY w)ac  Apply a series of options as sub-options to this
        :class:`_orm.Load`
        object.

        E.g.::

            query = session.query(Author)
            query = query.options(
                        joinedload(Author.book).options(
                            load_only(Book.summary, Book.excerpt),
                            joinedload(Book.citations).options(
                                joinedload(Citation.author)
                            )
                        )
                    )

        :param \*opts: A series of loader option objects (ultimately
         :class:`_orm.Load` objects) which should be applied to the path
         specified by this :class:`_orm.Load` object.

        .. versionadded:: 1.3.6

        .. seealso::

            :func:`.defaultload`

            :ref:`orm_queryguide_relationship_sub_options`

        zLoader option z2 is not compatible with the Load.options() method.N)r   AttributeErrorrS   rF   sa_excArgumentError)r[   rQ   r*  aes       rc   r   zLoad.options  sw    >  
	C	$$T*
	  " !#}5 ..( .1 1 
 s   	A+AAc	                    |rd| _         | j                  j                  rt        j                  d      t        | j                        rm|r>| j                  j                  j                  | j                  j                  |d          n-t        j                  d| j                  j                   d      |ht        j                  | j                  d |||||||	      }	|	r<| xj                  |	fz  c_
        |J | xj                  t        d|d         z  c_        | S |D ]  }
t        |
t              r)t        j                  | j                  |
|||||||	      }	n(t         j                  | j                  |
|||||||	      }	|	sg|t"        u r|	j                  | _        | xj                  |	fz  c_
        |	j$                  j'                  d	d
      s|	j)                         }| xj                  |fz  c_
         | S )NT3Wildcard token cannot be followed by another entityr   zMapped attribute 'z#' does not refer to a mapped entity)r   r   r   zTuple[_InternalEntityType[Any]]r   r~   F)rG   r   is_tokenrR  rS  r   prop_strategy_lookup_ClassStrategyLoadcreater  r  r   rS   rT   _TokenStrategyLoad_AttributeStrategyLoadr1   
local_optsget_recurse)r[   rn   r   r   rQ   r   rG   r   r   load_elementr\   r1s               rc   r   zLoad._clone_for_bind_strategy  s     (,D%99&&E  dii( 		//		L**((8 9/ / 
 =-44		$%#5- 5 
L /'''//45tJ7G4 /\ S  '.dC(#5#<#<		 $,#-+='5 $= 
$L $:#@#@		 $,#-+='5 $A 
$L   $'::$0$5$5	LL\O3L $..223DeL)224-O'.R re   c                `    | j                         }| j                  j                         |d<   |S Nr   _shallow_to_dictr   	serializer[   ds     rc   __getstate__zLoad.__getstate__G  +    !!#II'')&	re   c                \    t        j                  |d         |d<   | j                  |       y rd  r   deserialize_shallow_from_dictr[   states     rc   __setstate__zLoad.__setstate__L  (    $00v?f&re   )r  _EntityType[Any])r   rT   )r   r   r   r   )r  r:   r  r=   r   r=   )r   r   r   r   )r  r:   r   r   r   r   r   r   r   )r   r   r   __doc__r  r+   ExtendedInternalTraversaldp_has_cache_keyInternalTraversaldp_has_cache_key_list
dp_boolean_traverse_internals_cache_key_traversalr  r  r  r  r  r  r  r  r:  r   r   r,   r   r   rj  rr  r   re   rc   r   r     s    I 
33DDE&&<<	
 
 !;!;!F!FG(&&<<	
  
%% DD-' )	 8#83<8	82h(& 1 	
 
@%N ) )` %)/3%)-148^.^ )^ 1	^
 "^ -^ #^ +^ 2^ 
^@
'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gZ	dZ
ded<   d	ed<   d
ed<   ded<   dZddZ	 	 	 	 	 ddZddZddZd Z	 	 	 	 	 	 	 	 ddZddZddZy)_WildcardLoadz)represent a standalone '*' load operation)r   r   r^  r   r   r^  NrB   cache_key_traversalr   r   zUnion[Tuple[()], Tuple[str]]Fc                J    d| _         d | _        t        j                  | _        y )Nr   )r   r   r   rt   r^  r  s    rc   r  z_WildcardLoad.__init__e  s    	//re   c	                    |J |d   }	|rt        |	t              r|	t        t        fv sJ | d|	 }	|| _        |	f| _        |rt        j                  |      | _        |J y )Nr   r   )	rS   rT   r   r   r   r   r   immutabledictr^  )
r[   rn   r   r   rQ   r   rG   r   r   r\   s
             rc   r   z&_WildcardLoad._clone_for_bind_strategyj  s        Qx4%.99	
:
 q' G	"006DO%%%re   c                    t        d      )Nz(Star option does not support sub-optionsr   r   s     rc   r   z_WildcardLoad.options  s    !"LMMre   c                   | j                   sJ | j                   d   }|j                  t              r|j                  d      d    dt         }t        t        |j                         j                  |      }|j                  sJ t        j                  |d| j                  d| j                  | j                        }|xj                  |fz  c_        y)aP  apply this :class:`_orm._WildcardLoad` object as a sub-option of
        a :class:`_orm.Load` object.

        This method is used by the :meth:`_orm.Load.options` method.   Note
        that :class:`_orm.WildcardLoad` itself can't have sub-options, but
        it may be used as the sub-option of a :class:`_orm.Load` object.

        r   r   N)r   r   r   splitr   r   r   tokenrW  r\  r[  r   r^  rG   r  )r[   r   r\   effective_pathru   s        rc   r   z_WildcardLoad._apply_to_parent  s     yyyyy|==(jjoa()?*;<D4fkkBHHN&&&&#**MMOO%%
 	6)#re   c           	        |j                   j                  }|r| j                  sy |D cg c]  }|j                   }}|j                  }| j
                  }|r| j                  ||      }	|	y |	|k(  sJ |rt        |      dk(  sJ |d   }
t        |
t              sJ | j                  ||
|      }|sy |}t        |
t              sJ t        j                  |j                  |
| j                  d | j                  | j                  |      }|sy |j
                  j                   sJ |j#                  | ||d |       |S c c}w )Nr   r   )r   )r   r   rG   r5  r   r   r   rK  rS   rT   _find_entity_basestringr\  r[  r
  r   r^  rW  r   )r[   r   r   r   
is_refreshr9  r   r   
start_pathnew_pathr  r  path_elementru   s                 rc   r   z_WildcardLoad._process  s\   "22EE
d77/>?COO??$11*.))
 z<@H z))) c*o2221%%%%--hxH %%%%#**''MMOO%% + 
 {{#### 	$$-$	
 k @s   D>c           	     n   |j                  dt               rat        t        |            dk7  ra|r_t	        j
                  ddj                  d |D               ddj                  d |D               d      |j                  t              rd	}|D ]  }|c S  |rt	        j
                  d
| d      y )Nr   r   zMCan't apply wildcard ('*') or load_only() loader option to multiple entities , c              3  2   K   | ]  }t        |        y wr   )rT   r   r9  s     rc   r   z8_WildcardLoad._find_entity_basestring.<locals>.<genexpr>  s     $B#SX$Br   z?. Specify loader options for each entity individually, such as c              3  (   K   | ]
  }d | d  yw)r  z).some_option('*')Nr   r  s     rc   r   z8_WildcardLoad._find_entity_basestring.<locals>.<genexpr>  s"      &$' #(u,> ?&s   .FzFQuery has only expression-based entities - can't find property named "".)r   r   rK  listrR  rS  joinr   )r[   r   r  r   r9  s        rc   r  z%_WildcardLoad._find_entity_basestring  s     >>Ao./04>"a' ..>99$B$BBC DP !II &+3& 
 	  ^^N+H 	C J		 **338'= 
 re   c                &    | j                         }|S r   )rf  rh  s     rc   rj  z_WildcardLoad.__getstate__	  s    !!#re   c                &    | j                  |       y r   )ro  rp  s     rc   rr  z_WildcardLoad.__setstate__  s    &re   r   r   r   r   r   )r   z"Iterable[_InternalEntityType[Any]]r  rT   r   rH   r   z"Optional[_InternalEntityType[Any]]r   Dict[str, Any]rq  r  r   r   )r   r   r   ru  r  r+   rv  dp_plain_objdp_string_multi_dictr{  r  r  rG   r  r   r   r   r   r  rj  rr  r   re   rc   r~  r~  Q  s    32I 
X77DDE	33@@A..CC	
 37/6''
&& * !&8N$:;z$4$ $ 	$
 
,$L're   r~  c                  v   e Zd ZU dZ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gZd
Zded<   ded	<   ded<   ded<   ded<   ded<   ded<   ded<   d%dZd Zed&d       Zd'dZd'dZd(dZd)dZd Z	 	 	 	 	 	 d*dZd Zd Zd Ze	 	 	 	 d+	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d,d       Zd-d Zd.d!Z d/d"Z!d0d#Z"e#	 	 	 	 	 	 d1d$       Z$y
)2r/  aA  represents strategy information to select for a LoaderStrategy
    and pass options to it.

    :class:`._LoadElement` objects provide the inner datastructure
    stored by a :class:`_orm.Load` object and are also the object passed
    to methods like :meth:`.LoaderStrategy.setup_query`.

    .. versionadded:: 2.0

    )r   r   rG   r^  r)  rR   ra  r   r   r^  r)  rG   rR   NzTuple[Any, ...]r   r   r   rH   zutil.immutabledict[str, Any]is_token_strategyis_class_strategyc                    t        |       S r   )r   r  s    rc   __hash__z_LoadElement.__hash__B  s    $xre   c                .    t        j                  | |      S r   )r*   compare)r[   others     rc   __eq__z_LoadElement.__eq__E  s    !!$..re   c                L    t        | j                  xr | j                  d u       S r   )rH   r^  r   r  s    rc   is_opts_onlyz_LoadElement.is_opts_onlyH  s    DOO=(=>>re   c                b    | j                   }|j                  |      }| j                  |       |S r   )	__class__r  _shallow_copy_to)r[   kwr   ss       rc   r   z_LoadElement._cloneL  s,    nnKKa re   c                f    | j                         }|j                  j                  |      |_        |S r   )r   r^  union)r[   r  news      rc   _update_optsz_LoadElement._update_optsS  s(    kkm--b1
re   c                `    | j                         }| j                  j                         |d<   |S rd  re  rh  s     rc   rj  z_LoadElement.__getstate__X  rk  re   c                \    t        j                  |d         |d<   | j                  |       y rd  rm  rp  s     rc   rr  z_LoadElement.__setstate__]  rs  re   c           	         |j                   }d}|D ]  }|j                  }|sd} n |st        j                  d|d    d      t        j                  d|d    ddj	                  d	 |D               d
      )NFTzGQuery has only expression-based entities; attribute loader options for r   z can't be applied here.zMapped class z@ does not apply to any of the root entities in this query, e.g. r  c              3  ^   K   | ]%  }|j                   rt        |j                          ' y wr   )r5  rT   )r   xs     rc   r   z3_LoadElement._raise_for_no_match.<locals>.<genexpr>v  s'      AMM AMM*s   +-zV. Please specify the full path from one of the root entities to the target attribute. )r   r5  rR  rS  r  )r[   parent_loaderr   r   found_entitiesr9  r8  s          rc   _raise_for_no_matchz _LoadElement._raise_for_no_matcha  s    !!" 	COOE!%		 &&004Qy 9##  &&Qy )5 II !0 	 re   c                    t         j                  |j                  |      }|syt        |      t        |      z
  }| j                  |   }t        j                  |f|dd z         }|S )a  receives the 'current_path' entry from an :class:`.ORMCompileState`
        instance, which is set during lazy loads and secondary loader strategy
        loads, and adjusts the given path to be relative to the
        current_path.

        E.g. given a loader path and current path::

            lp: User -> orders -> Order -> items -> Item -> keywords -> Keyword

            cp: User -> orders -> Order -> items

        The adjusted path would be::

            Item -> keywords -> Keyword


        Nr   )r   r   r   rK  r   r   rM  )r[   r  r   chopped_start_pathtokens_removed_from_start_pathloader_lead_path_elements         rc   '_adjust_effective_path_for_current_pathz4_LoadElement._adjust_effective_path_for_current_path  s~    ( "__''
 "),^)<s@
 *
& $(99-K#L %,,%'*<QR*@@
 re   c                    t               )zApply ORM attributes and/or wildcard to an existing path, producing
        a new path.

        This method is used within the :meth:`.create` method to initialize
        a :class:`._LoadElement` object.

        r   r[   r   r\   r   r   r   r   s          rc   
_init_pathz_LoadElement._init_path  s     "##re   c                    t               )zimplemented by subclasses.r   )r[   r  r   r   r=  r   s         rc   _prepare_for_compile_statez'_LoadElement._prepare_for_compile_state  s     "##re   c                    | j                  |||||      }|D ]P  }||j                  v r1t        j                  | |j                  |         |j                  |<   B| |j                  |<   R y)z^populate ORMCompileState.attributes with loader state for this
        _LoadElement.

        N)r  
attributesr/  
_reconcile)r[   r  r   r   r=  r   keysr   s           rc   r   z"_LoadElement.process_compile_state  s     .."
  	5Cm...0<0G0G-22371((- 15((-	5re   c                h   | j                  |       }||_        ||_        ||_        |rt	        j
                  |      nt        j                  |_        d|_        |	|	|_	        n|
|sd|_	        nd|_	        |j                  ||||||
      }|sy|j                  |j                  k(  sJ ||_        |S )z+Create a new :class:`._LoadElement` object.r   NT)r  r   r   rG   r   r  rt   r^  r)  rR   r  r  rW  )r   r   r\   r   r   r^  rG   r   r   r   r   r*  s               rc   r[  z_LoadElement.create  s      kk##7 .8Dz*doo 	 !)&8C#j&*C#&*C#~~$j(N
 $$555
re   c                    t               r   r   r  s    rc   r  z_LoadElement.__init__  s    !##re   c                    | j                         }t        j                  | j                  d d  | j                  dd  z         |_        |S )N)r   r   rM  r   )r[   rb   s     rc   r`  z_LoadElement._recurse  s;    "))$))A,23*GHre   c                    t         fd|j                  j                  d      f|j                  z   D              s6t	        j
                  d j                  d    d|j                  d    d       j                  |j                        S )a%  adjust the path of this :class:`._LoadElement` to be
        a subpath of that of the given parent :class:`_orm.Load` object's
        path.

        This is used by the :meth:`_orm.Load._apply_to_parent` method,
        which is in turn part of the :meth:`_orm.Load.options` method.

        c              3  |   K   | ]3  }t        j                  |j                  j                  d              5 ywrA  rB  )r   rE  r[   s     rc   r   z2_LoadElement._prepend_path_from.<locals>.<genexpr>  s;      

 	 99		%%a(
rF  r   zAttribute "r   z" does not link from element "r  )rJ  r   rD  r  rR  rS  r  r   s   ` rc   rH  z_LoadElement._prepend_path_from  s      

  0046//0
 
 &&diil^ ,!!'R 15 
 !!&++..re   c                "   | j                         }|j                  | j                  k(  sJ |j                  | j                  k(  sJ |j                  | j                  k(  sJ t	        j
                  |dd |j                  d d  z         |_        |S )Nr   r   )r   r   r^  r  r   rM  r   r!  s      rc   r  z_LoadElement._prepend_path%  s    $--///  DOO333''4+A+AAAA"))$q*v{{1~*EFre   c                    | j                   r|S | j                   du r| S |j                   r| S |j                   du r|S || u r| S |j                  | j                  k(  r|j                  | j                  k(  r| S | j                  r[|j	                         }|j                  j                  | j                        |_        |xj                  | j                  z  c_        |S |j                  r[| j	                         } | j                  j                  |j                        | _        | xj                  |j                  z  c_        | S | j                  j                  r| S t        j                  d| j                   d      )a  define behavior for when two Load objects are to be put into
        the context.attributes under the same key.

        :param replacement: ``_LoadElement`` that seeks to replace the
         existing one

        :param existing: ``_LoadElement`` that is already present.

        FzLoader strategies for z	 conflict)rR   r   r^  r  r   r  r)  r   rW  rR  InvalidRequestError)replacementexistings     rc   r  z_LoadElement._reconcile0  sn   " **O,,5))))U2O{"!5!55##{'='==%%(H"*"5"5";";&&#H $$(C(CC$O""%,,.K%0%;%;%A%A##&K" ''8+C+CC'&& (($[%5%5$6i@
 	
re   )r   int)r   rH   )r  r   r   r/  r  r  )r  r   r   r   r   Optional[PathRegistry])TNNN)r   r   r\   z%Union[_AttrType, _StrPathToken, None]r   r   r   r   r^  r   rG   rH   r   rH   r   r   r   r   r   r   r   r/  r  )r   r/  )r   r   r   r/  )r   r   r   r/  )r  r/  r  r/  r   r/  )%r   r   r   ru  r  __visit_name__r+   rv  rw  r  r  rx  dp_clauseelement_listr{  r|  r  r  r  propertyr  r   r  rj  rr  r  r  r  r  r   r  r[  r  r`  rH  r  staticmethodr  r   re   rc   r/  r/    s   	I $N 
33DDE	X77DDE..CC	
 
H66LLM	!;!;!H!HI	 : : G GH
  $$''$$
,,/ ? ?

'<$*$:F$	$L
$	$56  /3-148)) 4) )	)
 1) () #) ) -) +) 2) 
) )V$/2	 6
!6
-96
	6
 6
re   r/  c                       e Zd ZU dZdZdZej                  dej                  j                  fdej                  j                  fgz   Zded<   ded<   dZdZd	 Zd
 Zd Zd Z fdZ fdZ xZS )r]  zLoader strategies against specific relationship or column paths.

    e.g.::

        joinedload(User.addresses)
        defer(Order.name)
        selectinload(User.orders).lazyload(Order.items)

    )rM   _path_with_polymorphic_pathattribute_strategy_load_elementrM   r  z*Union[Mapper[Any], AliasedInsp[Any], None]r  Fc                   |J d | _         d | _        t        |      \  }}}	|j                  r!|}	||	   }|j                  r|j
                  }|S |j                  sJ t        j                  |d   |j                        sB|r?|r||d   urt        j                  d      t        |t        |      |j                         ny |r|j                  rJ || _        n|j                  | _        t        |dd       r;|j                   }
t!        |
      }|| _         |j
                  |	   | _        ||	   |   }n||	   }|j                  r|j
                  }|S )Nr   r   zCan't apply wildcard ('*') or load_only() loader option to multiple entities in the same option. Use separate options per entity.rM   )rM   r  _parse_attr_argumentis_property
has_entityentity_pathis_attributer6  rC  r   rR  rS  rL  rT   r)  rX   r%   )r[   r   r\   r   r   r   r   r  _rX  acext_infos               rc   r  z!_AttributeStrategyLoad._init_path  sa    +/(,T2a
 D:D''K""5 <<Hdkk
 $jm"; ..H  -T3t9dkkJ ++++#1D #'#7#7D 4T*Br{H$DM/3/?/?/ED,:h'D :D??##Dre   c                    | j                   sJ d       |j                  j                  }|j                  }|j	                         }|j	                         }|j                  |t        | j                          S )a  Apply the current bound parameters in a QueryContext to the
        immediate "extra_criteria" stored with this Load object.

        Load objects are typically pulled from the cached version of
        the statement from a QueryContext.  The statement currently being
        executed will have new values (and keys) for bound parameters in the
        extra criteria which need to be applied by loader strategies when
        they handle this criteria for a result set.

        z8this should only be called if _extra_criteria is present)r)  r   r2  r0  r1  r%  r&   )r[   r  r3  current_queryk1k2s         rc   _generate_extra_criteriaz/_AttributeStrategyLoad._generate_extra_criteria  sw       	FE	F  **;;
 ++-..0**2tT5I5I/JKKre   c                   | j                   sJ | j                  }|sJ |j                  sKt        t        j
                  j                  |j                  j                  |j                  fdd            }| j                   }|r| j                  ||      }|y |}d|j                  f}||v r||   }|}|j                  |      }	|	||<   y |||<   y )NT)aliased_use_mapper_pathpath_with_polymorphic)r  rM   is_aliased_classr%   r6  r!   _with_polymorphic_factorymapperbase_mapperr  r   _merge_with)
r[   r  r   pwpir  r  r   existing_aliased_inspthis_aliased_inspnew_aliased_insps
             rc   _set_of_type_infoz(_AttributeStrategyLoad._set_of_type_info  s    ////}}t$$$$>>KK++[[N %)	 ? D 55
CCLH !J&
(?(?@'>$+CL! $4@@!  ,GCLGCLre   c                *   |j                   }|j                  j                  }| j                  j                  rJ |r| j
                  sg S | j                  r| j                  |j                  |       | j                  s| j                  sg S |r|s| j                  ||       | j                  j                  r| j                  j                  }n| j                  }|r|J | j                  ||      }|g S dt        t         |      j"                  fgS Nru   )r   r   r   r   rW  rG   rM   r  r  r   r^  r  r  r   r  r   r   r   )	r[   r  r   r   r=  r   r   r  r  s	            rc   r  z1_AttributeStrategyLoad._prepare_for_compile_state  s     %11"22EE
99%%%%d77I== ""=#;#;\J }}T__I2$$]OD99!YY--N!YYN!---!IIN %	4n=JJKLLre   c                B   t         |          }d|d<   | j                  r| j                  j                         |d<   | j                  rU| j                  j
                  rd |d<   |S | j                  j                  r| j                  j                  |d<   |S J d       |S )Nr   r)  r  rM   zunexpected object for _of_type)superrj  r  rg  rM   r  	is_mapperclass_)r[   ri  r  s     rc   rj  z#_AttributeStrategyLoad.__getstate__A  s    G "  "
++00::< +, ==}}-- $*  (( $ 4 4*  ?>>ure   c                    t         |   |       |j                  dd       rt        j                  |d         | _        nd | _        |j                  dd       rt        |d         | _        y d | _        y )Nr  rM   )r  rr  r_  r   rn  r  r%   rM   )r[   rq  r  s     rc   rr  z#_AttributeStrategyLoad.__setstate__Y  sk    U#992D9/;/G/G340D, 04D,99Z&#E*$56DM DMre   )r   r   r   ru  r  r  r/  r{  r+   rv  dp_multirw  r  r  r  r  r  r  r  rj  rr  __classcell__)r  s   @rc   r]  r]  j  s     <I6N&::	X77@@A)..??	
>  98!77EN#LJ  D*MX0! !re   r]  c                  ,    e Zd ZdZdZdZdZdZd Zd Z	y)r\  a  Loader strategies against wildcard attributes

    e.g.::

        raiseload('*')
        Load(User).lazyload('*')
        defer('*')
        load_only(User.name, User.email)  # will create a defer('*')
        joinedload(User.addresses).raiseload('*')

    token_strategy_load_elementTFc                    |]|j                  t              }|j                  t              s|r|r| d| }|j                  |      }|S t	        j
                  d      |S )Nr   kStrings are not accepted for attribute names in loader options; please use class-bound attributes directly.)r   r   r   r  rR  rS  )r[   r   r\   r   r   r   r   default_tokens           rc   r  z_TokenStrategyLoad._init_path|  sl      MM.9M}}_-*^1TF3Dzz$'**K  re   c                   |j                   }|j                  j                  }| j                  j                  sJ |r| j
                  sg S | j                  s| j                  sg S | j                  }|r&t        j                  |f|j                  dd  z         }|r| j                  ||      }	|	g S |	}t        t        |      j                         D 
cg c]  }
d|
f c}
S c c}
w )Nr   ru   )r   r   r   r   rW  rG   r   r^  r   rM  r  r   r   "_generate_natural_for_superclasses)r[   r  r   r   r=  r   r   r  r  new_effective_pathr   s              rc   r  z-_TokenStrategyLoad._prepare_for_compile_state  s     %11"22EE
yy!!!!d77I }}T__I!)00')N,?,?,CCN !%!M!M" ")	/N !>446
 |$
 	
 
s   C!N)
r   r   r   ru  r  inherit_cacher  r  r  r  r   re   rc   r\  r\  i  s)    
 3NM&0
re   r\  c                  ,    e Zd ZdZdZdZdZdZd Zd Z	y)rZ  zLoader strategies that deals with a class as a target, not
    an attribute path

    e.g.::

        q = s.query(Person).options(
            selectin_polymorphic(Person, [Engineer, Manager])
        )

    TFclass_strategy_load_elementc                    |S r   r   r  s          rc   r  z_ClassStrategyLoad._init_path  s	     re   c                   |j                   }|j                  j                  }|r| j                  sg S | j                  s| j
                  sg S | j                  }|r| j                  ||      }	|	g S |	}d|j                  fgS r  )	r   r   r   rG   r   r^  r   r  r   )
r[   r  r   r   r=  r   r   r  r  r	  s
             rc   r  z-_ClassStrategyLoad._prepare_for_compile_state  s     %11"22EE
d77I }}T__I!%!M!M" ")	/N>66788re   N)
r   r   r   ru  r
  r  r  r  r  r  r   re   rc   rZ  rZ    s)    	 M2N
9re   rZ  c                   d }d|dd fd|dd  ffD ]  \  }}|D ]  }t        |t              r|j                  dt        z         rt	        j
                  dd       |d	d  }|t        k(  r2|rt        j                  d
      |
t               } | |t        fi |}t        j                  d      |t        |      \  }}	}t        |	      }|r!|s|j                  |      } | ||fddi|} | ||fi |}  |sJ |S )NTr   r   Fr  zThe undocumented `.{WILDCARD}` format is deprecated and will be removed in a future version as it is believed to be unused. If you have been using this functionality, please comment on Issue #4390 on the SQLAlchemy project tracker.rJ   rK   r   rV  r  r^   )rS   rT   
startswithr   r   rW   rR  rS  r~  r   r  r   r   )
methr  chainedr  lead_element
is_default_keysr\   r  lead_entitys
             rc   _generate_from_keysr    sg    -1L #D2J/%bc1CC 1B
E 0	BD$$??3#89((# !&  8D?*!$22- 
 $+'4#'n#K#KL !../   '(<T(B%A{A#'#4L"'3'?'?'E'+($(:>(BD( $(d#Ab#ALa0	B1Bf <re   c                ,   	 t        |       }t	        |      r|j
                  }|}n9t        |      r|j
                  }|j                  }nt        j                  d      |||fS # t        j                  $ r}t        j                  d      |d}~ww xY w)a  parse an attribute or wildcard argument to produce an
    :class:`._AbstractLoad` instance.

    This is used by the standalone loader strategy functions like
    ``joinedload()``, ``defer()``, etc. to produce :class:`_orm.Load` or
    :class:`._WildcardLoad` objects.

    z:expected ORM mapped attribute for loader strategy argumentN)r%   rR  NoInspectionAvailablerS  r   r   r   rX  )r\   r  errr  rX  s        rc   r  r  :	  s      't} t$kk	4	 kkyy""H
 	
 d""% '' ""H
	s   A% %B8BBc                    t        t        | j                        }|j                  }d| j                   d| j                   d|_        || _        | S )zdecorator that applies docstrings between standalone loader functions
    and the loader methods on :class:`._AbstractLoad`.

    z=Produce a new :class:`_orm.Load` object with the
:func:`_orm.z#` option applied.

See :func:`_orm.z` for usage examples.

)rX   rF   r   ru  )fnbound_fnfn_docs      rc   loader_unbound_fnr  _	  sX    
 }bkk2HF[[M  H BJIre   c                 :    t        t        j                  | d|      S )NT)r  r   rd   r  r  s     rc   rd   rd   u	  s    t22D$CCre   Frf   c                \    t        |d         \  }}} t        |      j                  |d| iS )Nr   rg   )r  r   rp   )rg   rn   r  r  s       rc   rp   rp   z	  s6     .eAh7A|Q'4''D)DDre   c                 :    t        t        j                  | d|      S NF)r  r   rv   r!  s     rc   rv   rv   	  s    teR@@re   c                 :    t        t        j                  | di       S r$  )r  r   r{   r  s    rc   r{   r{   	  s    t00$rBBre   )r~   c                >    t        t        j                  |dd| i      S NFr~   )r  r   r   r~   r  s     rc   r   r   	  s&     4):O(L re   c                 :    t        t        j                  | di       S r$  )r  r   r   r&  s    rc   r   r   	  s    t}}dE2>>re   c                >    t        t        j                  |dd| i      S r(  )r  r   r   r)  s     rc   r   r   	  s&     D%*;_)M re   c                 :    t        t        j                  | di       S r$  )r  r   r   r&  s    rc   r   r   	  s    t{{D%<<re   c                 :    t        t        j                  | d|      S r$  )r  r   rg   r!  s     rc   rg   rg   	  s    t~~tUB??re   c                 :    t        t        j                  | di       S r$  )r  r   r   r&  s    rc   r   r   	  s    t//ubAAre   c                   |rt        j                  dd       |rd|i}ni }t        t        j                  | f|z   d|      S )Nz}The *addl_attrs on orm.defer is deprecated.  Please use method chaining in conjunction with defaultload() to indicate a path.1.3rK   rg   F)r   rW   r  r   r   )r   rg   
addl_attrsr  s       rc   r   r   	  sO      		
 9%tzzC6J+>rJJre   c                t    |rt        j                  dd       t        t        j                  | f|z   di       S )NzThe *addl_attrs on orm.undefer is deprecated.  Please use method chaining in conjunction with defaultload() to indicate a path.r0  rK   F)r   rW   r  r   r   )r   r1  s     rc   r   r   	  s;     		
 t||cVj-@%LLre   c                8    t               }|j                  |       S r   )r~  r   )r   r  s     rc   r   r   	  s    oG  &&re   c                @    t        t        j                  | fdd|i      S )NFr   )r  r   r   )r   r   s     rc   r   r   	  s'     sfelJ-G re   c                :    t        |       }|j                  |      S r   )r   r   )base_clsr   uls      rc   r   r   	  s     
hB""7++re   c                b   t        |       dkD  r| d   j                  | d   j                  j                  u}t	        |      rt        |      }n|j                  j                  }t        j                  d| d| d    d|r	d| d    dnd	|s|| d   j                  smt        j                  | j                  t        |      j                        r:d
| d    d| d| d   j                  j                  j                   d| d	fz        d	fz        t        j                  d| d| d    d      )Nr   r   r  z ORM mapped entity or attribute "z#" does not link from relationship "z%s".%sz	.of_type(r   z  Did you mean to use "z,)" or "loadopt.options(selectin_polymorphic(z, [z]), ...)" ?zORM mapped attribute "z" does not link mapped class "")rK  r  r  r  r   rT   r   rR  rS  r  r6  r7  r%   )r   rN  rO  path_is_of_typeparent_entity_strs        rc   rL  rL  	  sh   
4y1}r(//b1G1GG / #M 2 - 4 4 = ="".xj 9''+Bxj8 ,;)DH:Q' + H55 77W]%;%B%BRz 12 3,,0HOO,B,B,K,K+L M)*+	7
 	
  
 	
* ""$XJ /""&r(1.
 	
re   )
r  zCallable[..., _AbstractLoad]r  r   r  rH   r  r   r   rF   )r\   r   r   zDTuple[InspectionAttr, _InternalEntityType[Any], MapperProperty[Any]])r  r4   r   r4   )r  r   r  r   r   rF   )rn   r   rg   rH   r   rF   )r  r   r   rF   )r  r   r~   r   r   rF   )r   r   r1  r   rg   rH   r   rF   )r   r   r1  r   r   rF   )r   rT   r   rF   )r   r   r   r   r   rF   )r6  rt  r   r   r   rF   )sru  
__future__r   typingr   r   r   r   r   r	   r
   r   r   r   r   r   r9  r   r6  _typingr   r   r   r   r  r   baser   
interfacesr   path_registryr   r   r   r   r   r   r   r    r!   r#   rR  r%   sqlr&   r'   r(   r)   r*   r+   sql.baser,   util.typingr-   r.   r/   r1   r  r3   r4   TYPE_CHECKINGr6   r7   r  r8   r9   r:   r;   r<   r=   r  r>   r?   sql._typingr@   rA   sql.cache_keyrB   rC   r   _WildcardKeyTyperT   r   r   _AttrGroupTypeGenerativeOnTraversalrF   r   r~  HasCacheKeyHasShallowCopyTraversibler/  r]  r\  rZ  r  r  r  rd   rp   rv   r{   r   r   r   r   rg   r   r   r   r   r   r   rL  r   re   rc   <module>rO     s   #               * & # , *   $ ) ( * 1 + ' ( &           "  ! 6D 3 D*2' 2e/0	$,&(%(*%2716( '#, 99:	34 S#XcN	y#~&A J44l A Hp'= p'f}'M }'@V
:44h6J6JV
r
|!\ |!~V
 V
r59 59p=
&=
= = 		=
 =@"#
"#I"#J, D D 38 E E A A C C 7;'4  ? ? 7;'4  = = @ @ B B >CK	K!*K7;KK K& M M ' '
 	 >  ,,)<,, , 
re   