AlkantarClanX12

Your IP : 3.22.77.191


Current Path : /opt/cloudlinux/venv/lib/python3.11/site-packages/sqlalchemy/orm/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/sqlalchemy/orm/__pycache__/util.cpython-311.pyc

�

�܋f������ddlZddlZddlZddlmZddlmZddlmZddlmZddlm	Z	ddlm
Z
dd	lmZdd
lmZddlm
Z
ddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZed��Z Gd�de��Z!d�Z"	d;d �Z#d!�Z$Gd"�d#ej%��Z&Gd$�d%e'��Z(Gd&�d'e��Z)ej*e(��d(���ej*e)��d)���d<d+�Z+							d=d,�Z,d>d-�Z-d.�Z.d/�Z/Gd0�d1ej0��Z1	d?d2�Z2d@d3�Z3d>d4�Z4d5�Z5d6�Z6d7�Z7d8�Z8d9�Z9d:�Z:dS)A�N�)�
attributes)�_class_to_mapper)�
_never_set)�	_none_set)�
attribute_str)�class_mapper)�InspectionAttr)�instance_str)�
object_mapper)�object_state)�state_attribute_str)�state_class_str)�	state_str)�MapperProperty)�PropComparator)�PathRegistry�)�event)�exc)�
inspection)�sql)�util)�
expression)�delete�
delete-orphan�all�merge�expunge�save-update�refresh-expire�nonec�r�eZdZdZe�gd���ZeZgd�ZdZ	d�Z
d�Zed���Z
dS)	�CascadeOptionszHKeeps track of the options sent to
    :paramref:`.relationship.cascade`)rr"r)rrr"r!)�save_updater�refresh_expirerr�
delete_orphanc���t|tj��s|�|�|��St	|��}|�|j��rYtjdd�	d�t|�|j����D����z���d|vr|�|j��d|vr|�
��|�d��t�t"|��}d|v|_d|v|_d|v|_d	|v|_d
|v|_d|v|_|jr|jstjd��|S)
NzInvalid cascade option(s): %s�, c�,�g|]}t|����S�)�repr��.0�xs  �J/opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/orm/util.py�
<listcomp>z*CascadeOptions.__new__.<locals>.<listcomp>Ps.�������Q������rr"r rr!rrrz5The 'delete-orphan' cascade option requires 'delete'.)�
isinstancer�string_types�from_string�set�
difference�_allowed_cascades�sa_exc�
ArgumentError�join�sorted�update�_add_w_all_cascades�clear�discard�	frozenset�__new__r$r%rr&rrr'�warn)�cls�
value_list�values�selfs    r0rBzCascadeOptions.__new__Hs����j�$�"3�4�4�	/�
�8J��?�?�:�.�.�.��Z�������S�2�3�3�	��&�/��)�)���!'�"�-�-�c�.C�D�D�"�"�������
�
�

��F�?�?��M�M�#�1�2�2�2��V����L�L�N�N�N����u����� � ���8�8��(�F�2����&�(���.�&�8�����&��
� �F�*���,��6�����	�d�k�	��I�J�
�
�
��r2c�`�dd�d�t|��D����zS)NzCascadeOptions(%r)�,c��g|]}|��Sr+r+r-s  r0r1z+CascadeOptions.__repr__.<locals>.<listcomp>ns��0I�0I�0I�q��0I�0I�0Ir2)r;r<�rGs r0�__repr__zCascadeOptions.__repr__ms.��#�s�x�x�0I�0I�F�4�L�L�0I�0I�0I�'J�'J�K�Kr2c�Z�d�tjd|pd��D��}||��S)Nc��g|]}|�|��Sr+r+)r.�cs  r0r1z.CascadeOptions.from_string.<locals>.<listcomp>rs��B�B�B���B�!�B�B�Br2z\s*,\s*�)�re�split)rD�argrFs   r0r5zCascadeOptions.from_stringps3��B�B�R�X�j�#�)��<�<�B�B�B���s�6�{�{�r2N)�__name__�
__module__�__qualname__�__doc__�all_cascadesr7r>r8�_viewonly_cascades�	__slots__rBrL�classmethodr5r+r2r0r$r$4s�������)�)�'�1�1�(�(�(����%��E�E�E���I�#�#�#�JL�L�L�����[���r2r$c�`����	��s�fd��	|r!�	���fd�}�	���fd�}�	���fd�}�	���fd�}n�	���fd�}�	���fd�}�	���fd�}tj|d	|d
d
���tj|d|d
�
��tj|d|d
d
���|rtj|d|d
d
���dSdS)zNRuns a validation method on an attribute value to be set or
    appended.
    c�:��|j�j}|j|uS�N)�manager�impl)�state�	initiatorr`�keys   �r0�detect_is_backrefz,_validator_events.<locals>.detect_is_backref}s����=��%�*�D��>��-�-r2c���|jtjur.�s�||��s �|����|d��S|S�NF��opr�OP_BULK_REPLACE�obj�ra�valuerbrd�include_backrefsrc�	validators   ����r0�appendz!_validator_events.<locals>.append�sU����|�:�#=�=�=� �>�(9�(9�%��(K�(K�>�!�y������c�5�%�@�@�@��r2c�|����s�||��s+|�������fd�|D��|dd�<dSdS)Nc�,��g|]}���|d����S)Fr+�r.rlrcrjrns  ���r0r1z7_validator_events.<locals>.bulk_set.<locals>.<listcomp>�s6������:?�I�I�c�3��u�5�5���r2�rj�rarFrbrjrdrmrcrns   @����r0�bulk_setz#_validator_events.<locals>.bulk_set�sv�����
�'8�'8��	�'J�'J�
��i�i�k�k��������CI�����q�q�q�	�	�	�
�
r2c�d���s�||��s �|����|d��S|Srfrs�rarl�oldvaluerbrdrmrcrns    ����r0�set_z_validator_events.<locals>.set_�sC����
�'8�'8��	�'J�'J�
� �y������c�5�%�@�@�@��r2c�h���s�||��s"�|����|d��dSdS)NTrsrks   ����r0�removez!_validator_events.<locals>.remove�sN����
9�'8�'8��	�'J�'J�
9��	�%�)�)�+�+�s�E�4�8�8�8�8�8�
9�
9r2c���|jtjur-�s�||��s�|����|��S|Sr^rgrks   ����r0roz!_validator_events.<locals>.append�sS����|�:�#=�=�=� �>�(9�(9�%��(K�(K�>�!�y������c�5�9�9�9��r2c�|����s�||��s+|�������fd�|D��|dd�<dSdS)Nc�*��g|]}���|����Sr+r+rrs  ���r0r1z7_validator_events.<locals>.bulk_set.<locals>.<listcomp>�s'���L�L�L�E�Y�Y�s�C��7�7�L�L�Lr2rsrts   @����r0ruz#_validator_events.<locals>.bulk_set�sg�����
M�'8�'8��	�'J�'J�
M��i�i�k�k��L�L�L�L�L�L�V�L�L�L��q�q�q�	�	�	�
M�
Mr2c�b���s�||��s�|����|��S|Sr^rsrws    ����r0ryz_validator_events.<locals>.set_�sA����
�'8�'8��	�'J�'J�
� �y������c�5�9�9�9��r2roT)�raw�retval�bulk_replace)r�r6r{N)r�listen)
�descrcrn�include_removesrmroruryr{rds
 `` `    @r0�_validator_eventsr�vs�������
�.�	.�	.�	.�	.�	.��.�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	9�	9�	9�	9�	9�	9�	9�	9�	9�	�	�	�	�	�	�	�	�	M�	M�	M�	M�	M�	M�	M�	M�
	�	�	�	�	�	�	�	�
�L��x��T�$�?�?�?�?�	�L��~�x�T�:�:�:�:�	�L��u�d��T�:�:�:�:��D�
��T�8�V��d�C�C�C�C�C�C�D�Dr2�p_unionTc�"��
���
�tj��}i�i�
|D]�}||�t�tj��r������||<i}�jD]5}|�|j��|||j<|j	�
|j<�6|��<�����
fd��
g}|�
��D]�\}	�|�s|�tj�
�fd�|D��tj
tj|	�����|��gz�g������z|�tj�
�fd�|D���g�������tj|��|��S)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.

    c�F��	�||S#t$r��rAtjtj���|���|��cYStjtj���|���|��cYSwxYwr^)�KeyErrorr�cast�null�label�type_coerce)�name�table�
cast_nulls�colnamemaps�typess  ���r0�colzpolymorphic_union.<locals>.col�s����	L��u�%�d�+�+���	L�	L�	L��
L��x���
�
�E�$�K�8�8�>�>�t�D�D�D�D�D���s�x�z�z�5��;�?�?�E�E�d�K�K�K�K�K�		L���s�
�AB �?B �B Nc�(��g|]}�|�����Sr+r+�r.r�r�r�s  ��r0r1z%polymorphic_union.<locals>.<listcomp>��%���;�;�;�$�S�S��u�%�%�;�;�;r2)�from_objc�(��g|]}�|�����Sr+r+r�s  ��r0r1z%polymorphic_union.<locals>.<listcomp>�r�r2)r�
OrderedSetr3r�Select�aliasrO�addrc�type�itemsro�select�literal_column�sql_util�_quote_ddl_exprr��	union_all)�	table_map�typecolname�	aliasnamer��colnamesrc�mrO�result�type_r�r�r�r�s   `      @@@@r0�polymorphic_unionr��s��������,�� � �H��K��E������#����e�S�Z�(�(�	#��K�K�M�M�E�"�I�c�N�����	"�	"�A��L�L�������A�a�e�H��6�E�!�%�L�L���E���L�L�L�L�L�L�L��F�!���)�)�����u��"��M�M��
�;�;�;�;�;�(�;�;�;��*�$�4�U�;�;����%��,�,���$�W����

�

�

�

�
�M�M��
�;�;�;�;�;�(�;�;�;�u�g����
�
�
�
�
�=�&�!�'�'�	�2�2�2r2c��|�rd}t|��}|dkrD|d}	|�d��}nF#t$r|�d��}Yn%wxYw|dvr|\}}ntjd|z���|�dd��}|r*tjd	d
�|��z���t
|��}|�)|�tj	|��|���S|�
||���S|�d��}|r/tjd	d
�|j��z���t|��}|�
|��S)
a)Generate "identity key" tuples, as are used as keys in the
    :attr:`.Session.identity_map` dictionary.

    This function has several call styles:

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

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

      E.g.::

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

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

        .. versionadded:: 1.2 added identity_token


    * ``identity_key(instance=instance)``

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

      E.g.::

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

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

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

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

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

      E.g.::

        >>> row = engine.execute("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:`.RowProxy` row returned by a
       :class:`_engine.ResultProxy`
       (must be given as a keyword arg)
      :param identity_token: optional identity token

        .. versionadded:: 1.2 added identity_token

    Nrr�row�ident)r�z1expected up to three positional arguments, got %s�identity_tokenzunknown keyword arguments: %sr))r��instance)�len�popr�r9r:r;r	�identity_key_from_primary_keyr�to_list�identity_key_from_row�keysr�identity_key_from_instance)	�args�kwargsr��largs�class_r�r��mapperr�s	         r0�identity_keyr�s���@�%;����D�	�	���A�:�:��!�W�F�
,��j�j��'�'�����
,�
,�
,��
�
�7�+�+����
,����
�f�_�_� �M�F�E�E��&�F��N���
� ���$4�d�;�;���	��&�/�$�)�)�F�2C�2C�C���
��f�%�%���;��7�7���U�#�#�N�8���
��/�/��N�0���
��:�:�j�)�)���	��&�/�$�)�)�F�K�2H�2H�H���
��x�(�(���0�0��:�:�:s�:�A�Ac�(�eZdZdZ				dd�Zd�ZdS)�
ORMAdapterzaColumnAdapter subclass which excludes adaptation of entities from
    non-matching mappers.

    NFTc	���tj|��}|j|_|j}|j}|r||_nd|_tj�|||||||j	���dS)N)�adapt_required�allow_label_resolve�anonymize_labels�
include_fn)
r�inspectr��
selectable�is_aliased_class�
aliased_classr��
ColumnAdapter�__init__�_include_fn)	rG�entity�equivalentsr�r�r��infor�r�s	         r0r�zORMAdapter.__init__os����!�&�)�)���k����_�
��0���	&�!'�D���!%�D����'�'����)� 3�-��'�	(�	
�	
�	
�	
�	
r2c�r�|j�dd��}|p|�|j��S)N�parentmapper)�_annotations�get�isar�)rG�elemr�s   r0r�zORMAdapter._include_fn�s5���"�&�&�~�t�<�<���z�4�V�Z�Z���4�4�4r2)NFTF)rTrUrVrWr�r�r+r2r0r�r�isO���������� ��

�
�
�
�85�5�5�5�5r2r�c�>�eZdZdZ									d	d�Zd�Zd�Zd�ZdS)
�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`


    NFr+c���t|��}|�|j�||���}t|||||r|n|j|�|n|j||	||
�
�
|_d|jjz|_dS)N)r��flatzAliasedClass_%s)	r�_with_polymorphic_selectabler��AliasedInsp�with_polymorphic_mappers�polymorphic_on�
_aliased_inspr�rT)rGrDr�r�r��adapt_on_namesr��with_polymorphic_discriminator�
base_alias�use_mapper_path�represents_outer_joinr�s            r0r�zAliasedClass.__init__�s���"�#�&�&���=��7�=�=���>���E�)�����'�
1�$�$��0�-�9�
+�*��&����!�
�
���"*�F�M�,B�B��
�
�
r2c��	|jd}|j}t||��}n#t$rt	���wxYwt|d��r*t|d��rt
j|j|��St|d��r|�	d|��}t|d��r&|�
|��}t|||��|S)Nr��__call__�__self__�__get__�adapt_to_entity)�__dict__�_target�getattrr��AttributeError�hasattrr��
MethodType�__func__r�r��setattr)rGrcr��target�attrs     r0�__getattr__zAliasedClass.__getattr__�s���	(� �M�/�:�M�#�*�F��6�3�'�'�D�D���	#�	#�	#� �"�"�"�	#�����4��$�$�	9���z�)B�)B�	9��#�D�M�4�8�8�8��4��#�#�	,��<�<��d�+�+�D��4�*�+�+�	%��'�'�
�6�6�D��D�#�t�$�$�$��s	�
'�Ac�H�dt|��|jjjfzS)Nz<AliasedClass at 0x%x; %s>)�idr�r�rTrKs r0rLzAliasedClass.__repr__s)��+��t�H�H���&�/�/
�
�	
r2c�*�t|j��Sr^)�strr�rKs r0�__str__zAliasedClass.__str__s���4�%�&�&�&r2)	NNFFr+NNFF)rTrUrVrWr�r�rLr�r+r2r0r�r��s�������8�8�z�
�
��!#�'+���#�%C�%C�%C�%C�N���:
�
�
�'�'�'�'�'r2r�c���eZdZdZd�Zed���ZdZ	ed���Zed���Z	d�Z
d�Zd	�Zd
�Z
ejd���Zejd���Zd
�Zd�Zd�ZdS)r�a�Provide an inspection interface for an
    :class:`.AliasedClass` object.

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

        from sqlalchemy import inspect
        from sqlalchemy.orm import aliased

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

    Attributes on :class:`.AliasedInsp`
    include:

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

    .. seealso::

        :ref:`inspection_toplevel`

    c�b�tj|��|_||_|x|_x|_|_||_||_tj|p|��|_	||_
|
|_|r|d|_||_
g|_|j
D]^}||urXt|j|||	|���}t#|j|jj|��|j�|j���_nd|_|g|_
t-j||j|	d���|_|	|_|j|_dS)NT)r�r�r�F)r�r�r�)�weakref�ref�_weak_entityr�r��persist_selectable�local_tabler�r��_base_alias�_use_mapper_pathr��_is_with_polymorphicr��_with_polymorphic_entitiesr�r�r�r�rTror�r�r��_equivalent_columns�_adapter�_adapt_on_namesr�)
rGr�r�r�r�r�r�rrr�r��poly�ents
             r0r�zAliasedInsp.__init__@se��$�K��/�/������ *�	*���	*��#�����	�,���"�;�{�':�d�;�;��� 0���%:��"�#�	5�(,�D�%�,D�D�)�.0�D�+��5�
N�
N���v�%�%�&���"�#'�'5�(8����C��D�K���)=�s�C�C�C��3�:�:�3�;L�M�M�M��
N�).�D�%�-3�H�D�)� �.���2�)�!�	
�
�
��
� .����}����r2c�*�|���Sr^)r�rKs r0r�zAliasedInsp.entityws��� � �"�"�"r2Tc��|jjS)zUReturn the mapped class ultimately represented by this
        :class:`.AliasedInsp`.)r�r�rKs r0r�zAliasedInsp.class_~s���{�!�!r2c�P�|jr|jjStj|��Sr^)rr��_path_registryr�
per_mapperrKs r0r
zAliasedInsp._path_registry�s)��� �	1��;�-�-��*�4�0�0�0r2c��|j|j|j|j|j|j|j|���|j|j	d�
S)N)
r�r�r�r�r�r�r�r�r�r�)
r�r�r�r�rr�r�rrr�rKs r0�__getstate__zAliasedInsp.__getstate__�sR���k��k��_��I�"�2�(,�(E�.2�.A��*�*�,�,�#�4�%)�%?�
�
�	
r2c
��|�|d|d|d|d|d|d|d|d|d	|d
�
�
dS)Nr�r�r�r�r�r�r�r�r�r�)r�)rGras  r0�__setstate__zAliasedInsp.__setstate__�ss���
�
��(�O��(�O��'�N��&�M��,�-��2�3��,���#�$��"�#��)�*�	
�	
�	
�	
�	
r2c�l�|j�|���||jd���S)N)�parententityr�)r�traverse�	_annotater�)rGr�s  r0�_adapt_elementzAliasedInsp._adapt_element�s7���}�%�%�d�+�+�5�5�!�4�;�?�?�
�
�	
r2c���|j}||vr/||jur|St|j|jj��jS|�|j��r|SJd|�d|�����)NFzmapper z doesn't correspond to )r�r�r�r�r�rTr�r�)rGr��	self_polys   r0�_entity_for_mapperzAliasedInsp._entity_for_mapper�s����1�	��Y������$�$�����K���!7���� ��Z�Z���
$�
$�	P��K�O�O�&�&�&�$�$�O�O�O�5r2c����jj\}}�j�|���fd�|���D��fS)Nc�L��i|] \}}�j�|��|��!Sr+)rr)r.r��paramrGs   �r0�
<dictcomp>z+AliasedInsp._get_clause.<locals>.<dictcomp>�s?���
�
�
��C���
�&�&�s�+�+�U�
�
�
r2)r��_get_clauserrr�)rG�onclause�
replacemaps`  r0rzAliasedInsp._get_clause�sa���#�{�6���*��M�"�"�8�,�,�
�
�
�
�",�"2�"2�"4�"4�
�
�
�
�	
r2c��iSr^r+rKs r0�_memoized_valueszAliasedInsp._memoized_values�s���	r2c�V�||jvr
|j|S||i|��x|j|<}|Sr^)r#)rGrc�	callable_r��kwrls      r0�_memozAliasedInsp._memo�sD���$�'�'�'��(��-�-�1:��D�1G�B�1G�1G�G�D�!�#�&���Lr2c��|jr(dd�d�|jD����z}nd}dt|��|jj|fzS)Nz(%s)r)c3�.K�|]}|jjV��dSr^)r�rT�r.�mps  r0�	<genexpr>z'AliasedInsp.__repr__.<locals>.<genexpr>�s8����+�+�')��	�"�+�+�+�+�+�+r2rPz<AliasedInsp at 0x%x; %s%s>)r�r;r�r�rT)rG�	with_polys  r0rLzAliasedInsp.__repr__�su���(�	�����+�+�-1�-J�+�+�+�"�"��I�I��I�,��t�H�H��K� ��0
�
�	
r2c����jr7d�jj�dd��fd��jD�����d�Sd�jj�d�S)Nzwith_polymorphic(z, [r)c3�B�K�|]}|�ju�|jjV��dSr^)r�r�rT)r.r+rGs  �r0r,z&AliasedInsp.__str__.<locals>.<genexpr>�sA�����������,�,��I�&�,�,�,�,��r2z])zaliased(�))rr�rTr;r�rKs`r0r�zAliasedInsp.__str__�s�����$�
	<�
	<���%�%�%��	�	�����"�;���������
�
	<�%)�L�$9�$9�$9�;�;r2N)rTrUrVrWr��propertyr�r�r�r
rrrrr�memoized_propertyrr#r'rLr�r+r2r0r�r�s3������$�$�L5%�5%�5%�n�#�#��X�#����
�"�"��X�"�
�1�1��X�1�
�
�
�
�
�
�
�
�
�
P�P�P�
��
�
���
�
����������
�
�
�<�<�<�<�<r2r�c��|jSr^)r��r�s r0�<lambda>r5�s	��&�2F�r2c��|Sr^r+r4s r0r5r5�s���r2Fc��t|tj��r-|rtjd���|�||���St
|||||���S)a�Produce an alias of the given element, usually an :class:`.AliasedClass`
    instance.

    E.g.::

        my_alias = aliased(MyClass)

        session.query(MyClass, my_alias).filter(MyClass.id > my_alias.id)

    The :func:`.aliased` function is used to create an ad-hoc mapping of a
    mapped class to a new selectable.  By default, a selectable is generated
    from the normally mapped selectable (typically a :class:`_schema.Table`)
    using the
    :meth:`_expression.FromClause.alias` method. However, :func:`.aliased`
    can also be
    used to link the class to a new :func:`_expression.select` statement.
    Also, the :func:`.with_polymorphic` function is a variant of
    :func:`.aliased` that is intended to specify a so-called "polymorphic
    selectable", that corresponds to the union of several joined-inheritance
    subclasses at once.

    For convenience, the :func:`.aliased` function also accepts plain
    :class:`_expression.FromClause` constructs, such as a
    :class:`_schema.Table` or
    :func:`_expression.select` construct.   In those cases, the
    :meth:`_expression.FromClause.alias`
    method is called on the object and the new
    :class:`_expression.Alias` object returned.  The returned
    :class:`_expression.Alias` is not
    ORM-mapped in this case.

    :param element: element to be aliased.  Is normally a mapped class,
     but for convenience can also be a :class:`_expression.FromClause`
     element.

    :param alias: Optional selectable unit to map the element to.  This is
     usually used to link the object to a subquery, and should be an aliased
     select construct as one would produce from the
     :meth:`_query.Query.subquery` method or
     the :meth:`_expression.Select.alias` methods of the
     :func:`_expression.select` construct.

    :param name: optional string name to use for the alias, if not specified
     by the ``alias`` parameter.  The name, among other things, forms the
     attribute name that will be accessible via tuples returned by a
     :class:`_query.Query` object.

    :param flat: Boolean, will be passed through to the
     :meth:`_expression.FromClause.alias` call so that aliases of
     :class:`_expression.Join` objects
     don't include an enclosing SELECT.  This can lead to more efficient
     queries in many circumstances.  A JOIN against a nested JOIN will be
     rewritten as a JOIN against an aliased SELECT subquery on backends that
     don't support this syntax.

     .. seealso:: :meth:`_expression.Join.alias`

    :param adapt_on_names: if True, more liberal "matching" will be used when
     mapping the mapped columns of the ORM entity to those of the
     given selectable - a name-based match will be performed if the
     given selectable doesn't otherwise have a column that corresponds
     to one on the entity.  The use case for this is when associating
     an entity with some derived selectable such as one that uses
     aggregate functions::

        class UnitPrice(Base):
            __tablename__ = 'unit_price'
            ...
            unit_id = Column(Integer)
            price = Column(Numeric)

        aggregated_unit_price = Session.query(
                                    func.sum(UnitPrice.price).label('price')
                                ).group_by(UnitPrice.unit_id).subquery()

        aggregated_unit_price = aliased(UnitPrice,
                    alias=aggregated_unit_price, adapt_on_names=True)

     Above, functions on ``aggregated_unit_price`` which refer to
     ``.price`` will return the
     ``func.sum(UnitPrice.price).label('price')`` column, as it is
     matched on the name "price".  Ordinarily, the "price" function
     wouldn't have any "column correspondence" to the actual
     ``UnitPrice.price`` column as it is not a proxy of the original.

    z+adapt_on_names only applies to ORM elements�r�)r�r�r�r�)r3r�
FromClauser9r:r�r�)�elementr�r�r�r�s     r0�aliasedr;�sx��n�'�:�0�1�1�

��	��&�=���
��}�}�T��}�-�-�-������)�
�
�
�	
r2c	�n�t|��}	|rZ|j|	usJ�tj|��}t	d�|jD����}
||
kr|S|�|
��}|	�|||���\}}|s|r|�|���}t||||||���S)a�Produce an :class:`.AliasedClass` construct which specifies
    columns for descendant mappers of the given base.

    Using this method will ensure that each descendant mapper's
    tables are included in the FROM clause, and will allow filter()
    criterion to be used against those tables.  The resulting
    instances will also have those columns already loaded so that
    no "post fetch" of those columns will be required.

    .. seealso::

        :ref:`with_polymorphic` - full discussion of
        :func:`_orm.with_polymorphic`.

    :param base: Base class to be aliased.

    :param classes: a single class or mapper, or list of
        class/mappers, which inherit from the base class.
        Alternatively, it may also be the string ``'*'``, in which case
        all descending mapped classes will be added to the FROM clause.

    :param aliased: when True, the selectable will be wrapped in an
        alias, that is ``(SELECT * FROM <fromclauses>) AS anon_1``.
        This can be important when using the with_polymorphic()
        to create the target of a JOIN on a backend that does not
        support parenthesized joins, such as SQLite and older
        versions of MySQL.   However if the
        :paramref:`.with_polymorphic.selectable` parameter is in use
        with an existing :class:`_expression.Alias` construct,
        then you should not
        set this flag.

    :param flat: Boolean, will be passed through to the
     :meth:`_expression.FromClause.alias` call so that aliases of
     :class:`_expression.Join`
     objects don't include an enclosing SELECT.  This can lead to more
     efficient queries in many circumstances.  A JOIN against a nested JOIN
     will be rewritten as a JOIN against an aliased SELECT subquery on
     backends that don't support this syntax.

     Setting ``flat`` to ``True`` implies the ``aliased`` flag is
     also ``True``.

     .. versionadded:: 0.9.0

     .. seealso:: :meth:`_expression.Join.alias`

    :param selectable: a table or select() statement that will
        be used in place of the generated FROM clause. This argument is
        required if any of the desired classes use concrete table
        inheritance, since SQLAlchemy currently cannot generate UNIONs
        among tables automatically. If used, the ``selectable`` argument
        must represent the full set of tables and columns mapped by every
        mapped class. Otherwise, the unaccounted mapped columns will
        result in their table being appended directly to the FROM clause
        which will usually lead to incorrect results.

    :param polymorphic_on: a column to be used as the "discriminator"
        column for the given selectable. If not given, the polymorphic_on
        attribute of the base classes' mapper will be used, if any. This
        is useful for mappings that don't have polymorphic loading
        behavior by default.

    :param innerjoin: if True, an INNER JOIN will be used.  This should
       only be specified if querying for one specific subtype only
    c��g|]	}|j��
Sr+)r�r*s  r0r1z$with_polymorphic.<locals>.<listcomp>�s��J�J�J�2�R�Y�J�J�Jr2)�	innerjoinr8)r�r�r�r�)
rr�r�to_setr6r��union�_with_polymorphic_argsr�r�)�base�classesr�r�r�r;r>r�_existing_alias�primary_mapper�new_classes�mapperss            r0�with_polymorphicrHVs���Z&�d�+�+�N��	1��%��7�7�7�7��+�g�&�&���J�J��!I�J�J�J�
�
���k�!�!�"�"��m�m�K�0�0�G�(�?�?���y�@����G�Z��1�$�1��%�%�4�%�0�0�
����!(�'5�(�"+�m�
���r2c�2�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��_deep_annotate)r:�excludes  r0�
_orm_annotaterM�s���"�7�\�4�,@�'�J�J�Jr2c�.�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.

    )rJr)rF�r��_deep_deannotate�r:s r0�_orm_deannotaterR�s$���$��6����r2c�*�tj|��Sr^rOrQs r0�_orm_full_deannotaterT�s���$�W�-�-�-r2c�Z�eZdZdZejjZ					dd�Zd�Z				d	d�Z	d
d�Z
dS)�_ORMJoinz/Extend Join to support ORM constructs as input.NFc��tj|��}t|d|��}	tj|��}
|
j}|
|_||_||_t|tj	��rt|	j
|��}t|tj��r!|j
���}|j}
n&t|t ��r|}
|
jj}nd}
|
r�t%j||j��r|}n|j}|
�||dd|
jd���\}}}}}}|�5|rt-j|||��}|}nt-j||||��}|}n|}||_t2j�||||||��|
s]t|
dd��rN|
jjrD|
jj}|�8|
jr|
j� |��}|j!|z|_!dSdSdSdSdS)N�_joined_from_infoT)�source_selectable�dest_selectable�source_polymorphic�dest_polymorphic�of_type_mapper�alias_secondaryr�)"rr�r�r�rX�
_left_memo�_right_memor3rr4r�r�QueryableAttribute�
comparator�_source_selectabler1r�parentr��clause_is_present�
_create_joinsr�rr;�_target_adapterr�Joinr��single�_single_table_criterionr�rrr )rG�left�rightr �isouter�fullr_r`�	left_info�
left_orm_info�
right_info�adapt_to�
on_selectable�prop�
adapt_from�pj�sj�source�dest�	secondary�target_adapter�single_crits                      r0r�z_ORMJoin.__init__�sY���&�t�,�,�	���&9�9�E�E�
��'��.�.�
��(��!+���$���&����h�� 1�2�2�	?��}�3�X�>�>�H��h�
� =�>�>�	�$�/�B�B�D�D�M��$�D�D�
��.�
1�
1�	��D� �K�2�M�M��D�� 	2��)�-��9M�N�N�
2�*�
�
�&�1�
��"�"�",� (�#'�!%�)�0� $�
#���
��������~��"��H�Y��r�:�:�E�!�H�H��8�D�)�R��A�A�D�!�H�H���#1�D� ��� � ��t�U�H�g�t�L�L�L��	<��
�H�d�3�3�	<��!�(�	<�%�+�C�K��&��.�L�",�"5�">�">�{�"K�"K�K� $�
�� ;��
�
�
�	<�	<�	<�	<�	<�	<�'�&r2c�H�|}t|tj��r!|j}t|tj���!|j|usJ�t|j|j|j|j|j|j���}t||j|j|j|j	���S)zlSplice a join into the center.

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

        )rmr_r`)rmr`)
r3rrhrkrlrVr rmr_r`)rG�other�leftmostrks    r0�_splice_into_centerz_ORMJoin._splice_into_center1s�������3�8�,�,�	%��}�H���3�8�,�,�	%��z�X�%�%�%�%���I��J��M��L����(�

�
�
�����K��N��M��)�
�
�
�	
r2c�*�t|||||���S)N)rnrm�rV)rGrlr rmrn�join_to_lefts      r0r;z
_ORMJoin.joinNs����e�X�D�'�J�J�J�Jr2c�*�t|||d|���S)NT)rmrnr�)rGrlr rnr�s     r0�	outerjoinz_ORMJoin.outerjoinXs����e�X�t�$�G�G�G�Gr2)NFFNN�NFFN�NFN)rTrUrVrWrrh�__visit_name__r�r�r;r�r+r2r0rVrV�s�������9�9��_�3�N���
���Q<�Q<�Q<�Q<�f
�
�
�@��
��
K�K�K�K�H�H�H�H�H�Hr2rVc�(�t|||||��S)aProduce an inner join between left and right clauses.

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

    :func:`_orm.join` is not commonly needed in modern usage,
    as its functionality is encapsulated within that of the
    :meth:`_query.Query.join` method, which features a
    significant amount of automation beyond :func:`_orm.join`
    by itself.  Explicit usage of :func:`_orm.join`
    with :class:`_query.Query` involves usage of the
    :meth:`_query.Query.select_from` method, as in::

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

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

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

    See :meth:`_query.Query.join` for information on modern usage
    of ORM level joins.

    .. deprecated:: 0.8

        the ``join_to_left`` parameter is deprecated, and will be removed
        in a future release.  The parameter has no effect.

    r�)rkrlr rmrnr�s      r0r;r;\s��T�D�%��7�D�9�9�9r2c�(�t|||d|��S)aProduce a left outer join between left and right clauses.

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

    Tr�)rkrlr rnr�s     r0r�r��s���D�%��4��6�6�6r2c��t|tj��r*t|��}t	|j|��j}n!t|tj��r|j}|�	||���S)a�Create filtering criterion that relates this query's primary entity
    to the given related instance, using established
    :func:`_orm.relationship()`
    configuration.

    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.

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

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

    :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

    )�from_entity)
r3rr4rr�r�r1rra�_with_parent)r�rtr�r�s    r0�with_parentr��sq��6�$��)�*�*���x�(�(���v�}�d�+�+�4���	�D�*�7�	8�	8���}�����X�;��?�?�?r2c�8�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_ras  r0r�r��s��
�%�g�.�.�E���r2c�8�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  r0r�r��s��
�%�g�.�.�E���r2c���|jr3|jr*|���|���urdSdS|jr|jr	||jvS||uS|�|��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)r�rrr��
common_parent��givenr�s  r0�_entity_corresponds_tor��s�����	#��!�	��!�!�#�#�u�'8�'8�':�':�:�:��t��u�	�	�#��!�	#��U�;�;�;��U�?�"�����&�&�&r2c��|jr|jo|jo||up||jvS|js|�|j��S|jo||jvS)adetermine if 'given' corresponds to 'entity', in terms
    of a path of loader options where a mapped attribute is taken to
    be a member of a parent entity.

    e.g.::

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

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

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


    )r�rrr�r�r�r�s  r0�$_entity_corresponds_to_use_path_implr��s���(
��
��#�
P��+�+�
P��&��N�E�V�-N�$N�	
�
�
$�
��"�"�6�=�1�1�1�
�#�
9���8�8�	
r2c��|jr#||jvp|j�|��S|jr	||jvS|�|��S)zedetermine if 'given' "is a" mapper, in terms of the given
    would load rows of type 'mapper'.

    )r�r�r�r�)r�r�s  r0�_entity_isar�sh��

��!���7�7�
�5�<�;K�;K��<
�<
�	
�
�	'�!���7�7�7��y�y�� � � r2c�|�ddlm}m}m}m}ddlm}ddlm}|x|_	x|_	x|_	x|_	|_	dS)aZUse random-ordering sets within the unit of work in order
    to detect unit of work sorting issues.

    This is a utility function that can be used to help reproduce
    inconsistent unit of work sorting issues.   For example,
    if two kinds of objects A and B are being inserted, and
    B has a foreign key reference to A - the A must be inserted first.
    However, if there is no relationship between A and B, the unit of work
    won't know to perform this sorting, and an operation may or may not
    fail, depending on how the ordering works out.   Since Python sets
    and dictionaries have non-deterministic ordering, such an issue may
    occur on some runs and not on others, and in practice it tends to
    have a great dependence on the state of the interpreter.  This leads
    to so-called "heisenbugs" where changing entirely irrelevant aspects
    of the test program still cause the failure behavior to change.

    By calling ``randomize_unitofwork()`` when a script first runs, the
    ordering of a key series of sets within the unit of work implementation
    are randomized, so that the script can be minimized down to the
    fundamental mapping and operation that's failing, while still reproducing
    the issue on at least some runs.

    This utility is also available when running the test suite via the
    ``--reversetop`` flag.

    r)�
unitofwork�sessionr��
dependency)�topological)�	RandomSetN)
�sqlalchemy.ormr�r�r�r��sqlalchemy.utilr��sqlalchemy.testing.utilr�r6)r�r�r�r�r�r�s      r0�randomize_unitofworkr�s���6G�F�F�F�F�F�F�F�F�F�F�F�+�+�+�+�+�+�1�1�1�1�1�1�5>�>�K�O�>���>���>��j�:�>�>�>r2)r�T)NNFF)FFNFFFNr^r�r�);rQr�r�rPrrBrrrrr	r
rrr
rrr�
interfacesrr�
path_registryrrrr9rrrrr�rArXr$r�r�r�r�r��objectr�r��	_inspectsr;rHrMrRrTrhrVr;r�r�r�r�r�r�r�r�r+r2r0�<module>r�s���
�	�	�	���������������"�"�"�"�"�"������������������������� � � � � � �������������������%�%�%�%�%�%�!�!�!�!�!�!�������&�&�&�&�&�&�&�&�&�&�&�&�'�'�'�'�'�'�������������������������������������"�"�"�"�"�"��y�	����?�?�?�?�?�Y�?�?�?�D?D�?D�?D�F=A�F3�F3�F3�F3�Re;�e;�e;�P$5�$5�$5�$5�$5��'�$5�$5�$5�NF'�F'�F'�F'�F'�6�F'�F'�F'�RO<�O<�O<�O<�O<�.�O<�O<�O<�d#��
��\�"�"�#F�#F�G�G�G�!��
��[�!�!�"7�"7�8�8�8�d
�d
�d
�d
�T�	������d�d�d�d�NK�K�K�K����.�.�.�@H�@H�@H�@H�@H�z��@H�@H�@H�HIM�*:�*:�*:�*:�Z7�7�7�7�!@�!@�!@�!@�H
�
�
� ���"'�'�'�( 
� 
� 
�F!�!�!�!>�!>�!>�!>�!>r2