
    +h
                       d 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   G d de e      Z! G d de!      Z" G d de#      Z$ e$       d?d!       Z%e%jL                  d"        Z% e$       d#        Z'e'jL                  d$        Z' e$       d?d%       Z(e(jL                  d&        Z( e$       d'        Z)e)jL                  d(        Z) e$       d)        Z*e*jL                  d*        Z* e$       d+        Z+e+jL                  d,        Z+ e$       d-        Z,e,jL                  d.        Z, e$       d/        Z-e-jL                  d0        Z- e$       d@d1       Z.e.jL                  d2        Z. e$       d3        Z/e/jL                  d4        Z/ e$       d@d5       Z0e0jL                  d6        Z0 e$       d7        Z1e1jL                  d8        Z1 e$       d9        Z2e2jL                  d:        Z2 e$       d;        Z3e3jL                  d<        Z3 e$       d=        Z4e4jL                  d>        Z4y )Az

   )util)QueryableAttribute)_class_to_mapper)_is_aliased_class)_is_mapped_class)InspectionAttr)LoaderOption)MapperProperty)PropComparator)_DEFAULT_TOKEN)_WILDCARD_TOKEN)PathRegistry)TokenRegistry)_orm_full_deannotate   )excinspect)and_)	coercions)roles)
traversals)visitors)_generative)
Generativec                   D    e Z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ed
        Zd Zd Zd Zd Zed        Z fdZdZdZdZdZdZdZd Zd Z d Z!	 	 d&dZ"d Z#d Z$d Z%e&d        Z'e&	 d'd       Z(e&d(d       Z)e&d        Z*e&d        Z+	 d)d Z,d*d!Z-d" Z.d# Z/d$ Z0d% Z1 xZ2S )+Loada  Represents loader options which modify the state of a
    :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:`.defer`, or similar.   However, the :class:`_orm.Load` object
    can also be used directly, and in some cases can be useful.

    To use :class:`_orm.Load` directly, instantiate it with the target mapped
    class as the argument.   This style of usage is
    useful when dealing with a :class:`_query.Query`
    that has multiple entities::

        myopt = Load(MyClass).joinedload("widgets")

    The above ``myopt`` can now be used with :meth:`_query.Query.options`,
    where it
    will only take effect for the ``MyClass`` entity::

        session.query(MyClass, MyOtherClass).options(myopt)

    One case where :class:`_orm.Load`
    is useful as public API is when specifying
    "wildcard" options that only take effect for a certain class::

        session.query(Order).options(Load(Order).lazyload('*'))

    Above, all relationships on ``Order`` will be lazy-loaded, but other
    attributes on those descendant objects will load using their normal
    loader strategy.

    .. seealso::

        :ref:`deferred_options`

        :ref:`deferred_loading_w_multiple`

        :ref:`relationship_loader_options`

    Tpathstrategy_of_type_extra_criteria_context_cache_key
local_optsc                     t        |      }|j                   |j                  | _        t	        j
                         | _        i | _        d| _        y NF)	r   _post_inspect_path_registryr   r   OrderedDictcontextr#   is_class_strategy)selfentityinsps      R/var/www/html/venv/lib/python3.12/site-packages/sqlalchemy/orm/strategy_options.py__init__zLoad.__init__a   sB    v''	 '')!&    c                 n    | j                  |       }||_        i |_        i |_        d |_        d|_        |S N )__new__r   r)   r#   r    r!   )clsr   loads      r.   for_existing_pathzLoad.for_existing_pathl   s9    {{3	!r0   c                 $    | j                  |      S N)_adjust_for_extra_criteria)r+   r)   uncached_opts      r.   '_adapt_cached_option_to_uncached_optionz,Load._adapt_cached_option_to_uncached_optionv   s    ..w77r0   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!   compile_stateselect_statementquery_generate_cache_key_apply_params_to_elementr   )r+   r)   
orig_querycurrent_queryk1k2s         r.   _generate_extra_criteriazLoad._generate_extra_criteriay   sw       	FE	F  **;;
 ++-..0**2tT5I5I/JKKr0   c                 r    j                   j                  i }ddgfd}| j                  ||      S )zApply the current bound parameters in a QueryContext to all
        occurrences "extra_criteria" stored within al this Load object;
        copying in place.

        Nc                     | j                   sy d   -j                         j                  j                         fd d  \  t        fd| j                   D              | _         y )N    c              3   B   K   | ]  }j                  |        y wr9   )rB   ).0critrE   rF   s     r.   	<genexpr>zCLoad._adjust_for_extra_criteria.<locals>.process.<locals>.<genexpr>   s&      ( ++B5(   )r!   rA   r@   tuple)optrE   rF   ckr)   rC   s    @@r.   processz0Load._adjust_for_extra_criteria.<locals>.process   sj    &&!u}224MM5571 FB"' (//( #Cr0   )r>   r?   _deep_clone)r+   r)   appliedrS   rR   rC   s    `  @@r.   r:   zLoad._adjust_for_extra_criteria   s>     **;;
D\	  11r0   c                 V   | |v r||    S | j                         }||| <   | j                  |_        |j                  | j                  k(  sJ |j                  | j                  k(  sJ |j                  | j                  k(  sJ | j
                  rit        j                  | j
                  j                         D cg c]+  \  }}|t        |t              r|j                  ||      n|f- c}}      |_        |j                  j                  | j                          ||       |S c c}}w r9   )	_generater   propagate_to_loadersr*   is_opts_onlyr)   r   r(   items
isinstancer   rT   r#   update)r+   rU   rS   clonedkeyvalues         r.   rT   zLoad._deep_clone   s   7?4= !--**d.G.GGGG''4+A+AAAA""d&7&7777<<!-- '+ll&8&8&: #U %eT2 ))'7;"	
FN 	  1s   90D%
c                     g }| j                   g S | j                   j                         D ]#  \  \  }}}|dk7  r|j                  ||fz          % |S Nloader)r)   rZ   append)r+   
serializedr^   loader_pathobjs        r.   r"   zLoad._context_cache_key   sc    
<<I'+||'9'9'; 	4#S+hkSF23	4 r0   c                 :    t         t        |          }i |_        |S r9   )superr   rW   r#   )r+   r]   	__class__s     r.   rW   zLoad._generate   s    tT,.r0   FNr3   c                     |j                   j                  sy | j                  ||t        |j                                y r9   )compile_options_enable_eagerloads_processboolcurrent_path)r+   r>   mapper_entitiess      r.   'process_compile_state_replaced_entitiesz,Load.process_compile_state_replaced_entities   s;     ,,??
 	]//00	
r0   c                     |j                   j                  sy | j                  ||j                  t	        |j
                         xr |j                   j                          y r9   )rk   rl   rm   _lead_mapper_entitiesrn   ro   _for_refresh_state)r+   r>   s     r.   process_compile_statezLoad.process_compile_state  sU    ,,??//]//00 E!11DDD		
r0   c                 L   |j                   j                  }|j                  }|r[| j                  j	                         D ]=  \  \  }}}|r|j
                  s| j                  ||      }	|	-||j                  ||	f<   ? y |j                  j                  | j                         y r9   )	rk   rt   ro   r)   rZ   rX   
_chop_path
attributesr\   )
r+   r>   rp   raiseerr
is_refreshro   token
start_pathrb   chopped_start_paths
             r.   rm   zLoad._process  s    "22EE
$11/3||/A/A/C +#
Vf&A&A%)__Z%N"%1  ",, 23 $$++DLL9r0   c                 <	   | j                   }d | _         |rT|j                  sHt        |t              rt	        j
                  d      t	        j
                  d|j                  d      t        |t        j                        r|j                  t              }|}	|j                  t              s|rI|rd| _        |r|d|}|r|j                  s|j                  |   }|j                  |      }|| _        |S |rt#        |      }
n|j$                  }
t        j&                  d       	 t)        |
j*                  |      }	 |j,                  x}}||   }n]t#        |      }|j6                  s|j                  rMt9        j:                  |j                  |d         s|r&t	        j
                  d|d|j$                  d      y |j<                  r|x}}||   }n|j>                  r|j,                  x}}t9        j:                  |j                  |d         s|rt	        j
                  d|d|j$                  dtA        |      dkD  rR|j$                  j6                  r<|j                  j                  r&d|d   d|j*                  jB                  d      d      y |jD                  r| jD                  s|jD                  | _"        t)        |dd       r|j                   }t#        |      x}}|| jF                  }|jH                  |   jK                  |d      }|j                  sPt9        jL                  |jN                  jP                  |jN                  dd|t#        |      nd       }t#        |      }|jH                  |   jS                  |d|       ||   |   }|| _         n||   }|jU                  |       |j                  r|jH                  }|| _        |S # t.        $ rZ}t        |t0              s>t        j2                  t	        j
                  d|	d|
d	t5        |      d
      |       n Y d }~d }~ww xY w# t.        $ rD}|r2t        j2                  t	        j
                  d|d|
d      |       nY d }~y Y d }~Fd }~ww xY w)Nz3Wildcard token cannot be followed by another entityzMapped attribute 'z#' does not refer to a mapped entityF:zUsing strings to indicate column or relationship paths in loader options is deprecated and will be removed in SQLAlchemy 2.0.  Please use the class-bound attribute directly.zExpected attribute "z" on z' to be a mapped attribute; instead got z object.)replace_contextzCan't find property named "z in this Query.zAttribute 'z' does not link from element ''zAttribute "z" does not link from element "".r   z  Did you mean to use z	.of_type(z)? r    path_with_polymorphicT)aliased_use_mapper_path_existing_alias)+r    
has_entityr[   r   sa_excArgumentErrorpropr   string_typesendswithr   r   rX   is_aliased_classparentr{   r   r   r,   warn_deprecated_20getattrclass_propertyAttributeErrorr
   raise_type	is_mapperorm_util$_entity_corresponds_to_use_path_implis_propertyis_attributelen__name__r!   r)   entity_pathgetwith_polymorphicmapperbase_mapperset_get_strategy)r+   r   attrfor_strategywildcard_keyry   polymorphic_entity_contextexisting_of_typedefault_tokenattr_str_nameentfound_propertyaeerrr-   r   acext_infoof_type_infoexistings                       r.   _generate_pathzLoad._generate_path  sZ     ==DOO$.**I  **26))> 
 dD--. MM.9M M}}_- 05D-&2D9D $,<,M,M;;'78Dzz$' 	./kk##6 szz40,0MM9D> :D4=D~~!6!6  DDKKb  $228<dkkK 
  $!!(,,~Dz""(,5~DDKKb  $22 !% $
 (+4y1}(,(=(=(,(D(D (,Bx1E1E%G %,  *,%, $  $''0D0D ,0+?+?D(4T2B.5bk9H|1959\\2#//59924K H $44%66$OO77$OO$(-1'3 -4H,=!% $+2;$$T*..24KR  :h/D$0DM  :D#((6??##D	Y & %dN;"00 $1#tDz!C -/  " 
 KK,,37> ),  
 s1   +Q O( (	Q1AQQ	R4RRc                 "    d| j                   dS )NzLoad(strategy=))r   r+   s    r.   __str__zLoad.__str__  s    &*mm55r0   c                 N    |"t        t        |j                                     }|S r9   )rP   sortedrZ   )r+   r   s     r.   _coerce_stratzLoad._coerce_strat  s#    VHNN$456Hr0   c                     t        d      )NzHOnly 'unbound' loader options may be used with the Load.options() method)NotImplementedError)r+   r   rU   bounds       r.   _apply_to_parentzLoad._apply_to_parent  s    !$
 	
r0   c           	      &   i }t        | t               }|rt        d      |D ]  }	 |j                  | ||        y# t        $ rJ}t        |t
              s/t        j                  t        j                  d|d      |       n Y d}~hd}~ww xY w)a  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:`relationship_loader_options`

            :ref:`deferred_loading_w_multiple`

        zMThe options() method is currently only supported for 'unbound' loader optionszLoader option z2 is not compatible with the Load.options() method.)from_N)
r[   _UnboundLoadr   r   r   r   r   r   r   r   )r+   optsapply_cacher   rQ   r   s         r.   optionszLoad.options  s    B t\22%/   	C$$T;>	 " 
!#t,KK,,8;> ! 
s   =	BA BBc                     | j                  |      }|| _        | j                  ||d      }|j                  | _        |j                  | _        |j
                  | _        dx|_        | _        |j                  | _        y )NrelationshipF)r   rX   _clone_for_bind_strategyr   r    r!   r*   )r+   r   r   rX   r]   s        r.   set_relationship_strategyzLoad.set_relationship_strategy  sr     %%h/$8!..tX~NKK	%55<AA 4#9$*$?$?!r0   c                 |    | j                  |      }d| _        |D ]  }| j                  ||d||      }d|_        ! y )NFcolumn)	opts_onlyr   T)r   r*   r   rX   )r+   attrsr   r   r   r   r]   s          r.   set_column_strategyzLoad.set_column_strategy$  sS    %%h/!& 	/D22hID 3 F +/F'		/r0   c                 h    | j                  |      }|D ]  }| j                  ||d       }d|_         y NT)r   r   rX   )r+   r   r   r   r]   s        r.   set_generic_strategyzLoad.set_generic_strategy.  s=    %%h/ 	/D2244HF*.F'	/r0   c                     | j                  |      }| j                  d |d       }d|_        d|_        |j                  j                  |       y r   )r   r   r*   rX   r#   r\   )r+   r   r   r]   s       r.   set_class_strategyzLoad.set_class_strategy5  sJ    %%h/..tXtD#' &*#  &r0   c                    | j                         }|j                  | j                  |||       ||_        | j                  |_        |r|j                  j                  |       |rd|_        |s|j                  r|j                          |S )a  Create an anonymous clone of the Load/_UnboundLoad that is suitable
        to be placed in the context / _to_bind collection of this Load
        object.   The clone will then lose references to context/_to_bind
        in order to not create reference cycles.

        T)rW   r   r   r   r#   r\   rY   _set_path_strategy)r+   r   r   r   r   r   r]   s          r.   r   zLoad._clone_for_bind_strategy=  sy     !diixF" OO$$T*"&Fv**%%'r0   c                    |s|sp|j                  |d      }|rG|rY|j                  j                  | j                         |xj                  | j                  z  c_        y |j	                  |d|        y y |j                  |d      }|j	                  |d|        |rR|j
                  rE| j                  j                  |j                         |xj                  | j                  z  c_        y y y ra   )r   r#   r\   r!   r   rY   )r+   r)   r   replace
merge_optsr   s         r.   _set_for_pathzLoad._set_for_pathT  s    Wxx2H''..t?,,0D0DD,(D1	  xx2HHHWh-H11&&x':':;((D,@,@@( 2xr0   c                    | j                   s-| j                  j                  r| j                  j                  }n| j                  }|j                  rF|j                         D ]+  }| j                  | j                  |d| j                         - d | _        y | j                  | j                  |d| j                         d | _        y )NTr   r   )	r*   r   r   r   is_tokengenerate_for_superclassesr   r)   rY   )r+   effective_pathr   s      r.   r   zLoad._set_path_strategyd  s    %%$))*>*>!YY--N!YYN""&@@B ""LL #00	 # "  ,,	   r0   c                     | j                   j                         }d|d<   |d   t        j                  |d   d      |d<   | j                  j                         |d<   |S )Nr3   r!   r)   )rb   r   )__dict__copyr   serialize_context_dictr   	serializer+   ds     r.   __getstate__zLoad.__getstate__~  se    MM   "
Y<#'>>)kAiL II'')&	r0   c                     | j                   j                  |       t        j                  | j                        | _        | j
                  %t        j                  | j
                        | _        y y r9   )r   r\   r   deserializer   r)   deserialize_context_dict)r+   states     r.   __setstate__zLoad.__setstate__  sO    U# ,,TYY7	<<#'@@NDL $r0   c                    d}t        t        ||j                              D ]  \  }\  }}t        |t        j
                        r>|dk(  r|j                  dt        z         r|c S |dt        k7  r||j                  k7  r y ||u rft        |t              r*|j                  r|j                  r|j                  |      r y  ||dz   d  S Nr   rJ   r   zrelationship:r   )	enumeratezipr   r[   r   r   r   r   r   r^   r   r   isa)r+   to_chopr   ic_tokenp_tokens         r.   rw   zLoad._chop_path  s    %.s7DII/F%G 	!A!'4#4#45 6g..s^/CD"NOEE7;;.'!7N3%%%%KK(/	0 q1uwr0   )TN)Tr%   )FN)TF)3r   
__module____qualname____doc___is_strategy_optionr   ExtendedInternalTraversaldp_has_cache_keydp_plain_objdp_multiInternalTraversaldp_clauseelement_listdp_has_cache_key_tuplesdp_string_multi_dict_cache_key_traversalr/   classmethodr7   r<   rG   r:   rT   r   r"   rW   rY   r*   r   rX   r    r!   rq   ru   rm   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rw   __classcell__)ri   s   @r.   r   r   %   s   (T  
33DDE	X77DDE	X77@@A	H66LLM ..FF	

 ..CC	
	'  8#LJ2<B  
 LH HO
	
:* #'sj6

 4 4l 37
@ 
@ / / / / ' ' CG.A 4O r0   r   c                   ~    e Zd ZdZd ZddZdZd Zd ZddZ	d	 Z
d
 Zd Zd Zed        Zd ZddZd Zd Zd Zy)r   a<  Represent a loader option that isn't tied to a root entity.

    The loader option will produce an entity-linked :class:`_orm.Load`
    object when it is passed :meth:`_query.Query.options`.

    This provides compatibility with the traditional system
    of freestanding options, e.g. ``joinedload('x.y.z')``.

    c                 <    d| _         g | _        i | _        d| _        y r2   )r   _to_bindr#   r!   r   s    r.   r/   z_UnboundLoad.__init__  s    	!r0   Nc                    t        |       }| j                  }|v r|   |fS |   }t        j                  }|
t	               ||f|j                  d| j                  |       z   d| j                  fz   | j                  r"dt        fd| j                  D              fndz   | j                  r!dt        fd| j                  D              fndz   | j                  r!|j                  d| j                  |       z   S dz   S )	aX  Inlined gen_cache_key

        Original traversal is::


            _cache_key_traversal = [
                ("path", visitors.ExtendedInternalTraversal.dp_multi_list),
                ("strategy", visitors.ExtendedInternalTraversal.dp_plain_obj),
                (
                    "_to_bind",
                    visitors.ExtendedInternalTraversal.dp_has_cache_key_list,
                ),
                (
                    "_extra_criteria",
                    visitors.InternalTraversal.dp_clauseelement_list),
                (
                    "local_opts",
                    visitors.ExtendedInternalTraversal.dp_string_multi_dict,
                ),
            ]

        The inlining is so that the "_to_bind" list can be flattened to not
        repeat the same UnboundLoad options over and over again.

        See #6869

        r   r   r  c              3   p   K   | ]-  }|vr'j                  |      s|j                          / yw))_unbound_option_seenN)add_gen_cache_key)rL   elemanon_map
bindparamsseens     r.   rN   z._UnboundLoad._gen_cache_key.<locals>.<genexpr>  sD       !t+DHHTN	 ++$jt , s   36r3   r!   c              3   B   K   | ]  }|j                          y wr9   )r  )rL   r  r  r  s     r.   rN   z._UnboundLoad._gen_cache_key.<locals>.<genexpr>  s&        ++HjArO   r#   )idri   r   _cache_key_traversal_visitorr   visit_multi_listr   r   r  rP   r!   r#   visit_string_multi_dict)	r+   r  r  r  idselfr5   id_visr  s	    ``     @r.   r  z_UnboundLoad._gen_cache_key  sI   : DnnXV$c**6"C55#<5D #J""		4: 4==)	*  ==   %)MM	 	 #6 '' & $($8$8  9D ?? ++ $//4:?$&	
H G$&	
r0   Fc                 H    | j                   j                  |        d | _         y r9   )r  rc   r   s    r.   r   z_UnboundLoad._set_path_strategy  s    T" r0   c                    | |v r||    S | j                         }||| <   | j                  |_        |j                  | j                  k(  sJ |j                  | j                  k(  sJ |j                  | j                  k(  sJ | j
                  xs dD cg c]  }|j                  ||       c}|_        |j                  j                  | j                          ||       |S c c}w r2   )	rW   r   rX   r*   rY   r  rT   r#   r\   )r+   rU   rS   r]   r  s        r.   rT   z_UnboundLoad._deep_clone  s    7?4= !--**d.G.GGGG''4+A+AAAA""d&7&7777 <@==;NB
37DWg.
 	  1
s   C#c           
         | |v r||    S || j                   }| j                         }||| <   | j                  |_        | j                  r| j                  d   }t	        |t
        j                        r3|j                  t              r|j                  d      d   dz   t        z   }|j                  |j                  | j                  dd z   || j                  d        |j                  | j                  k(  sJ |j                  | j                  k(  sJ |j                  | j                  k(  sJ t               }|j                   |_         |j                   D cg c]  }||vr|j!                  |      s| c}|D cg c]+  }||vr%|j!                  |      s|j#                  ||||      - c}z   |j                   d d  |j$                  j'                  | j$                         |S c c}w c c}w )Nr   r   rJ   )r  rW   r   r   r[   r   r   r   r   splitr   r   rX   r*   rY   r   r  r   r#   r\   )	r+   r   rU   r   to_bindr]   r   uniqr  s	            r.   r   z_UnboundLoad._apply_to_parent4  s   7?4= ?mmG!--9999R=D$ 1 12t}}8 zz#q)C//A!!dii"o-tT]]D **d.G.GGGG''4+A+AAAA""d&7&7777u // 
4 
  
4 !!&'5'B
	
 	  1

s   G%<0G*c                    |r?t        |t        j                        r%|t        t        fv r|t        k(  rd| _        |d|}|rt        |d         r| j                  s|dd }|r||fz   }|| _        t        |dd      | _
        |S )NFr   r   rJ   r!   r3   )r[   r   r   r   r   rX   r   r*   r   r   r!   )r+   r   r   r   r   s        r.   r   z_UnboundLoad._generate_pathb  s    4!2!23.99~%,1)*D1D$T"X.t7M7M":D4'>D	&t->Cr0   c                     | j                   j                         }d|d<   | j                  | j                  d      |d<   |S )Nr3   r!   T)filter_aliased_classr   )r   r   _serialize_pathr   r   s     r.   r   z_UnboundLoad.__getstate__t  sC    MM   "
(((N&	r0   c                 "   g }|d   D ]p  }t        |t              rMt        |      dk(  r|\  }}d }n|\  }}}t        ||      }|r|j	                  |      }|j                  |       `|j                  |       r t        |      |d<   || _        y )Nr   r   )r[   rP   r   r   of_typerc   r   )r+   r   retr^   r5   propkeyr%  r   s           r.   r   z_UnboundLoad.__setstate__}  s    = 	 C#u%s8q=#&LC"G,/)C'sG,<<0D

4 

3	  c
fr0   c                 D   |j                   d   }|j                  j                  }| j                  D ]g  }||vs|j	                  |       |r|j
                  s(|j                  |D cg c]  }|j                   c}|j                  |j                   |       i y c c}w )N_unbound_load_dedupes)	rx   rk   rt   r  r  rX   _bind_loaderentity_zeroro   )r+   r>   rp   ry   dedupesrz   valr   s           r.   rm   z_UnboundLoad._process  s    **+BC"22EE
== 
	C'!C c&>&>  0?@S__@!..!,,	
	 As   )B
c                     t               }d }|D cg c]  } ||      D ]  }|  }	}}|	dd D ]'  }d|_        |r |||fi |}|j                  |      })  |||	d   fi |}d|_        |S c c}}w )Nc                     t        | t        j                        rU| t        k(  rt        fS | j                  dt        z         rt        j                  dd       | dd  } | j                  d      S | fS )N.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.1.4versionr   )r[   r   r   r   r   
startswithwarn_deprecatedr  r^   s    r.   
_split_keyz+_UnboundLoad._from_keys.<locals>._split_key  sn    #t001/)*,,^^C/$9:((# !& ab'Cyy~%vr0   rJ   r   TF)r   _is_chain_linkdefaultload)
r5   methkeyschainedkwrQ   r7  r^   r{   
all_tokenss
             r.   
_from_keysz_UnboundLoad._from_keys  s    n	* (,ICIeIeI
I"% 	-E "&C3,,ooe,	- 3
2-"-"
 Js   A1c                    d}t        t        ||j                                     D ]  \  }\  }\  }}t        |t        j
                        r@|dk(  r|j                  dt        z         r|c S |dt        k7  sT||j                  k7  sd y t        |t              sw|j                  |usA|j                  |us|j                  j                  r|j                  j                  |      r y  |dz  }||d  S r   )r   r   pairsr[   r   r   r   r   r   r^   r   r   _parententityr   r   )r+   r   r   r   r   p_entityp_props          r.   rw   z_UnboundLoad._chop_path  s    09&1
 	,A,+(F '4#4#456g..s^/CD"NOEE6::-G^4##61))9#11;;&4488B  '	* FAqr{r0   c                 P   g }|D ]  }t        |t              r|r^|j                  rRt        |j                        j                  r3|j                  |j                  j                  |j                  d f       t|j                  |j                  j                  |j                  |j                  r|j                  j                  nd f       t        |t              r4|j                  |j                  j                  |j                  d f       |j                  |         |S r9   )r[   r   r    r   r   rc   _parentmapperr   r^   r,   r   )r+   r   r"  r&  r{   s        r.   r#  z_UnboundLoad._serialize_path  s     	"E%!34(/@@JJ 3 3 : :EIItLMJJ!//66!II5:^^ENN11 E>2

E//66		4HI

5!'	"( 
r0   c           	      .   | j                   }| j                  r|r	||d   fz  }|r| j                  ||      }|sy|d   }t        |t        j
                        r| j                  |||      }nyt        |t              r+|j                  }| j                  |||j                  |      }n>| j                  rt        |      rt        |      }||vrd}nt        j                  d      |sy|}	t        |	      }
||
j                   }| j"                  |
_        | j$                  |
_        | j                  |
_        | j&                  |
_        |
j                   }|
j                  sSt)        |      D ]E  \  }}|
j+                  |
j                   ||t-        |      dz
  k(  r| j"                  ndd||      rE y |
j.                  j1                  | j.                         |
j                  s-|
j                   j2                  r|
j                   j4                  }n|
j                   }|j6                  rA|j9                         D ],  }|
j;                  ||| j<                   | j$                         . |
S |
j;                  ||| j<                   | j$                         |
S )a]  Convert from an _UnboundLoad() object into a Load() object.

        The _UnboundLoad() uses an informal "path" and does not necessarily
        refer to a lead entity as it may use string tokens.   The Load()
        OTOH refers to a complete path.   This method reconciles from a
        given Query into a Load.

        Example::


            query = session.query(User).options(
                joinedload("orders").joinedload("items"))

        The above options will be an _UnboundLoad object along the lines
        of (note this is not the exact API of _UnboundLoad)::

            _UnboundLoad(
                _to_bind=[
                    _UnboundLoad(["orders"], {"lazy": "joined"}),
                    _UnboundLoad(["orders", "items"], {"lazy": "joined"}),
                ]
            )

        After this method, we get something more like this (again this is
        not exact API)::

            Load(
                User,
                (User, User.orders.property))
            Load(
                User,
                (User, User.orders.property, Order, Order.items.property))

        rJ   Nz6mapper option expects string key or list of attributesr   )r   r   )r   r*   rw   r[   r   r   _find_entity_basestringr   r   _find_entity_prop_comparatorrB  r   r   r   r   r   r)   r   rY   r!   r   r   r   r#   r\   r   r   r   r   r   r8  )r+   entitiesro   r)   ry   r|   r{   r,   r   path_elementrb   r   idxr   s                 r.   r*  z_UnboundLoad._bind_loader  s   H YY
!!l8A;.(J
 \BJ 1eT../11(E8LF~.>>D66$ 3 3XF ##(8(?U^FX%&&K   l#?nnG--"//#'#9#9 !%!5!5{{'''
3 	
U,,KK%(C
Oa,?%?DMMT/6 -  	 	  1''FKK,B,B#[[//N#[[N ""&@@B $$ $ 3 33#00	 %      ///,,	 !  r0   c           	      f   t        |      r|}nt        |      }|D ]  }t        j                  ||      s|c S  |rut	        |      s8t        j                  dt        j                  t        |            d|d      t        j                  d|ddj                  d |D              d      y )	Nz@Query has only expression-based entities, which do not apply to z ""zMapped attribute "zA" does not apply to any of the root entities in this query, e.g. , c              3   2   K   | ]  }t        |        y wr9   str)rL   xs     r.   rN   z<_UnboundLoad._find_entity_prop_comparator.<locals>.<genexpr>  s     *Da3q6*D   zV. Please specify the full path from one of the root entities to the target attribute. )r   r   r   _entity_corresponds_tolistr   r   r   clsname_as_plain_namer   join)r+   rJ  r   r   ry   	searchforr   s          r.   rI  z)_UnboundLoad._find_entity_prop_comparator~  s    V$I(0I 	C..sI>
	 H~ ..  55d4jA4I  !..  *D8*D!DF  r0   c           	      n   |j                  dt        z         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 rO  c              3   2   K   | ]  }t        |        y wr9   rQ  rL   r   s     r.   rN   z7_UnboundLoad._find_entity_basestring.<locals>.<genexpr>  s     %C3c#h%CrT  z?. Specify loader options for each entity individually, such as c              3   &   K   | ]	  }d |z    yw)zLoad(%s).some_option('*')Nr3   r\  s     r.   rN   z7_UnboundLoad._find_entity_basestring.<locals>.<genexpr>  s      &$' !<c A&s   r0  FzFQuery has only expression-based entities - can't find property named "r   )r   r   r   rV  r   r   rX  r   )r+   rJ  r{   ry   r   s        r.   rH  z$_UnboundLoad._find_entity_basestring  s    >>#/04>"a' .. !II%C(%CC II &+3& 
  ^^N+H 	C J		 **:?B 
 r0   r9   F)r   r   r   r   r/   r  r8  r   rT   r   r   r   r   rm   r  r?  rw   r#  r*  rI  rH  r3   r0   r.   r   r     sn    "Q
f N0,\$& % %N60BH8 r0   r   c                   $    e Zd Zd Zd Zd Zd Zy)loader_optionc                      y r9   r3   r   s    r.   r/   zloader_option.__init__  s    r0   c                     |j                   x| _        }|| _        t        t        |      rt        d|z        t        t        ||       | S )Nz#Load class already has a %s method.)r   namefnhasattrr   	TypeErrorsetattr)r+   rd  rc  s      r.   __call__zloader_option.__call__  sE    ;;&	D4ATJKKdBr0   c                     || _         | j                  j                  }dd| j                  iz  | j                  _        ||_        | S )NzProduce a new :class:`_orm.Load` object with the
:func:`_orm.%(name)s` option applied.

See :func:`_orm.%(name)s` for usage examples.

rc  )_unbound_fnrd  r   rc  )r+   rd  fn_docs      r.   _add_unbound_fnzloader_option._add_unbound_fn  sG     DII

 
r0   c                     dd| j                   iz  |_         t        j                  ddd| j                   iz  d      |      }|| _        | S )Na}  Produce a standalone "all" option for
:func:`_orm.%(name)s`.

.. deprecated:: 0.9

    The :func:`_orm.%(name)s_all` function is deprecated, and will be removed
    in a future release.  Please use method chaining with
    :func:`_orm.%(name)s` instead, as in::

        session.query(MyClass).options(
            %(name)s("someattribute").%(name)s("anotherattribute")
        )

rc  z0.9zThe :func:`.%(name)s_all` function is deprecated, and will be removed in a future release.  Please use method chaining with :func:`.%(name)s` insteadF)add_deprecation_to_docstring)rc  r   r   
deprecated_unbound_all_fn)r+   rd  s     r.   _add_unbound_all_fnz!loader_option._add_unbound_all_fn  sk     DII


 
T__ (+1499*=> */
   "r0   N)r   r   r   r/   rh  rl  rq  r3   r0   r.   r`  r`    s    r0   r`  Nc                 0   |@t        |t              st        |      }|j                  }nFt	        j
                  dd       n.t        |dd      r!t        |j                        }|j                  }| j                  |ddid	      }||j                  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
    :meth:`_query.Query.populate_existing` method 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.r1  r2  r    lazyjoinedF)rX   eager_from_alias)
r[   rR  r   
selectabler   r5  r   r    r   r#   )loadoptr   aliasinfootr]   s         r.   contains_eagerr{    s    N %%5>DOOE   6  
z4	(T]]#..vx u / F -2F()Mr0   c                  V    t               j                  t         j                  | d|      S r   )r   r?  r{  r;  r=  s     r.   r{  r{  8  s&    >$$##T4 r0   c                 `    | j                  |ddd      }|j                  ddddddi       |S )al  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 :class:`_query.Query` that has multiple entities,
    the lead entity can be
    specifically referred to using the :class:`_orm.Load` constructor::

        session.query(User, Address).join(User.addresses).options(
                    Load(User).load_only(User.name, User.fullname),
                    Load(Address).load_only(Address.email_address)
                )

     .. note:: This method will still load a :class:`_schema.Column` even
        if the column property is defined with ``deferred=True``
        for the :func:`.column_property` function.

    .. versionadded:: 0.9.0

    FTdeferred
instrument*undefer_pksr   )rw  r   r]   s      r.   	load_onlyr  ?  sG    L ((E6F $d3mT5J Mr0   c                  0     t               j                  |  S r9   )r   r  )r   s    r.   r  r  n  s    #<>##U++r0   c                 P    | j                  |ddi      }|||j                  d<   |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"
        query(User).options(joinedload(User.orders))

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

        # lazily load Order.items, but when Items are loaded,
        # joined-load the keywords collection
        query(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::

        query(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::

        query(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::

        query(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.

     .. versionchanged:: 1.0.0 ``innerjoin=True`` now implies
        ``innerjoin="nested"``, whereas in 0.9 it implied
        ``innerjoin="unnested"``.  In order to achieve the pre-1.0 "unnested"
        inner join behavior, use the value ``innerjoin="unnested"``.
        See :ref:`migration_3008`.

    .. note::

        The joins produced by :func:`_orm.joinedload` are **anonymously
        aliased**.  The criteria by which the join proceeds cannot be
        modified, nor can the :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:`_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`

    rs  rt  	innerjoin)r   r#   )rw  r   r  rb   s       r.   
joinedloadr  s  s7    p ..tfh5GHF)2+&Mr0   c                  N    t         j                  t         j                  | d|      S r%   )r   r?  r  r}  s     r.   r  r    s    ""<#:#:D%LLr0   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"
        query(User).options(subqueryload(User.orders))

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

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


    .. seealso::

        :ref:`loading_toplevel`

        :ref:`subquery_eager_loading`

    rs  subqueryr   rw  r   s     r.   subqueryloadr    s    < ,,TFJ3GHHr0   c                  N    t         j                  t         j                  | di       S r%   )r   r?  r  r;  s    r.   r  r        ""<#<#<dE2NNr0   c                 *    | j                  |ddi      S )a9  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"
        query(User).options(selectinload(User.orders))

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

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

    .. versionadded:: 1.2

    .. seealso::

        :ref:`loading_toplevel`

        :ref:`selectin_eager_loading`

    rs  selectinr  r  s     r.   selectinloadr    s    > ,,TFJ3GHHr0   c                  N    t         j                  t         j                  | di       S r%   )r   r?  r  r  s    r.   r  r    r  r0   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`

    rs  selectr  r  s     r.   lazyloadr  #  s     ,,TFH3EFFr0   c                  N    t         j                  t         j                  | di       S r%   )r   r?  r  r  s    r.   r  r  5  s    ""<#8#8$rJJr0   c                 .    | j                  |d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.

    .. seealso::

        :ref:`loading_toplevel`

        :ref:`selectin_eager_loading`

    rs  	immediater  )rw  r   rb   s      r.   immediateloadr  :  s     , ..tfk5JKFMr0   c                  N    t         j                  t         j                  | di       S r%   )r   r?  r  r  s    r.   r  r  T  s    ""<#=#=tUBOOr0   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; for
    column-based attributes, see :func:`_orm.defer`.

    .. note:: Setting this loading strategy as the default strategy
        for a relationship using the :paramref:`.orm.relationship.lazy`
        parameter may cause issues with flushes, such if a delete operation
        needs to load related objects and instead ``None`` was returned.

    .. seealso::

        :ref:`loading_toplevel`

    rs  noloadr  r  s     r.   r  r  Y  s    0 ,,TFH3EFFr0   c                  N    t         j                  t         j                  | di       S r%   )r   r?  r  r  s    r.   r  r  t  s    ""<#6#6eRHHr0   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.


    .. versionadded:: 1.1

    .. seealso::

        :ref:`loading_toplevel`

        :ref:`prevent_lazy_with_raiseload`

        :ref:`deferred_raiseload`

    rs  raise_on_sqlraiser  )rw  r   sql_onlys      r.   	raiseloadr  y  s4    N ,,v~? 7>? r0   c                  N    t         j                  t         j                  | d|      S r%   )r   r?  r  r}  s     r.   r  r    s    ""<#9#94KKr0   c                 &    | j                  |d      S )a:  Indicate an attribute should load using its default loader style.

    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.query(MyClass).options(
            defaultload(MyClass.someattribute).
            defer("some_column").
            undefer("some_other_column")
        )

    .. seealso::

        :meth:`_orm.Load.options` - allows for complex hierarchical
        loader option structures with less verbosity than with individual
        :func:`.defaultload` directives.

        :ref:`relationship_loader_options`

        :ref:`deferred_loading_w_multiple`

    Nr  r  s     r.   r9  r9    s    D ,,T488r0   c                  N    t         j                  t         j                  | di       S r%   )r   r?  r9  r  s    r.   r9  r9    s    ""<#;#;T5"MMr0   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("attribute_one"),
                            defer("attribute_two"))

        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("someattr").defer("some_column"))

    A :class:`_orm.Load` object that is present on a certain path can have
    :meth:`_orm.Load.defer` called multiple times,
    each will operate on the same
    parent entity::


        session.query(MyClass).options(
                        defaultload("someattr").
                            defer("some_column").
                            defer("some_other_column").
                            defer("another_column")
            )

    :param key: Attribute to be deferred.

    :param raiseload: raise :class:`.InvalidRequestError` if the column
     value is to be loaded from emitting SQL.   Used to prevent unwanted
     SQL from being emitted.

     .. versionadded:: 1.4

     .. seealso::

        :ref:`deferred_raiseload`

    :param \*addl_attrs: This option supports the old 0.8 style
     of specifying a path as a series of attributes, which is now superseded
     by the method-chained style.

        .. deprecated:: 0.9  The \*addl_attrs on :func:`_orm.defer` is
           deprecated and will be removed in a future release.   Please
           use method chaining in conjunction with defaultload() to
           indicate a path.


    .. seealso::

        :ref:`deferred`

        :func:`_orm.undefer`

    Tr  r  r  )rw  r^   r  r   s       r.   deferr    s1    J !5H $&&vx88r0   c                     |rt        j                  dd       t        j                  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.3r2  F)r   r5  r   r?  r  )r^   
addl_attrsr=  s      r.   r  r    sH     		
 ""SFZ/ r0   c                 .    | j                  |fddd      S )ag  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("col1"), undefer("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
        session.query(MyClass).options(
            defaultload(MyClass.items).undefer('text'))

    :param key: Attribute to be undeferred.

    :param \*addl_attrs: This option supports the old 0.8 style
     of specifying a path as a series of attributes, which is now superseded
     by the method-chained style.

        .. deprecated:: 0.9  The \*addl_attrs on :func:`_orm.undefer` is
           deprecated and will be removed in a future release.   Please
           use method chaining in conjunction with defaultload() to
           indicate a path.

    .. seealso::

        :ref:`deferred`

        :func:`_orm.defer`

        :func:`_orm.undefer_group`

    FTr  r  )rw  r^   s     r.   undeferr  -  s$    X &&	U$7 r0   c                     |rt        j                  dd       t        j                  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.r  r2  F)r   r5  r   r?  r  )r^   r  s     r.   r  r  ^  sH     		
 ""sfz15" r0   c                 6    | j                  ddd|z  did      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`::

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

    .. versionchanged:: 0.9.0 :func:`_orm.undefer_group` is now specific to a
       particular entity load path.

    .. seealso::

        :ref:`deferred`

        :func:`_orm.defer`

        :func:`_orm.undefer`

    r  Nzundefer_group_%sT)r   r  )rw  rc  s     r.   undefer_groupr  l  s0    > &&T&-t4 '  r0   c                 4    t               j                  |       S r9   )r   r  )rc  s    r.   r  r    s    >''--r0   c                     t        j                  t        j                  t	        |            }| j                  |fddid|i      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.::


        sess.query(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.

    .. versionchanged:: 1.4  Loader options such as
       :func:`_orm.with_expression`
       take effect only at the **outermost** query used, and should not be used
       within subqueries or inner elements of a UNION. See the change notes at
       :ref:`change_8879` for background on how to correctly add arbitrary
       columns to subqueries.

    .. note:: the target attribute is populated only if the target object
       is **not currently loaded** in the current :class:`_orm.Session`
       unless the :meth:`_query.Query.populate_existing` method is used.
       Please refer to :ref:`mapper_querytime_expression` for complete
       usage details.

    .. seealso::

        :ref:`mapper_querytime_expression`

    query_expressionT
expressionr   )r   expectr   LabeledColumnExprRoler   r   )rw  r^   r  s      r.   with_expressionr    sT    P !!##%9*%EJ &&	#T*,
1K '  r0   c                 T    t         j                  t         j                  | fdd|i      S )NFr  )r   r?  r  )r^   r  s     r.   r  r    s+    ""$$sfelJ5O r0   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_polymorphicTrJ  c              3   2   K   | ]  }t        |        y wr9   r   )rL   r5   s     r.   rN   z'selectin_polymorphic.<locals>.<genexpr>  s     88rT  r6  r  )r   rP   r   r  )rw  classess     r.   selectin_polymorphicr    sE      	#T*88bA
   Nr0   c                 l    t               }d|_        t        |       f|_        |j	                  |       |S r   )r   r*   r   r   r  )base_clsr  uls      r.   r  r    s3    	BBx "BGG$Ir0   r9   r^  )5r   r   r   r   rx   r   baser   r   r   r   
interfacesr	   r
   r   path_registryr   r   r   r   r   r   r   r   sqlr   r   r   r   r   sql.baser   r   r   r   objectr`  r{  rl  r  r  r  r  r  r  r  r  r9  r  r  r  r  r  r3   r0   r.   <module>r     sx    * " # "   $ & & ) * ' ( &         " !G
 :| G
 TK4 K\8F 8v < <~    + +\ , , Z Zz M M I I@ O O I IB O O G G" 
K K  2 P P G G4 I I ( (V L L !9 !9H N N G9 G9T 
 
 - -` 	
 
    F . . - -`    !  4 %% &r0   