Sh3ll
OdayForums


Server : LiteSpeed
System : Linux premium84.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
User : claqxcrl ( 523)
PHP Version : 8.1.32
Disable Function : NONE
Directory :  /opt/hc_python/lib64/python3.12/site-packages/sqlalchemy/orm/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //opt/hc_python/lib64/python3.12/site-packages/sqlalchemy/orm/__pycache__/util.cpython-312.pyc
�

���g�;�
�
�ddlmZddlZddlZddlZddlZddlZddlmZddlmZddlm	Z	ddlm
Z
ddlmZddlmZdd	lm
Z
dd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddl"m#Z#ddl"m$Z$ddl"m%Z%ddl"m&Z&dd l"m'Z'dd!l"m(Z(dd"l"m)Z)dd#l"m*Z*dd$l"m+Z+dd%l"m,Z,dd&l"m-Z-dd'l"m.Z.dd(l"m/Z/dd)l"m0Z0dd*l"m1Z1dd+l"m2Z2dd,l"m3Z3dd-l"m4Z4dd.l"m5Z5dd/l6m7Z7dd0l6m8Z8dd1l6m9Z9dd2l6m:Z:dd3l6m;Z;dd4l<m=Z=d5d6lm>Z>d5dlmZ?d5d7lm@Z@d5d8lmAZAd5d9lmBZBd5d:lCmDZDd5d;lAmEZEd5d<lAmFZFd5d=lAmGZGd5d>lAmHZHd5d9lAmBZId5d?lAmJZJd5d@lKmLZLd5dAlMmNZNd5dBlOmPZPd5dClQmRZRd5dDlQmSZSd5dElTmUZUd5dFlTmVZVd5dGlWmXZXd5dHlYmZZZd5dIl[m\Z]d5dJl[m^Z_d5dKl[m`Z`d5dLl[maZad5dMl[mbZbd5dNl[mcZcd5dOl[mdZdej,r�ddPlmeZeddQlmfZfddRlmgZgddSlmhZhddTlimjZjddUlimkZkddVllmmZmddWl<mnZnddXlompZpddYlqmrZrd5dZlsmtZtd5d[lsmuZud5d\lKmvZvd5d]lKmwZwd5d^lKmxZxd5d_lKmyZyd5d`lKmzZzd5dalKm{Z{d5dblMm|Z|d5dclOm}Z}d5ddlTm~Z~d5delWmZd5dflWm�Z�d5dglWm�Z�d5dhl�m�Z�d5dil[m�Z�edje�k�Z�e�dl�Z�e�je�jeB�je-e5e*dm���n�Z�Gdo�dped�Z�e
e�e�e]��Z\Gdq�dred�Z�e
e�e�e_��Z^Gds�dtee��Z�du�Z�	d�dv�Z�		d�ddddw�											d�dx�Z�Gdy�dze�j$�Z�Gd{�d|eI�j(�Z�Gd}�d~eI�j(�Z�Gd�d�e@�j.d�e9e�Z�e@�j2Gd��d�e:ee;eRe+eZe@�j.d�e
e�	�Z�Gd��d��Z�Gd��d�e7�Z�e@�j:e��d���e@�j:e��				d�d���Z�e�ee�Z�e@�j:e��				d�d���Z�e@�j2Gd��d�e9e�eNeSe@�j.d�e+��Z�d�d�d��Z�d�d��Z�d�d��Z�Gd��d�eF�jL�Z�	d�							d�d��Z�d�d��Z�d�d��Z�						d�d��Z�						d�d��Z�d�d��Z�d�d��Z�								d�d��Z�Gd��d�e��Z�						d�d��Z�		d�																			d�d��Z�d�d��Z�y)��)�annotationsN)�AbstractSet)�Any)�Callable)�cast)�Dict)�	FrozenSet)�Generic)�Iterable)�Iterator)�List)�Match)�Optional)�Sequence)�Tuple)�Type)�
TYPE_CHECKING)�TypeVar)�Union�)�
attributes)�exc)�_O)�insp_is_aliased_class)�insp_is_mapper)�prop_is_relationship)�_class_to_mapper)�_MappedAnnotationBase)�
_never_set)�_none_only_set)�	_none_set)�
attribute_str)�class_mapper)�
DynamicMapped)�InspectionAttr)�instance_str)�Mapped)�
object_mapper)�object_state)�opt_manager_of_class)�
ORMDescriptor)�state_attribute_str)�state_class_str)�	state_str)�WriteOnlyMapped)�CriteriaOption)�MapperProperty)�ORMColumnsClauseRole)�ORMEntityColumnsClauseRole)�ORMFromClauseRole)�PathRegistry�)�event)�
inspection)�sql)�util��result_tuple)�	coercions)�
expression)�lambdas)�roles)�visitors)�
is_selectable)�SupportsCloneAnnotations)�ColumnCollection)�HasCacheKey)�MemoizedHasCacheKey)�
ColumnElement)�KeyedColumnElement)�
FromClause)�
MemoizedSlots)�de_stringify_annotation)�eval_name_only)�fixup_container_fwd_refs)�
get_origin)�is_origin_of_cls)�Literal)�Protocol)�_EntityType)�_IdentityKeyType)�_InternalEntityType)�_ORMCOLEXPR)�
_MapperEntity)�ORMCompileState)�Mapper)�AbstractEntityRegistry)�Query)�RelationshipProperty)�Row)�
RowMapping)�_CE)�_ColumnExpressionArgument)�_EquivalentColumnMap)�_FromClauseArgument)�_OnClauseArgument)�_PropagateAttrsType)�_SA)�ReadOnlyColumnCollection)�
BindParameter)�_ColumnsClauseElement)�Select)�
Selectable)�anon_map)�_AnnotationScanType�_T)�bound)�delete�
delete-orphan�all�merge�expunge�save-update�refresh-expire�none)r'r/r$)�locals_c�2�eZdZddd�											dd�Zy)�_DeStringifyAnnotationNF)�str_cleanup_fn�include_genericc��y�N�)�self�cls�
annotation�originating_moduleryrzs      �D/opt/hc_python/lib64/python3.12/site-packages/sqlalchemy/orm/util.py�__call__z_DeStringifyAnnotation.__call__�s���)r�	Type[Any]r�rkr��strryz#Optional[Callable[[str, str], str]]rz�bool�returnr���__name__�
__module__�__qualname__r�r}r�r�rxrx�sJ��?C� %��
��(�� �	�<�
���
�r�rxc��eZdZdd�Zy)�
_EvalNameOnlyc��yr|r})r~�name�module_names   r�r�z_EvalNameOnly.__call__�s��Cr�N)r�r�r�r�r�rr�r}r�r�r�r��s��?r�r�c���eZdZUdZejgd��ZeZgd�ZdZ	de
d<de
d<de
d<de
d	<de
d
<de
d<				d�fd�Zd
�Ze
d��Z�xZS)�CascadeOptionszHKeeps track of the options sent to
    :paramref:`.relationship.cascade`)rpruro)rrrprurtrq)�save_updatern�refresh_expirerqrr�
delete_orphanr�r�rnr�rqrrr�c����t|t�s|�|j|�St|�}|j	|j
�r`t
jddjt|j	|j
��D�cgc]
}t|���c}�z��d|vr|j|j�d|vr|j�|jd�t�|�A||�}d|v|_d|v|_d|v|_d|v|_d	|v|_d
|v|_|j,r!|j$st/j0d�|Scc}w)NzInvalid cascade option(s): %s�, rprursrnrtrqrrroz5The 'delete-orphan' cascade option requires 'delete'.)�
isinstancer��from_string�set�
difference�_allowed_cascades�sa_exc�
ArgumentError�join�sorted�repr�update�_add_w_all_cascades�clear�discard�super�__new__r�rnr�rqrrr�r:�warn)r�
value_list�values�xr~�	__class__s     �r�r�zCascadeOptions.__new__�s^����j�#�&�*�*<��?�?�:�.�.��Z������S�2�2�3��&�&�/��)�)�"(�"�-�-�c�.C�.C�D�"��"�A��Q��"����
�

��F�?��M�M�#�1�1�2��V���L�L�N����u���w��s�F�+��(�F�2����&�(���.�&�8�����&��
� �F�*���,��6������d�k�k��I�I�M�N����3s�E$c�b�ddjt|�D�cgc]}|��c}�zScc}w)NzCascadeOptions(%r)�,)r�r�)r~r�s  r��__repr__zCascadeOptions.__repr__�s,��#�s�x�x�F�4�L�0I�L�q��L�0I�'J�K�K��0Is�	,
c�p�tjd|xsd�D�cgc]}|s�|��	}}||�Scc}w)Nz\s*,\s*�)�re�split)r�arg�cr�s    r�r�zCascadeOptions.from_string�s9���X�X�j�#�)��<�B�<���!�<��B��6�{���Cs�3�3)r�z#Optional[Union[Iterable[str], str]]r�r�)r�r�r��__doc__�all_cascadesr�r�r��_viewonly_cascades�	__slots__�__annotations__r�r��classmethodr��
__classcell__�r�s@r�r�r��s����)�'�1�1�(���%��N���I����L����K�
�M���#�<�#�	�#�JL����r�r�c�d����	��s�fd��	|r!�	���fd�}�	���fd�}�	���fd�}�	���fd�}n�	���fd�}�	���fd�}�	���fd�}tj|d	|d
d
��tj|d|d
�
�tj|d|d
d
��|rtj|dd
d
��yy)zNRuns a validation method on an attribute value to be set or
    appended.
    c�R��|j�j}|j|uSr|)�manager�impl)�state�	initiatorr��keys   �r��detect_is_backrefz,_validator_events.<locals>.detect_is_backrefs&����=�=��%�*�*�D��>�>��-�-r�c���|jtjur$�s	�||�s�|j��|d�S|S�NF��opr�OP_BULK_REPLACE�obj�r��valuer�r��include_backrefsr��	validators   ����r��appendz!_validator_events.<locals>.appends>����|�|�:�#=�#=�=� �(9�%��(K� �����c�5�%�@�@��r�c	����s	�||�s-|j�}|D�cgc]
}�|�|d���c}|ddyycc}wr��r��	r�r�r�r�r�r�r�r�r�s	     ����r��bulk_setz#_validator_events.<locals>.bulk_setsN����'8��	�'J��i�i�k��CI��CI�%�I�c�3��u�5�6���q�	�(K��s�;c�P���s	�||�s�|j��|d�S|Sr�r��r�r��oldvaluer�r�r�r�r�s    ����r��set_z_validator_events.<locals>.set_s,����'8��	�'J� �����c�5�%�@�@��r�c�P���s	�||�s�|j��|d�yy)NTr�r�s   ����r��removez!_validator_events.<locals>.removes*����'8��	�'J��%�)�)�+�s�E�4�8�(Kr�c���|jtjur#�s	�||�s�|j��|�S|Sr|r�r�s   ����r�r�z!_validator_events.<locals>.append#s<����|�|�:�#=�#=�=� �(9�%��(K� �����c�5�9�9��r�c�~���s	�||�s,|j�}|D�cgc]}�|�|���c}|ddyycc}wr|r�r�s	     ����r�r�z#_validator_events.<locals>.bulk_set+sE����'8��	�'J��i�i�k��EK�L�V�E�Y�s�C��7�V�L��q�	�(K��Ls�:c�N���s	�||�s�|j��|�S|Sr|r�r�s    ����r�r�z_validator_events.<locals>.set_0s*����'8��	�'J� �����c�5�9�9��r�r�T)�raw�retval�bulk_replace)r�r�r�N)r7�listen)
�descr�r��include_removesr�r�r�r�r�r�s
 `` `    @r��_validator_eventsr��s����
�	.��	�	�	�	9�	9�	�	M�
	�
�L�L��x��T�$�?�	�L�L��~�x�T�:�	�L�L��u�d��T�:��
���T�8�V��d�C�r�c����
��tj�}i�
i�|D]�}||}tjtj
|d��}|||<i}|jD]p}|j|k(rtjd|�d|�d���|j|j�|||j<|j�|j<�r|�
|<����
�fd�}	g}
|j�D]�\}}|�|
jtj|D�cgc]}|	||���
c}tj t#j$|��j'|�gz�j)|����|
jtj|D�cgc]}|	||���
c}�j)|����tj*|
�j-|�Scc}wcc}w)a0Create a ``UNION`` statement used by a polymorphic mapper.

    See  :ref:`concrete_inheritance` for an example of how
    this is used.

    :param table_map: mapping of polymorphic identities to
     :class:`_schema.Table` objects.
    :param typecolname: string name of a "discriminator" column, which will be
     derived from the query, producing the polymorphic identity for
     each row.  If ``None``, no polymorphic discriminator is generated.
    :param aliasname: name of the :func:`~sqlalchemy.sql.expression.alias()`
     construct generated.
    :param cast_nulls: if True, non-existent columns, which are represented
     as labeled NULLs, will be passed into CAST.   This is a legacy behavior
     that is problematic on some backends such as Oracle - in which case it
     can be set to False.

    T)�allow_selectzPolymorphic union can't use 'z3' as the discriminator column due to mapped column zn; please apply the 'typecolname' argument; this is available on ConcreteBase as '_concrete_discriminator_name'c�$��	�||S#t$r{�r<tjtj��|�j	|�cYStj
tj��|�j	|�cYSwxYwr|)�KeyErrorr9r�null�label�type_coerce)r��table�
cast_nulls�colnamemaps�typess  ���r��colzpolymorphic_union.<locals>.colnsy���	L��u�%�d�+�+���	L���x�x����
�E�$�K�8�>�>�t�D�D����s�x�x�z�5��;�?�E�E�d�K�K�		L�s��AB�:B�B)r:�
OrderedSetr=�expectr@�StrictFromClauseRoler�r�r��InvalidRequestError�add�type�itemsr�r9�select�literal_column�sql_util�_quote_ddl_exprr��select_from�	union_all�alias)�	table_map�typecolname�	aliasnamer��colnamesr�r��mr�r��result�type_r�r�r�s   `         @@r��polymorphic_unionr=s����,&*�_�_�%6�H��K��E����#���� � ��&�&��D�
���	�#�������A��u�u��#��0�0�#�A�'���
�L�L������A�a�e�e�H��6�6�E�!�%�%�L����E��-�0L��F�!���)���u��"��M�M��
�
�6>�?�h�d��T�5�)�h�?��.�.� (� 8� 8�� ?��#�e�K�0���	��+�e�$�
�
�M�M��
�
�3;�<�8�4�c�$��&�8�<���+�e�$�
�*�(�=�=�&�!�'�'�	�2�2��@��=s�G!�G&)�instance�row�identity_tokenc�8�|�ft|�}|�F|�tjd��|jt	tj|��|��S|j||��S|�t|�}|j|�Stjd��)a5Generate "identity key" tuples, as are used as keys in the
    :attr:`.Session.identity_map` dictionary.

    This function has several call styles:

    * ``identity_key(class, ident, identity_token=token)``

      This form receives a mapped class and a primary key scalar or
      tuple as an argument.

      E.g.::

        >>> identity_key(MyClass, (1, 2))
        (<class '__main__.MyClass'>, (1, 2), None)

      :param class: mapped class (must be a positional argument)
      :param ident: primary key, may be a scalar or tuple argument.
      :param identity_token: optional identity token

        .. versionadded:: 1.2 added identity_token


    * ``identity_key(instance=instance)``

      This form will produce the identity key for a given instance.  The
      instance need not be persistent, only that its primary key attributes
      are populated (else the key will contain ``None`` for those missing
      values).

      E.g.::

        >>> instance = MyClass(1, 2)
        >>> identity_key(instance=instance)
        (<class '__main__.MyClass'>, (1, 2), None)

      In this form, the given instance is ultimately run though
      :meth:`_orm.Mapper.identity_key_from_instance`, which will have the
      effect of performing a database check for the corresponding row
      if the object is expired.

      :param instance: object instance (must be given as a keyword arg)

    * ``identity_key(class, row=row, identity_token=token)``

      This form is similar to the class/tuple form, except is passed a
      database result row as a :class:`.Row` or :class:`.RowMapping` object.

      E.g.::

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

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

        .. versionadded:: 1.2 added identity_token

    zident or row is required)r
zclass or instance is required)
r#r�r��identity_key_from_primary_key�tupler:�to_list�identity_key_from_rowr(�identity_key_from_instance)�class_�identrr	r
�mappers      r��identity_keyr�s���J���f�%���;��}��*�*�+E�F�F��7�7��d�l�l�5�)�*�>�8��
��/�/��N�0��
�
�	��x�(���0�0��:�:��"�"�#B�C�Cr�c��eZdZdZej
�Zej
�Zej
�Zej
�Z	ej
�Z
ej
�Zej
�Zej
�Z
ej
�Zej
�Zej
�Zy)�_TraceAdaptRolea�Enumeration of all the use cases for ORMAdapter.

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

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

    N)r�r�r�r��enum�auto�ALIASED_INSP�JOINEDLOAD_USER_DEFINED_ALIAS� JOINEDLOAD_PATH_WITH_POLYMORPHIC�JOINEDLOAD_MEMOIZED_ADAPTER�MAPPER_POLYMORPHIC_ADAPTER�WITH_POLYMORPHIC_ADAPTER�#WITH_POLYMORPHIC_ADAPTER_RIGHT_JOIN� DEPRECATED_JOIN_ADAPT_RIGHT_SIDE�ADAPT_FROM_STATEMENT�COMPOUND_EAGER_STATEMENT�LEGACY_SELECT_FROM_ALIASr}r�r�rr�s����0�4�9�9�;�L�%.�D�I�I�K�!�'0�t�y�y�{�$�"+�$�)�)�+��"+������(�t�y�y�{��*3�$�)�)�+�'�'0�t�y�y�{�$�
%�4�9�9�;�� )�t�y�y�{�� )�t�y�y�{�r�rc�V��eZdZdZdZddddddd�															d�fd�Z�xZS)	�ORMStatementAdapterz.ColumnAdapter which includes a role attribute.)�roleNFT��equivalents�adapt_required�allow_label_resolve�anonymize_labels�adapt_on_names�adapt_from_selectablesc	�@��||_t�	|�	|||||||��y)Nr')r&r��__init__)
r~r&�
selectabler(r)r*r+r,r-r�s
         �r�r/zORMStatementAdapter.__init__(s3�����	�
����#�)� 3�-�)�#9�	�	
r�)r&rr0rir(�Optional[_EquivalentColumnMap]r)r�r*r�r+r�r,r�r-�!Optional[AbstractSet[FromClause]])r�r�r�r�r�r/r�r�s@r�r%r%#sx���8��I�7;�$�$(�!&�$�DH�
��
��
�
4�
��

�"�
��
��
�!B�
�
r�r%c	�~��eZdZUdZdZded<ded<ddd	ddd	ddd
�																			d
�fd�Zd�Z�xZS)�
ORMAdapterzaColumnAdapter subclass which excludes adaptation of entities from
    non-matching mappers.

    )r&r�is_aliased_class�aliased_inspr�r5�Optional[AliasedInsp[Any]]r6NFT)r(r)r*r+r0�limit_on_entityr,r-c
����||_|j|_|�|j}t|�rd|_||_nd|_d|_t�|�||||||r|jnd|	|
��y)NTF)r)r*r+�
include_fnr,r-)	r&rr0rr5r6r�r/�_include_fn)r~r&�entityr(r)r*r+r0r8r,r-r�s           �r�r/zORMAdapter.__init__Ks������	��m�m������*�*�J� ��(�$(�D�!� &�D��$)�D�!� $�D��
�����)� 3�-�+:�t�'�'��)�#9�	�		
r�c��|jjdd�}|xs8|j|j�xs|jj|�S)N�parentmapper)�_annotations�get�isar)r~�elemr<s   r�r;zORMAdapter._include_fnosF���"�"�&�&�~�t�<���z�O�V�Z�Z����4�O�������8O�Or�)r&rr<�_InternalEntityType[Any]r(r1r)r�r*r�r+r�r0zOptional[Selectable]r8r�r,r�r-r2)	r�r�r�r�r�r�r/r;r�r�s@r�r4r4@s�����
G�I���,�,�7;�$�$(�!&�+/� $�$�DH�"
��"
�)�"
�
4�"
��
"
�"�"
��"
�)�"
��"
��"
�!B�"
�HPr�r4c��eZdZUdZded<									d																			dd�Ze				d
d��Zdd�Z								dd�Z	dd	�Z
dd
�Zy)�AliasedClassa�Represents an "aliased" form of a mapped class for usage with Query.

    The ORM equivalent of a :func:`~sqlalchemy.sql.expression.alias`
    construct, this object mimics the mapped class using a
    ``__getattr__`` scheme and maintains a reference to a
    real :class:`~sqlalchemy.sql.expression.Alias` object.

    A primary purpose of :class:`.AliasedClass` is to serve as an alternate
    within a SQL statement generated by the ORM, such that an existing
    mapped entity can be used in multiple contexts.   A simple example::

        # find all pairs of users with the same name
        user_alias = aliased(User)
        session.query(User, user_alias).join(
            (user_alias, User.id > user_alias.id)
        ).filter(User.name == user_alias.name)

    :class:`.AliasedClass` is also capable of mapping an existing mapped
    class to an entirely new selectable, provided this selectable is column-
    compatible with the existing mapped selectable, and it can also be
    configured in a mapping as the target of a :func:`_orm.relationship`.
    See the links below for examples.

    The :class:`.AliasedClass` object is constructed typically using the
    :func:`_orm.aliased` function.   It also is produced with additional
    configuration when using the :func:`_orm.with_polymorphic` function.

    The resulting object is an instance of :class:`.AliasedClass`.
    This object implements an attribute scheme which produces the
    same attribute and method interface as the original mapped
    class, allowing :class:`.AliasedClass` to be compatible
    with any attribute technique which works on the original class,
    including hybrid attributes (see :ref:`hybrids_toplevel`).

    The :class:`.AliasedClass` can be inspected for its underlying
    :class:`_orm.Mapper`, aliased selectable, and other information
    using :func:`_sa.inspect`::

        from sqlalchemy import inspect

        my_alias = aliased(MyClass)
        insp = inspect(my_alias)

    The resulting inspection object is an instance of :class:`.AliasedInsp`.


    .. seealso::

        :func:`.aliased`

        :func:`.with_polymorphic`

        :ref:`relationship_aliased_class`

        :ref:`relationship_to_window_function`


    r�r�Nc
���tdtj|��}|j}d}
|�[|jr1|j
jr|j
j�}n,|jj||��}n|jrd}
|�J�t|||||r|n|j|�|n|j||	||
|
�|_
d|jj�d�|_y)N�_InternalEntityType[_O]F�r��flatT�aliased(�))rr8�inspectrr5r0�_is_subqueryr��_with_polymorphic_selectable�_anonymous_fromclause�AliasedInsp�with_polymorphic_mappers�polymorphic_on�
_aliased_insprr�)r~�mapped_class_or_acr�r�rIr,rQ�with_polymorphic_discriminator�
base_alias�use_mapper_path�represents_outer_join�inspr�
nest_adapterss              r�r/zAliasedClass.__init__�s���%�z�'9�'9�:L�'M�
�������
��=��$�$����)E�)E����-�-�/���7�7�M�M�!�!�N����
"�
"� �M�� � � �(�����,�)��4�4�2�=�/��*�*����!��'
���,#�6�=�=�#9�#9�":�!�<��
r�c�8�|j|�}d|jjj�d�|_||_|j
rL|jD]=}||us�tj|�}t||jj|��?|S)NrJrK)
r�rrr�rS�_is_with_polymorphic�_with_polymorphic_entitiesrE�_reconstitute_from_aliased_insp�setattr)rr6r��sub_aliased_insp�ents     r�r^z,AliasedClass._reconstitute_from_aliased_insp�s����k�k�#���!�,�"5�"5�"<�"<�"E�"E�!F�a�H���(����,�,�$0�$K�$K� �#�<�7�&�F�F�(��C��C�!1�!8�!8�!A�!A�3�G�%L��
r�c��	|jd}|j}t||�}t|d�r,t|d�r t
j|j|�St|d�r|jd|�}t|d�r|j|�}t|||�|S#t$rt	��wxYw)NrSr��__self__�__get__�adapt_to_entity)�__dict__�_target�getattrr��AttributeError�hasattrr��
MethodType�__func__rdrer_)r~r�rS�target�attrs     r��__getattr__zAliasedClass.__getattr__s���	(� �M�M�/�:�M�#�*�*�F��6�3�'�D�
�4��$���z�)B��#�#�D�M�M�4�8�8��4��#��<�<��d�+�D��4�*�+��'�'�
�6�D��D�#�t�$����1�	#� �"�"�	#�s�B+�+B?c�R�t||�}t|d�r,t|d�r tj|j|�St|d�r|jd|�}t|d�r8t
j|�|_|j|�}t|||�|S)Nr�rcrdre)rhrjr�rkrlrd�weakref�ref�_weak_entityrer_)r~r��mapped_classr6rns     r��_get_from_serializedz!AliasedClass._get_from_serializeds���
�|�S�)���4��$���z�)B��#�#�D�M�M�4�8�8��4��#��<�<��d�+�D��4�*�+�(/���D�(9�L�%��'�'��5�D��D�#�t�$��r�c�^�dt|�|jjjfzS)Nz<AliasedClass at 0x%x; %s>)�idrSrgr��r~s r�r�zAliasedClass.__repr__5s0��+��t�H����&�&�/�/�/
�
�	
r�c�,�t|j�Sr|)r�rSrxs r��__str__zAliasedClass.__str__;s���4�%�%�&�&r�)	NNFFNNNFF)rTz_EntityType[_O]r��Optional[FromClause]r��
Optional[str]rIr�r,r�rQ�Optional[Sequence[Mapper[Any]]]rU�Optional[ColumnElement[Any]]rVr7rWr�rXr�)r6�AliasedInsp[_O]r��AliasedClass[_O])r�r�r�r)r�r�rtrr6rr�r)r�r�)r�r�r�r�r�r/r�r^rorur�rzr}r�r�rErEus���9�v�M�
'+�"��$�DH�GK�15� %�&+�8=�+�8=�$�8=��	8=�
�8=��
8=�#B�8=�)E�8=�/�8=��8=� $�8=�t��*��	����"�:���&(��8G��	��.
�'r�rErc�(�eZdZUdZdZdejjfdejjfdejjfdejjfdejjfdejjfd	ejjfgZ
d
ed<ded<d
ed<ded<ded<ded<	ded<																							d+d�Ze				d,											d-d��Ze								d.																					d/d��Zed0d��ZdZ	d1d�Zed0d��Zed2d��Zed3d��Zd4d�Zd5d �Zd6d!�Z	d7					d8d"�Zer	d7					d9d#�ZneZd$�Z d%�Z!d&�Z"d'�Z#d(�Z$d)�Z%d*�Z&y):rPa�Provide an inspection interface for an
    :class:`.AliasedClass` object.

    The :class:`.AliasedInsp` object is returned
    given an :class:`.AliasedClass` using the
    :func:`_sa.inspect` function::

        from sqlalchemy import inspect
        from sqlalchemy.orm import aliased

        my_alias = aliased(MyMappedClass)
        insp = inspect(my_alias)

    Attributes on :class:`.AliasedInsp`
    include:

    * ``entity`` - the :class:`.AliasedClass` represented.
    * ``mapper`` - the :class:`_orm.Mapper` mapping the underlying class.
    * ``selectable`` - the :class:`_expression.Alias`
      construct which ultimately
      represents an aliased :class:`_schema.Table` or
      :class:`_expression.Select`
      construct.
    * ``name`` - the name of the alias.  Also is used as the attribute
      name when returned in a result tuple from :class:`_query.Query`.
    * ``with_polymorphic_mappers`` - collection of :class:`_orm.Mapper`
      objects
      indicating all those mappers expressed in the select construct
      for the :class:`.AliasedClass`.
    * ``polymorphic_on`` - an alternate column or SQL expression which
      will be used as the "discriminator" for a polymorphic load.

    .. seealso::

        :ref:`inspection_toplevel`

    )�__weakref__rsrr0r��_adapt_on_namesrQrR�_use_mapper_path�_base_aliasrX�persist_selectable�local_tabler\r]�_adapterrg�__clause_element__�_memoized_values�_all_column_expressions�_nest_adaptersr�r�r�rgr0rQrRz
Mapper[_O]rrIr4r�zSequence[Mapper[Any]]zSequence[AliasedInsp[Any]]r]zweakref.ref[AliasedClass[_O]]rsz!Union[Type[_O], AliasedClass[_O]]c��|j}|j}
tj|�|_|
|_|x|_x|_|_||_||_	tj|xs|�|_
||_|
|_||_
|r�d|_||_g|_|jD]q}||
us�t#|j$|||	|��}t'|j|j$j(|�|j j+|j,��snd|_|
g|_t/t0j2|
||
j4|	d|jD�chc]}|	s|j
��c}d��|_|r<t9|t:�sJ�|j6j=|j6�|_|	|_||_ ycc}w)NT)rVr,rWF)r0r(r,r+r-r8)!r<rrqrrrsr0r�r�r�rRr�r�rXr�r\rQr]rErr_r�r�rSr4rr�_equivalent_columnsr�r�rP�wrapr�rg)r~r<�	inspectedr0r�rQrRr�r�r,rXrZrTr�polyrars                 r�r/zAliasedInsp.__init__�s���'�-�-���!�!��#�K�K��/�������	
���	
�$�1�D�4D���	�,���"�;�;�{�':�d�;��� 0���%:��"�+���#�(,�D�%�,D�D�)�.0�D�+��5�5���v�%�&����"�#'�'5�(8��C��D�K�K����)=�)=�s�C��3�3�:�:�3�;L�;L�M�6�).�D�%�-3�H�D�)�"��(�(��!��2�2�)�!��6�6�$�6�A�%����6�$�
"�
��
�$��i��5�5�5�%�.�.�3�3�D�M�M�B�D�M�-���)����$s�(GNc���t|t�rR|rtjd��|r|j	||��Stjtj||��St|||||��S)Nz+adapt_on_names only applies to ORM elementsrH�rI)r�rIr�r,)
r�rIr�r�r�r=r�r@�AnonymizedFromClauseRolerE)r�elementr�r�rIr,s      r��_alias_factoryzAliasedInsp._alias_factory�s}���g�z�*���*�*�A�����}�}�$�T�}�:�:� �'�'��2�2�G�$��� �����-��
r�c
���t|�}|dvr|rtjd��|j|||��\}}|s|r|�J�|j	|��}t|||	||||
|��S)Nr�z[the 'flat' and 'selectable' arguments cannot be passed simultaneously to with_polymorphic()��	innerjoinr�)r�rQr,rUrWrX)rr�r��_with_polymorphic_argsrOrE)
r�base�classesr0rIrR�aliasedr�r,r�r��primary_mapper�mapperss
             r��_with_polymorphic_factoryz%AliasedInsp._with_polymorphic_factorys���*�$�/���]�*�t��&�&�7��
�
-�C�C��Z�9�D�
�����d��)�)�)�#�9�9�t�9�D�J�����%,�)�+9�,�&/�-�	
�		
r�c��|j�}|�/tj|�}tj|�|_|Sr|)rsrEr^rqrr)r~ras  r�r<zAliasedInsp.entity6s=�����!���;��>�>�t�D�C� '���C� 0�D���
r�Tc�x�|jj|j||d��jd|d��S)N)r>�parententity�entity_namespace�orm��compile_state_plugin�plugin_subject)r0�	_annotater�_set_propagate_attrsrxs r��#_memoized_method___clause_element__z/AliasedInsp._memoized_method___clause_element__Gs@�����(�(� $��� $�$(�
�
��
�%*�d�C�
�
	
r�c��|jSr|)r<rxs r�r�zAliasedInsp.entity_namespaceRs���{�{�r�c�.�|jjS)zUReturn the mapped class ultimately represented by this
        :class:`.AliasedInsp`.)rrrxs r�rzAliasedInsp.class_Vs���{�{�!�!�!r�c�p�|jr|jjStj|�Sr|)r�r�_path_registryr5�
per_mapperrxs r�r�zAliasedInsp._path_registry\s,��� � ��;�;�-�-�-��*�*�4�0�0r�c��|j|j|j|j|j|j
|j|j�|j|j|jd�S)N)r<rr�r�r,rQrUrVrWrXrZ)r<rr0r�r�rQrRr�r�rXr�rxs r��__getstate__zAliasedInsp.__getstate__csj���k�k��k�k��_�_��I�I�"�2�2�(,�(E�(E�.2�.A�.A��*�*�,�#�4�4�%)�%?�%?�!�0�0�
�	
r�c�|�|j|d|d|d|d|d|d|d|d|d	|d
|d�y)Nr<rr�r�rQrUrVrWr,rXrZ)r/)r~r�s  r��__setstate__zAliasedInsp.__setstate__rsg���
�
��(�O��(�O��'�N��&�M��,�-��2�3��,���#�$��"�#��)�*��/�"�	
r�c���|j}|j|usJ�tjd�|jD��}|jD�chc]}|j��}}||k(r|S|j|�}|j
|d|j��\}}|jd��}t||||j|j|j��jScc}w)Nc3�4K�|]}|j���y�wr|)r��.0�mps  r��	<genexpr>z*AliasedInsp._merge_with.<locals>.<genexpr>�s����"
� =�"�B�I�I� =�s�r�Tr�)rQrUrWrX)
rr:�to_setrQr�unionr�rXrOrErRr�rS)	r~�otherr��our_classesr��new_classesr�r�r0s	         r��_merge_withzAliasedInsp._merge_with�s��������{�{�n�,�,�,��k�k�"
� $� =� =�"
�
��,1�+I�+I�J�+I�R�r�y�y�+I��J��+�%��L�!�'�'��4�G�,�C�C��T��)D�)D�%D�D�
���� �5�5�4�5�@�
����%,�+0�+?�+?�!�2�2�"'�"=�"=�

��-�	��Ks�C+c���t|t�sJ�||jd�}|r||d<|jj	|�j|�j
d|d��S)N)r�r>�	proxy_keyr�r�)r�rGrr��traverser�r�)r~�exprr��ds    r��_adapt_elementzAliasedInsp._adapt_element�sh���$�
�.�.�.� � �K�K�
��� �A�k�N�

�M�M�"�"�4�(�
�Y�q�\�
!�
!�).�$�G��	
r�c��yr|r})r~r�r�s   r��_orm_adapt_elementzAliasedInsp._orm_adapt_element�s��r�c��|j}||vrD||jur|St|j|jj
�jS|j|j�r|SJd|�d|����)Nzmapper z doesn't correspond to )rQrrhr<rr�rSrA)r~r�	self_polys   r��_entity_for_mapperzAliasedInsp._entity_for_mapper�sq���1�1�	��Y������$�����K�K����!7�!7���-� ��Z�Z����
$��K�O�&�$�O�O�5r�c���|jj\}}|jj|�|j	�D��cic]!\}}|jj|�|��#c}}fScc}}wr|)r�_get_clauser�r�r�)r~�onclause�
replacemapr��params     r��_memoized_attr__get_clausez&AliasedInsp._memoized_attr__get_clause�su��#�{�{�6�6���*��M�M�"�"�8�,�#-�"2�"2�"4�
�"4�J�C���
�
�&�&�s�+�U�2�"4�
�
�	
��
s�&A2c��iSr|r}rxs r��_memoized_attr__memoized_valuesz+AliasedInsp._memoized_attr__memoized_values�s���	r�c�@�|jr>|jj|jD�cgc]}|j��c}�}n|jj�}|D��cgc]\}}||j	|�f��}}}t|�Scc}wcc}}wr|)r\r�_columns_plus_keysr]r�rD)r~ra�cols_plus_keysr�r�s     r��&_memoized_attr__all_column_expressionsz2AliasedInsp._memoized_attr__all_column_expressions�s����$�$�!�[�[�;�;�'+�'F�'F�G�'F�����'F�G��N�"�[�[�;�;�=�N�=K�
�<J���S�S�$�%�%�c�*�+�N�	�
� ��/�/��H��

s�B�*Bc�n�||jvr|j|S||i|��x|j|<}|Sr|)r�)r~r��	callable_�args�kwr�s      r��_memozAliasedInsp._memo�sE���$�'�'�'��(�(��-�-�1:�D�1G�B�1G�G�D�!�!�#�&���Lr�c��|jr&ddjd�|jD��z}nd}dt|�|jj|fzS)Nz(%s)r�c3�HK�|]}|jj���y�wr|)rr�r�s  r�r�z'AliasedInsp.__repr__.<locals>.<genexpr>�s����+�-J�r��	�	�"�"�-J�s� "r�z<AliasedInsp at 0x%x; %s%s>)rQr�rwrr�)r~�	with_polys  r�r�zAliasedInsp.__repr__�sc���(�(�����+�-1�-J�-J�+�"��I��I�,��t�H��K�K� � ��0
�
�	
r�c�����jr?d�jj�ddj�fd��jD���d�Sd�jj�d�S)Nzwith_polymorphic(z, [r�c3�f�K�|](}|�jur|jj���*y�wr|)rrr�)r�r�r~s  �r�r�z&AliasedInsp.__str__.<locals>.<genexpr>s/������;������,��I�I�&�&�;�s�.1z])rJrK)r\rgr�r�rQrxs`r�rzzAliasedInsp.__str__�s\����$�$����%�%��	�	��"�;�;����
�%�%)�L�L�$9�$9�;�;r�)r<r�r�rGr0rIr�r|rQr}rRr~r�r7r�r�r,r�rXr�rZr�)NNFF)r�z"Union[_EntityType[_O], FromClause]r�r{r�r|rIr�r,r�r�z#Union[AliasedClass[_O], FromClause])FFNFFFNF)r�zUnion[Type[_O], Mapper[_O]]r�z/Union[Literal['*'], Iterable[_EntityType[Any]]]r0z'Union[Literal[False, None], FromClause]rIr�rRr~r�r�r�r�r,r�r�r|r�r�r�r�)r�r�)r�rI)r��Type[_O])r�rY)r��Dict[str, Any])r�r�r��None)r�rr�rr|)r�rUr�r|r�rU)r�r^r�r|r�r^)'r�r�r�r�r�rA�ExtendedInternalTraversal�	dp_string�
dp_boolean�dp_inspectable�dp_clauseelement�InternalTraversal�dp_has_cache_key_list�_cache_key_traversalr�r/r�r�r��propertyr<r5r�r�rr�r�r�r�r�rr�r�r�r�r�r�r�rzr}r�r�rPrP?s>��$�L�I�2
��3�3�=�=�>�	�H�>�>�I�I�J�	�X�?�?�J�J�K�	�H�6�6�E�E�F�	�x�9�9�J�J�K�&��&�&�<�<�	
�
�8�5�5�F�F�G���
������3�3� :�:�/�/�:�
.�.��J*� �J*�+�J*��	J*�
�J*�#B�
J*�5�J*�0�J*��J*��J*� $�J*��J*�X�'+�"��$�
�3��$���	�
���
�
-����8�
?D��7;���$�"�!&�%
�)�%
�A�%
�<�	%
�
�%
�5�
%
��%
��%
��%
��%
��%
�
�%
��%
�N�������	
������"��"�
�1��1�

�

��>7;�
��
�&3�
�	�
�*�"&�	��	��	��		�,��P�
��0��
�<r�rPc�J�eZdZdZdZd�Zejd�d��Zy)�_WrapUserEntityaA wrapper used within the loader_criteria lambda caller so that
    we can bypass declared_attr descriptors on unmapped mixins, which
    normally emit a warning for such use.

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

    ��subjectc��||_yr|r�)r~r�s  r�r/z_WrapUserEntity.__init__s	����r�zsqlalchemy.orm.decl_apic�,�tjjj}tj|d�}||jvrAt|j||j�r|j|j|�St||�S)Nr�)r:�	preloadedr��decl_api�object�__getattribute__rfr��
declared_attr�fgetrh)r~r�r�r�s    r�r�z _WrapUserEntity.__getattribute__s���>�>�%�%�.�.���)�)�$�	�:���7�#�#�#�
����T�"�H�$:�$:�)
��#�#�D�)�.�.�w�7�7��7�D�)�)r�N)	r�r�r�r�r�r/r:�preload_moduler�r}r�r�r�r�s5����I���T���2�3�	*�4�	*r�r�c���eZdZUdZdZdejjfdejjfdejjfdejjfdejjfgZde
d<d	e
d<d
e
d<de
d<de
d<de
d<d
e
d<				d											dd�Zed��Zd�Zdd�Zdd�Z				dd�Z						dd�Zdd�Zd d�Zy)!�LoaderCriteriaOptiona
Add additional WHERE criteria to the load for all occurrences of
    a particular entity.

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

    .. versionadded:: 1.4

    )�root_entityr<�deferred_where_criteria�where_criteria�_where_crit_orig�include_aliases�propagate_to_loadersr�r<r�rrzOptional[Type[Any]]�"Optional[_InternalEntityType[Any]]z9Union[ColumnElement[bool], lambdas.DeferredLambdaElement]r�r�rrc�,�tdtj|d��}|�td|�|_d|_nd|_||_||_t
|�r{|j�
|j}n|�J�|j}d|_tj|tjt|�ftj|����|_n0d|_tj tj|�|_||_||_y)NrCFr�T)�track_closure_variables)�lambda_args�opts)rr8rLr�r<r�callabler�r?�DeferredLambdaElementr@�WhereHavingRoler��
LambdaOptionsr�r=r�rr)	r~�entity_or_baser��loader_onlyrrrr<�wrap_entitys	         r�r/zLoaderCriteriaOption.__init__Os���&����~�u�5�
���>�#�K��@�D���D�K�#�D�� �D�K� .����N�#����+�"�.�.���)�)�)�$�m�m��+/�D�(�")�"?�"?���%�%�,�[�9�;��*�*�,C��	#�D��,1�D�(�"+�"2�"2��%�%�~�#�D�� /���$8��!r�c� �t||||��S)N)rr)r�)rr<r�rrs     r��	_unreducezLoaderCriteriaOption._unreduce�s��$���+�!5�	
�	
r�c���tj|jr|jjn|j|j
|j|jffSr|)r�rr<rr�rrrrxs r��
__reduce__zLoaderCriteriaOption.__reduce__�sP�� �*�*�&*�k�k����"�"�t�7G�7G��%�%��$�$��)�)�	
�
�	
r�c#��K�|jr)|jjjEd{���y|jsJ�t	|jj��}|rv|j
d�}tdtj|d���}|r|jjEd{���n|j|j��|r�uyy7��7�+�w)NrrCF)�raiseerr)r<r�self_and_descendantsr��list�__subclasses__�poprr8rL�extend)r~�stack�subclassras    r��_all_mappersz!LoaderCriteriaOption._all_mappers�s������;�;��{�{�)�)�>�>�>�>��#�#�#�#���)�)�8�8�:�;�E�� �9�9�Q�<���.��&�&�x�%�@����"�z�z�>�>�>�>��L�L��!8�!8�!:�;��	
?��?�s(�0C&�C"�BC&�8C$�9&C&� C&�$C&c�V�|jjjdd�|uryy)N�for_loader_criteriaFT)�select_statementr?r@�r~�
compile_states  r��_should_includez$LoaderCriteriaOption._should_include�s3���*�*�7�7�;�;�%�t�
��
�
�r�c���|jr0td|jj|j��}n|j}t|t�sJ�tj|d|idd��S)N�ColumnElement[bool]rT)�detect_subquery_cols�ind_cols_on_fromclause)	r�rr��_resolve_with_argsr<r�rGr��_deep_annotate)r~�ext_info�crits   r��_resolve_where_criteriaz,LoaderCriteriaOption._resolve_where_criteria�ss���'�'��%��#�#�6�6�x���G��D�
�&�&�D��$�
�.�.�.��&�&��
"�D�)�!%�#'�	
�	
r�c�&�|j|�yr|)�process_compile_state)r~r!�mapper_entitiess   r��'process_compile_state_replaced_entitiesz<LoaderCriteriaOption.process_compile_state_replaced_entities�s��
	
�"�"�=�1r�c�:�|j|j�y)z7Apply a modification to a given :class:`.CompileState`.N)�get_global_criteria�global_attributesr s  r�r-z*LoaderCriteriaOption.process_compile_state�s��	
� � ��!@�!@�Ar�c�z�|j�D](}|jd|fg�}|j|��*y)N�additional_entity_criteria)r�
setdefaultr�)r~rr��
load_criterias    r�r1z(LoaderCriteriaOption.get_global_criteria�sA���#�#�%�B�1�J�1�1�-�r�2�B��M�
� � ��&�&r�N)FFTT)rz_EntityType[Any]r�zXUnion[_ColumnExpressionArgument[bool], Callable[[Any], _ColumnExpressionArgument[bool]]]r
r�rr�rr�rr�)r�zIterator[Mapper[Any]])r!rWr�r�)r)rCr�r$)r!rWr.zIterable[_MapperEntity]r�r�)r!rWr�r�)rzDict[Any, Any]r�r�)r�r�r�r�r�rAr��dp_plain_obj�dp_has_cache_keyr�r�r��_traverse_internalsr�r/r�rrrr"r+r/r-r1r}r�r�r�r�(sZ��	��I�
��:�:�G�G�H�	�8�5�5�F�F�G�	�8�5�5�F�F�G�	�H�6�6�A�A�B�	��!;�!;�!F�!F�G���%�$�.�.�M�M�!�!�������"� %�%)�(,�/9�(�/9�
�/9��/9��/9�#�/9�"&�/9�b�
��
�	
�<�"�
�0�
�	�
�$2�&�2�1�2�
�	2�B�'r�r�c��|jSr|)rS)rms r��<lambda>r;�s
��&�2F�2Fr�c��	t|�}|�|jsy|j}|S#tj$rYywxYwr|)r*�	is_mappedrr�NO_STATE)r�
class_managerrs   r��_inspect_mcr@�sL���,�V�4�
�� �
�(?�(?���%�%���
���<�<����s�*�*�A�Ac�B�tdt|��}t|�S)Nr�)rrNr@)r�origins  r��_inspect_generic_aliasrC�s ���*�j��0�
1�F��v��r�c�*�eZdZUdZdZ	dZdZdZdZe	j�Zded<e	jZded<						dd�Z						dd	�Zedd
��Zedd��Ze		dd
��Zded<	ded<	d�Zd�Zed��Zd�Z								dd�Zy)�Bundlea+A grouping of SQL expressions that are returned by a :class:`.Query`
    under one namespace.

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

    .. seealso::

        :ref:`bundles`


    FTrc�_propagate_attrszList[_ColumnsClauseElement]�exprsc
��|x|_|_|D�cgc](}tjtj
||����*}}||_td�|D�cgc]}|jjd|��� c}D��j�x|_|_|jd|j�|_ycc}wcc}w)a<Construct a new :class:`.Bundle`.

        e.g.::

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

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

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

        )�apply_propagate_attrsc3�NK�|]}t|d|j�|f���y�w)r�N)rh�_label)r�r�s  r�r�z"Bundle.__init__.<locals>.<genexpr>@s*����1
�O���S�%����
,�c�2�O�s�#%�bundle�
single_entityN)r�rKr=r�r@�ColumnsClauseRolerGrDr?r@�as_readonlyr��columnsrrM)r~r�rGr�r��
coerced_exprs�es       r�r/zBundle.__init__$s���&#'�&��	�D�K�
�	
���
����'�'��T�
��		�
�#��
� 0�1
�AN�O��A����*�*�8�Q�7��O�1
�!
��+�-�	����� �V�V�O�T�5G�5G�H����
��Ps�-B?�#C
c
��|j|j|jft|jD�cgc]}|j||���c}�zScc}wr|)r�r�rMr
rG�_gen_cache_key)r~rj�
bindparamsr�s    r�rTzBundle._gen_cache_keyFsT������	�	�4�+=�+=�>��CG�:�:�N�:�4�T�
 �
 ��:�
6�:�N�B
�
�	
��Ns�A
c�X�|jdjjdd�}|S)Nrr>�rGr?r@)r~r�s  r�rz
Bundle.mapperMs,��$(�J�J�q�M�$>�$>�$B�$B��D�%
���	r�c�X�|jdjjdd�}|S)Nrr�rW)r~�ies  r�r<z
Bundle.entityTs-��15���
�2
�
�,�s�s�>�4�0�	��	r��6ReadOnlyColumnCollection[str, KeyedColumnElement[Any]]c��|jSr|)r�rxs r�r�zBundle.entity_namespace[s
���v�v�
r�rPr�c��|jj|j�}|jj|j�|Sr|)r�r�rfr�)r~r��cloneds   r��_clonez
Bundle._clone~s5�����'�'����7�������t�}�}�-��
r�c	��||d�}|j|j�|jdjj	d|j
�}t
j|jD�cgc]}|jj	d|��� c}tjdd��j|�jd|d��Scc}w)	N)rLr�rr�rLF)�_literal_as_text_role�groupr�r�)r�r?rGrFr@r<r>�
ClauseListr@rNr�r�)r~rr�rRs    r�r�zBundle.__clause_element__�s���!%�4�@������4�,�,�-����A��7�7�;�;��d�k�k�
��
�!�!�<@�:�:�F�:�a�!�.�.�$�$�X�q�1�:�F�',�&=�&=��
�
�Y�{�
#�
!�
!�-2�&4���	
��Gs�2#Cc�6�|j�jSr|)r��clausesrxs r�rdzBundle.clauses�s���&�&�(�0�0�0r�c�4�|j�}||_|S)z<Provide a copy of this :class:`.Bundle` passing a new label.)r^r�)r~r�r]s   r�r�zBundle.label�s�����������
r�c�V���t||D�cgc]}d��c}��d��fd�}|Scc}w)aProduce the "row processing" function for this :class:`.Bundle`.

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

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

            from sqlalchemy.orm import Bundle


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

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

                    return proc

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

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

        r}c�F����D�cgc]
}||���c}�Scc}wr|r})r	�proc�keyed_tuple�procss  ��r�rhz)Bundle.create_row_processor.<locals>.proc�s$����e�<�e�d��S�	�e�<�=�=��<s�)r	zRow[Any]r�rr;)r~�queryrj�labels�lrhris  `   @r��create_row_processorzBundle.create_row_processor�s3���L#�6��+?��1�B��+?�@��	>����,@s�	&
N)r�r�rGz_ColumnExpressionArgument[Any]r�r)rjrjrUzList[BindParameter[Any]]r�zTuple[Any, ...])r�zOptional[Mapper[Any]])r�r)r�rZ)rkzSelect[Any]rjz#Sequence[Callable[[Row[Any]], Any]]rlz
Sequence[str]r�zCallable[[Row[Any]], Any])r�r�r�r�rM�is_clause_element�	is_mapperr5�	is_bundler:�
immutabledictrFr��	EMPTY_SET�	proxy_setr/rTr�rr<r�r^r�rdr�rnr}r�r�rErE�s;���$�M�<����I����I�,>�D�,>�,>�,@��)�@����I�&�&� I�� I�!?� I�GJ� I�D
� �
�.F�
�	�
�����������	?����
D�C��0>�=�/��

�2�1��1��+��+�3�+��	+�

#�+r�rEz
Bundle[_T]c�4�tj|ddi|�S)z�Deep copy the given ClauseElement, annotating each element with the
    "_orm_adapt" flag.

    Elements within the exclude collection will be cloned but not annotated.

    �
_orm_adaptT)r�r()r��excludes  r��
_orm_annotaterx�s���"�"�7�\�4�,@�'�J�Jr�c�0�tj|d��S)z�Remove annotations that link a column to a particular mapping.

    Note this doesn't affect "remote" and "foreign" annotations
    passed by the :func:`_orm.foreign` and :func:`_orm.remote`
    annotators.

    )rvr�)r��r��_deep_deannotate�r�s r��_orm_deannotater}�s���$�$��6��r�c�,�tj|�Sr|rzr|s r��_orm_full_deannotater�s���$�$�W�-�-r�c��eZdZdZej
jZdZ						d															d	d�Zd�Z				d
									dd�Z
		d							d
d�Zy)�_ORMJoinz/Extend Join to support ORM constructs as input.TNc	���tdtj|��}	tdtj|��}
|
j}||_||_t
|tj�rbtr&t
|jtj�sJ�|jj�}|j}
||jz
}n-t
|t �r|}
|
j"j}nd}
d}|	j}|
r�t%j&||�r|}nt
|t(�sJ�|}|
j+||d|
d|��\}}}}}}|�7|rt-j.|||�}|}nt-j.||||�}|}n|}||_t3|	�r|j4j7dd�}nt9|	�st;|	�r|	}nd}|�"|j4j=d|i�|_t?|�xr|
}t@jBjE||||||�|jF�J�|r%|xjFt-jH|�zc_#|
s�tK|
dd�rw|
jLjNr`td|
�}
|
jLjP}|�;t;|
�r|
jRjU|�}|jF|z|_#yyyyy)Nz+Union[FromClause, _InternalEntityType[Any]]T)�source_selectable�dest_selectable�source_polymorphic�of_type_entity�alias_secondary�extra_criteriar�rrC)+rr8rLr0�
_left_memo�_right_memor�r�QueryableAttributer�
comparatorr[�
Comparator�_source_selectabler��_extra_criteriar1�parentr��clause_is_presentrI�
_create_joinsr9r��_target_adapterrBr?r@rrr�r�r>�Joinr/r��and_rhr�single�_single_table_criterionr�r�)r~�left�rightr��isouter�fullr�r�r��	left_info�
right_info�adapt_to�
on_selectable�prop�left_selectable�
adapt_from�pj�sj�source�dest�	secondary�target_adapterr��augment_onclause�single_crits                         r�r/z_ORMJoin.__init__�s����9����t�$�
�	�
�9����u�%�
�
��(�(��%���&����h�
� =� =�>��!��'�'�)=�)H�)H����%�/�/�B�B�D�M��$�$�D��x�7�7�7�O�
��.�
1��D� �K�K�2�2�M��D� �M�#�.�.����)�)�-��I�*�
�!�/�:�>�>�>�,�
��"�"�",� (�#'�)� $�.�
#��
��������~���H�H�Y��r�:�E�!�H��8�8�D�)�R��A�D�!�H���#1�D� ���#�*�7�7�;�;����L��I�
&�*?�	�*J�$�L��L��#� $� 1� 1� 7� 7���.�!�D�� ��0�=��X����� � ��t�U�H�g�t�L��}�}�(�(�(���M�M�S�X�X��7�7�M���
�H�d�3��!�!�(�(��8�*�E�J�%�+�+�C�C�K��&�(��4�",�"5�"5�">�">�{�"K�K� $�
�
�� ;��
�'�)�4�r�c���|}t|tj�r'|j}t|tj�r�'|j|usJ�t|j|j|j|j|j|jj��}t||j|j|j|j��S)zlSplice a join into the center.

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

        )r�r�r�)r�r�)r�r9r�r�r�r�r�r�r�r�r�)r~r��leftmostr�s    r��_splice_into_centerz_ORMJoin._splice_into_centerqs�������3�8�8�,��}�}�H���3�8�8�,��z�z�X�%�%�%���I�I��J�J��M�M��L�L�����(�(�7�7�

�����K�K��N�N��M�M��)�)�
�	
r�c�"�t|||||��S)N)r�r��r�)r~r�r�r�r�s     r�r�z
_ORMJoin.join�s����e�X�D�'�J�Jr�c�"�t|||d|��S)NT)r�r�r�)r~r�r�r�s    r��	outerjoinz_ORMJoin.outerjoin�s����e�X�t�$�G�Gr�)NFFNNr})r�rar�rar��Optional[_OnClauseArgument]r�r�r�r�r��
Optional[Any]r�r�r�zTuple[ColumnElement[bool], ...])NFF)
r�rar�r�r�r�r�r�r�r�r�)r�rar�r�r�r�r�r�)r�r�r�r�r>r��__visit_name__�
inherit_cacher/r�r�r�r}r�r�r�r��s��9��_�_�3�3�N��M�15���$(�%)�;=�w<�!�w<�#�w<�.�	w<�
�w<��
w<�"�w<�#�w<�9�w<�r
�@15���K�"�K�.�K��	K�
�K�
�
K�15��	H�"�H�.�H��	H�

�Hr�r�c�B�t|t�rtjd��t|tj
�rL|jr|j}|j}|�t|�stjd|����|}n|}|j||��S)a	Create filtering criterion that relates this query's primary entity
    to the given related instance, using established
    :func:`_orm.relationship()`
    configuration.

    E.g.::

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

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

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


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

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

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

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

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

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

      .. versionadded:: 1.2

    z@with_parent() accepts class-bound mapped attributes, not stringsz6Expected relationship property for with_parent(), got )�from_entity)
r�r�r�r�rr��_of_typer�r�_with_parent)rr�r��mapper_property�prop_ts     r��with_parentr��s���l�$����"�"�N�
�	
�
�D�*�7�7�	8��=�=��-�-�K��-�-���"�*>��+
��&�&��&�'�)��
�!�������x�[��A�Ar�c�D�tj|�}|jS)z�Return True if the given object has a database
    identity.

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

    .. seealso::

        :func:`.was_deleted`

    )r�instance_state�has_identity��object_r�s  r�r�r��s ��
�%�%�g�.�E����r�c�D�tj|�}|jS)z�Return True if the given object was deleted
    within a session flush.

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

    .. seealso::

        :attr:`.InstanceState.was_deleted`

    )rr��was_deletedr�s  r�r�r��s ��
�%�%�g�.�E����r�c��t|�r-t|�r!|j�|j�uryyt|�r|jr||jvS||uSt	|�sJ�|j|�S)z�determine if 'given' corresponds to 'entity', in terms
    of an entity passed to Query that would match the same entity
    being referred to elsewhere in the query.

    TF)rr�r�rQr�
common_parent��givenr<s  r��_entity_corresponds_tor�
s���V�$� ��'��!�!�#�u�'8�'8�':�:���	�u�	%��!�!��U�;�;�;�;��U�?�"��%� � � �����&�&r�c��t|�r0t|�xr#|jxr||uxs||jvSt|�s|j|j�S|jxr||j
vS)a�determine if 'given' corresponds to 'entity', in terms
    of a path of loader options where a mapped attribute is taken to
    be a member of a parent entity.

    e.g.::

        someoption(A).someoption(A.b)  # -> fn(A, A) -> True
        someoption(A).someoption(C.d)  # -> fn(A, C) -> False

        a1 = aliased(A)
        someoption(a1).someoption(A.b)  # -> fn(a1, A) -> False
        someoption(a1).someoption(a1.b)  # -> fn(a1, a1) -> True

        wp = with_polymorphic(A, [A1, A2])
        someoption(wp).someoption(A1.foo)  # -> fn(wp, A1) -> False
        someoption(wp).someoption(wp.A1.foo)  # -> fn(wp, wp.A1) -> True

    )rr�r]rArrQr�s  r��$_entity_corresponds_to_use_path_implr�$s���*�U�#�!�&�)�
P��+�+�+�
P��&��N�F�e�.N�.N�$N�	
�
#�6�
*��y�y����'�'�
�#�#�
9���8�8�8�	
r�c���|jr+||jvxs|jj|�S|jr!||jvxs|j|�S|j|�S)zedetermine if 'given' "is a" mapper, in terms of the given
    would load rows of type 'mapper'.

    )r5rQrrA)r�rs  r��_entity_isar�Hsr��

�����7�7�7�
�5�<�<�;K�;K��<
�	
�
�	'�	'���7�7�7�L�5�9�9�V�;L�L��y�y�� � r�c���d�}t|t�r�tj|�\}}}t|t�rt|t�r
||z
dkrgSt|t�r|dkst|t�r|dkr|�|j||�}|�t|�dd|j�St|�S|dk(r|�yt|||dz�dS)zdcalculate __getitem__ in terms of an iterable query object
    that also has a slice() method.

    c��td��)Nz@negative indexes are not accepted by SQL index / slice operators)�
IndexErrorr}r�r��_no_negative_indexesz&_getitem.<locals>._no_negative_indexes]s���
&�
�	
r�rN���r)r��slicer:�decode_slice�intr�step)�iterable_query�itemr��start�stopr��ress       r��_getitemr�Ws���
��$��� �-�-�d�3���t�T�
�t�S�!��5�#�&��u���!��I����$�����t�S�!�d�Q�h� �"��"�"�5�$�/������9�T�D�4�9�9�4�5�5���9���2�:� �"���t�d�Q�h�7�8��;�;r�c�p�	t|||j�}t|t�S#t$rYywxYwr�)rKr�rOr�	NameError)�raw_annotationr�originating_cls�	annotateds    r��_is_mapped_annotationr�~sE��

B�+����!;�!;�
�	� �	�+@�A�A������s�)�	5�5c��eZdZy)�
_CleanupErrorN)r�r�r�r}r�r�r�r��s��r�r�c	�B�	�tjd|�}|s|S	t|jd�|�}|tjurd}n!	t|t�r
|j}n|S	g}|}	|j||ur|n|jd��|jd�}tjd|�}|�|j|�n�btjd|d	�smtjd
|d	�sTd�	dj�	fd
�|d	jd�D��|d	<dj|�dt!|�dz
zz}|S#t$r'}td|�d|jd��d��|�d}~wwxYw#t$r|cYSwxYw)Nz^([^ \|]+?)\[(.+)\]$rzFor annotation "z%", could not resolve container type "z[".  Please ensure this type is imported at the module level outside of TYPE_CHECKING blocks�ClassVarr6z^["'].*["']$r�z[\[\]]z"' r�c3�H�K�|]}d|j���d����y�w)�"N)�strip)r�rB�
stripcharss  �r�r�z1_cleanup_mapped_str_annotation.<locals>.<genexpr>�s)�����
�6J�d�a��
�
�:�&�'�q�)�6J�s�"r��[�])r��matchrLrar�r��typingr��
issubclassrr��	TypeErrorr��searchr�r��len)
r�r��mmr��ne�real_symbolr�inner�g2r�s
         @r��_cleanup_mapped_str_annotationr��s����
���)�:�	6�B�
�����R�X�X�a�[�*<�=���f�o�o�� ��	��#�4�5�!�l�l��!�!��
�E��E�
�
���B�%�K�[�U�[�[��^�D�
�[�[��^�����0�"�5���=��L�L����
�.
�H�H�(�%��)�4�
�	�	�)�U�2�Y�/��
��I�I�
�6;�B�i�o�o�c�6J�
�
��b�	��X�X�e�_��s�5�z�A�~�(>�?�
����C����z�l�+�!�x�x��{�m�,.�
.�
�
�	���� �	���	�s)�E�F�	F
�&"F�F
�F�Fc		�"�|�6|r3tjd|j�d|�d|j�d���y	t|||t��}	|r|	dfSt|	d
�rt|	t�sr|rl|syt|	d
d�}|tjuryt|t�rt|t �rytjd|j�d|�d�d
���|	dfSt#|	j$�dk7rtjd��t'|	j$d�|	j(fS#t
$r}
tjd|�d��|
�d}
~
wt$r-}|rd	|vrtjd|�d��|�|}	Yd}~��<d}~wwxYw)z�given an annotation, figure out if it's ``Mapped[something]`` and if
    so, return the ``something`` part.

    Includes error raise scenarios and other options.

    Nz4Python typing annotation is required for attribute "�.z " when primary argument(s) for "z#" construct are None or not present)ryzCould not interpret annotation zt.  Check that it uses names that are correctly imported at the module level. See chained stack trace for more hints.zMapped[�
__origin__zType annotation for "a" can't be correctly interpreted for Annotated Declarative Table form.  ORM annotations should normally make use of the ``Mapped[]`` generic type, or other ORM-compatible generic type, as a container for the actual type, which indicates the intent that the attribute is mapped. Class variables that are not intended to be mapped by the ORM should use ClassVar[].  To allow Annotated Declarative to disregard legacy annotations which don't use Mapped[] to pass, set "__allow_unmapped__ = True" on the class or a superclass this class.�zlpr)�coderz)Expected sub-type for Mapped[] annotationr)r�r�r�rKr�r�r�rjrOrrhr�r�r�r�r�r+r��__args__rMr�)
r�rr�r��attr_cls�required�is_dataclass_field�
expect_mappedrr��cer�rBs
             r��_extract_mapped_subtyper�s���$����&�&���L�L�>��3�%�(��%�%�&�&I�K��
�
�#�,����9�	
�	�,��$����y�,�/�7G��,�8
���� ��L�$�?���V�_�_�,�� ���-�*��M�3� ��*�*�+�C�L�L�>��3�%�@-�-� ���$!�$��&��y�!�!�"�a�'��&�&�;��
�
%�Y�%7�%7��%:�;�� � �
�	
��}���"�"�-�n�-=�>D�
D�
��		��
�#��	�^�3��&�&�1�.�1A�BH�H���	
�#�	��#�s#�D2�2	F�;E�F�!"F	�	Fc�l�t|d�r|j�}nd}tj||�S)N�_mapper_property_name)rjrr:�clsname_as_plain_name)r�r�s  r��_mapper_property_as_plain_namer]	s3���t�,�-��)�)�+�����%�%�d�D�1�1r�)�p_unionT)NN)rzOptional[Type[_T]]rzUnion[Any, Tuple[Any, ...]]rzOptional[_T]r	z%Optional[Union[Row[Any], RowMapping]]r
r�r�z_IdentityKeyType[_T])rr�r�zOptional[Mapper[_O]]r|)r�rdrwr�r�rd)r�rdr�rd)rr�r�z"attributes.QueryableAttribute[Any]r�zOptional[_EntityType[Any]]r�r$)r�r�r�r�)r�rCr<rCr�r�)r�rCrzMapper[Any]r�r�)r�z
Query[Any]r�rr�r)r�rkrr�r�r�r�r�)r�r�r�r�r�r�)TT)r�zOptional[_AnnotationScanType]rr�r�r�r�r�r�r�r�r�rr�rr�rr�r�z@Optional[Tuple[Union[_AnnotationScanType, str], Optional[type]]])r�r�r�r�)��
__future__rr�	functoolsr�r�r�rrrrrr	r
rrr
rrrrrrrrrqr�rr�_typingrrrrr�rrrr r!r"r#r$r%r&r'r(r)r*r+r,r-r.r/�
interfacesr0r1r2r3r4�
path_registryr5r7r�r8r9r:�
engine.resultr<r=r>r?r@r�rA�sql._typingrB�sql.annotationrC�sql.baserD�
sql.cache_keyrErF�sql.elementsrGrH�sql.selectablerI�util.langhelpersrJ�util.typingrK�_de_stringify_annotationrL�_eval_name_onlyrMrNrOrPrQrRrSrTrU�contextrVrWrrXrYrkrZ�
relationshipsr[�enginer\r]r^r_r`rarbrcrdrerfrgrhri�sql.visitorsrjrkrl�	frozensetr��partialrr�_de_stringify_partialrxr�r�r�r�rr�Enumr�
ColumnAdapterr%r4�InspectablerE�_self_inspectsrPr�r��	_inspectsr�r@�GenericAliasrCrErxr}rr�r�r�r�r�r�r�r�r�r��	Exceptionr�r�rrr}r�r��<module>r's���#���	��
���������������� �������*�#�)�6�'�*�2�(�0�.��2�.��0�.�&��<�4�(�!�&�8�,�2�)�7������(�����"��'�5�'�'�/�(�-�'�,�M�;�2�$�*�!�"�	���$�)�,�$�&�(��5��3��#�!�7�2�1�/�1�$�3�,�6�'�+�'�1��T�����	���*�	�)�)�
����D����.�*�	
�
�	��	�X�	���1�2J�K���
@�H�@��m�%:�?�%K�L��F�Y�s�^�F�R?D�F=A�O3�f"&�)-�UD�"�15�$(�
UD��UD�&�UD��	UD�

/�UD�"�
UD��UD�p9+�d�i�i�9+�x
�(�0�0�
�:2P��'�'�2P�jG'����,�-�/C�B�/G�G'�T���I<��r�"��������,�-��B�K�I<��I<�X*�*�8p'�>�p'�f#��
���\�"�#F�G�����d����������D��I�������l�#������$�����Y���������<�(��Y��Y�xK��.�lH�z���lH�d/3�IB��IB�
,�IB�,�IB��	IB�X
� �"'�#�'�-E�'�	�'�.!
�#�!
�-E�!
�	�!
�H!�$<�NB�'�B�	�B��B�
�	B�*	�I�	�W��W�),�W��W�D��i
�1�i
�	
�i
��i
�

�	i
�
�i
��
i
��i
��i
��i
�F�i
�X2r�

ZeroDay Forums Mini