
    +h3             
       ~   d Z ddlmZ ddlmZ ddlmZ ddlZddlZddl	m
Z
 ddl	mZ dd	l	mZ dd
l	mZ ddl	mZ ddl	mZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddl	m!Z! ddl	mZ" ddl	m#Z# ddl	m$Z$ ddl	m%Z% ddl	m&Z& ddl	mZ ddl&mZ' dd l&m(Z( dd!l&m)Z) dd"l&m*Z* dd#l&m+Z+ ddl&mZ, dd$l&m-Z- dd%l.m/Z/ dd&lm0Z0  ejb                         Z2dZ3d' Z4d( Z5d)a6 ejn                  d*      Z8ejr                  ju                         Z;e#jx                  e$jz                   G d+ d,eee'j|                  e                    Z? G d- d.e@      ZAd/ ZBd0 ZC ej                  d1      d2        ZE ej                  d1      d3        ZFd4 ZGd5 ZHd6 ZId7 ZJ G d8 d9eK      ZLy):a5  Logic to map Python classes to and from selectables.

Defines the :class:`~sqlalchemy.orm.mapper.Mapper` class, the central
configurational unit which associates a class with a database table.

This is a semi-private module; the main configurational API of the ORM is
available in :class:`~sqlalchemy.orm.`.

    )absolute_import)deque)chainN   )
attributes)exc)instrumentation)loading)
properties)util)_class_to_mapper)_state_mapper)class_mapper)	state_str)_MappedAttribute)EXT_SKIP)InspectionAttr)MapperProperty)ORMEntityColumnsClauseRole)ORMFromClauseRole)StrategizedProperty)PathRegistry   )event)
inspection)log)schema)sql)base)	coercions)
expression)	operators)roles)visitors)LABEL_STYLE_TABLENAME_PLUS_COL)HasMemoizedc                  X    t         5  t        t              cd d d        S # 1 sw Y   y xY wN)_CONFIGURE_MUTEXset_mapper_registries     H/var/www/html/venv/lib/python3.12/site-packages/sqlalchemy/orm/mapper.py_all_registriesr/   @   s#    	 '%&' ' 's    )c               #   \   K   t               D ]  } | j                         D ]  }|   y wr(   )r/   _mappers_to_configure)regmappers     r.   _unconfigured_mappersr4   E   s5       //1 	FL	s   *,FNO_ATTRIBUTEc                   
   e Zd ZdZdZdZ ej                  d      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dzd       ZdZ		 dZ
ed        Zd	 Zed
        ZdZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ 	 e ejB                  dd      d               Z"ejF                  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/e0jb                  d        Z2e0jb                  d        Z3e0jb                  d        Z4 ejj                  d      d        Z6 ejj                  d      d|d       Z7 ejj                  d      d        Z8d  Z9d! Z:d" Z;d# Z<d$ Z=ed%        Z>d& Z?d' Z@d( ZAd) ZBd* ZCd+ ZDd}d,ZEd- ZFed.        ZGd/ ZHd0 ZIe0jb                  d1        ZJe0jb                  d2        ZKe0jb                  d3        ZLe0jb                  d4        ZMe0jb                  d5        ZNeLZO	 e0jb                  d6        ZPe0jb                  d7        ZQe0jb                  d8        ZRe0jb                  d9        ZSe0jb                  d:        ZTe0jb                  d;        ZUe0jb                  d<        ZVe0jb                  d=        ZWe0j                  d>        ZYejF                  d?        ZZed@        Z[	 d~dAZ\e0jb                  dB        Z]edC        Z^ddDZ_e0jb                  dE        Z`ddFZae0jb                  dG        Zbe0jb                  dH        Zce0jb                   ejj                  d      dI               Zde0jb                   ejj                  d      dJ               ZeedK        Zfe0jb                  dL        Zg ejj                  dM      e0jb                  dN               Zhe0jb                   ejj                  d      dO               ZidP Zje0jb                  dQ        Zke0jb                  dR        ZldS Zme0jb                  dT        ZndU ZodV ZpdW ZqdX ZrdY ZsdZ Zte0jb                  d[        Zud\ Zvd] Zwed^        Zxdd_Zydd`ZzddaZ{db Z|e}j                  fdcZdd Ze0jb                  de        Ze0jb                  df        Ze0jb                  dg        Ze0jb                  dh        Ze0jb                  di        Ze}j                  fdjZdk Zdl Zdm Ze}j                  fdnZdo Zdp Zdq Z ejj                  dr      ds        Ze0jb                  dt        ZdduZe0jb                  dv        Ze0jb                  dw        Zdx ZejF                  dy        Zy)Mappera  Defines an association between a Python class and a database table or
    other relational structure, so that ORM operations against the class may
    proceed.

    The :class:`_orm.Mapper` object is instantiated using mapping methods
    present on the :class:`_orm.registry` object.  For information
    about instantiating new :class:`_orm.Mapper` objects, see
    :ref:`orm_mapping_classes_toplevel`.

    F)1.3a  The :paramref:`.mapper.non_primary` parameter is deprecated, and will be removed in a future release.  The functionality of non primary mappers is now better suited using the :class:`.AliasedClass` construct, which can also be used as the target of a :func:`_orm.relationship` in 1.3.)non_primaryNTc                    t        j                  |t        d      | _        | j                  j                  d| j                  j
                  | _        d| _        t        j                  |      | _	        || _
        |	| _        t        |
t              r|
| _        d| _        n|
| _        |du rd| _        n|	d | _        n|| _        || _        d| _        || _        |*t)        j*                  t,        j.                  |      | _        nd| _        || _        || _        |xs i | _        g | _        || _        || _        || _        |&t)        j*                  t,        j@                  |d      nd| _!        g | _"        t         jF                  | _$        || _%        || _&        || _'        d| _(        d| _)        d| _*        i | _+        || _,        d| _-        || _.        | j&                  r| j"                  sd| _/        n|| _/        | ja                  |       || _1        || _2        |i | _3        n|| _3        |t        jh                  |      | _5        nd| _5        |rt        jh                  |      | _6        nd| _6        tn        5  | jp                  jr                  ju                  ||        | jw                          | jy                          | j{                          | j}                          | j                          | j                  j                  |        | j                  d       | j                          ddd       y# 1 sw Y   yxY w)	aUO  Direct constructor for a new :class:`_orm.Mapper` object.

        The :func:`_orm.mapper` function is normally invoked through the
        use of the :class:`_orm.registry` object through either the
        :ref:`Declarative <orm_declarative_mapping>` or
        :ref:`Imperative <orm_imperative_mapping>` mapping styles.

        .. versionchanged:: 1.4 The :func:`_orm.mapper` function should not
           be called directly for classical mapping; for a classical mapping
           configuration, use the :meth:`_orm.registry.map_imperatively`
           method.   The :func:`_orm.mapper` function may become private in a
           future release.

        Parameters documented below may be passed to either the
        :meth:`_orm.registry.map_imperatively` method, or may be passed in the
        ``__mapper_args__`` declarative class attribute described at
        :ref:`orm_declarative_mapper_options`.

        :param class\_: The class to be mapped.  When using Declarative,
          this argument is automatically passed as the declared class
          itself.

        :param local_table: The :class:`_schema.Table` or other selectable
           to which the class is mapped.  May be ``None`` if
           this mapper inherits from another mapper using single-table
           inheritance.   When using Declarative, this argument is
           automatically passed by the extension, based on what
           is configured via the ``__table__`` argument or via the
           :class:`_schema.Table`
           produced as a result of the ``__tablename__``
           and :class:`_schema.Column` arguments present.

        :param always_refresh: If True, all query operations for this mapped
           class will overwrite all data within object instances that already
           exist within the session, erasing any in-memory changes with
           whatever information was loaded from the database. Usage of this
           flag is highly discouraged; as an alternative, see the method
           :meth:`_query.Query.populate_existing`.

        :param allow_partial_pks: Defaults to True.  Indicates that a
           composite primary key with some NULL values should be considered as
           possibly existing within the database. This affects whether a
           mapper will assign an incoming row to an existing identity, as well
           as if :meth:`.Session.merge` will check the database first for a
           particular primary key value. A "partial primary key" can occur if
           one has mapped to an OUTER JOIN, for example.

        :param batch: Defaults to ``True``, indicating that save operations
           of multiple entities can be batched together for efficiency.
           Setting to False indicates
           that an instance will be fully saved before saving the next
           instance.  This is used in the extremely rare case that a
           :class:`.MapperEvents` listener requires being called
           in between individual row persistence operations.

        :param column_prefix: A string which will be prepended
           to the mapped attribute name when :class:`_schema.Column`
           objects are automatically assigned as attributes to the
           mapped class.  Does not affect :class:`.Column` objects that
           are mapped explicitly in the :paramref:`.mapper.properties`
           dictionary.

           This parameter is typically useful with imperative mappings
           that keep the :class:`.Table` object separate.  Below, assuming
           the ``user_table`` :class:`.Table` object has columns named
           ``user_id``, ``user_name``, and ``password``::

                class User(Base):
                    __table__ = user_table
                    __mapper_args__ = {'column_prefix':'_'}

           The above mapping will assign the ``user_id``, ``user_name``, and
           ``password`` columns to attributes named ``_user_id``,
           ``_user_name``, and ``_password`` on the mapped ``User`` class.

           The :paramref:`.mapper.column_prefix` parameter is uncommon in
           modern use. For dealing with reflected tables, a more flexible
           approach to automating a naming scheme is to intercept the
           :class:`.Column` objects as they are reflected; see the section
           :ref:`mapper_automated_reflection_schemes` for notes on this usage
           pattern.

        :param concrete: If True, indicates this mapper should use concrete
           table inheritance with its parent mapper.

           See the section :ref:`concrete_inheritance` for an example.

        :param confirm_deleted_rows: defaults to True; when a DELETE occurs
          of one more rows based on specific primary keys, a warning is
          emitted when the number of rows matched does not equal the number
          of rows expected.  This parameter may be set to False to handle the
          case where database ON DELETE CASCADE rules may be deleting some of
          those rows automatically.  The warning may be changed to an
          exception in a future release.

          .. versionadded:: 0.9.4 - added
             :paramref:`.mapper.confirm_deleted_rows` as well as conditional
             matched row checking on delete.

        :param eager_defaults: if True, the ORM will immediately fetch the
          value of server-generated default values after an INSERT or UPDATE,
          rather than leaving them as expired to be fetched on next access.
          This can be used for event schemes where the server-generated values
          are needed immediately before the flush completes.   By default,
          this scheme will emit an individual ``SELECT`` statement per row
          inserted or updated, which note can add significant performance
          overhead.  However, if the
          target database supports :term:`RETURNING`, the default values will
          be returned inline with the INSERT or UPDATE statement, which can
          greatly enhance performance for an application that needs frequent
          access to just-generated server defaults.

          .. seealso::

                :ref:`orm_server_defaults`

          .. versionchanged:: 0.9.0 The ``eager_defaults`` option can now
             make use of :term:`RETURNING` for backends which support it.

        :param exclude_properties: A list or set of string column names to
          be excluded from mapping.

          See :ref:`include_exclude_cols` for an example.

        :param include_properties: An inclusive list or set of string column
          names to map.

          See :ref:`include_exclude_cols` for an example.

        :param inherits: A mapped class or the corresponding
          :class:`_orm.Mapper`
          of one indicating a superclass to which this :class:`_orm.Mapper`
          should *inherit* from.   The mapped class here must be a subclass
          of the other mapper's class.   When using Declarative, this argument
          is passed automatically as a result of the natural class
          hierarchy of the declared classes.

          .. seealso::

            :ref:`inheritance_toplevel`

        :param inherit_condition: For joined table inheritance, a SQL
           expression which will
           define how the two tables are joined; defaults to a natural join
           between the two tables.

        :param inherit_foreign_keys: When ``inherit_condition`` is used and
           the columns present are missing a :class:`_schema.ForeignKey`
           configuration, this parameter can be used to specify which columns
           are "foreign".  In most cases can be left as ``None``.

        :param legacy_is_orphan: Boolean, defaults to ``False``.
          When ``True``, specifies that "legacy" orphan consideration
          is to be applied to objects mapped by this mapper, which means
          that a pending (that is, not persistent) object is auto-expunged
          from an owning :class:`.Session` only when it is de-associated
          from *all* parents that specify a ``delete-orphan`` cascade towards
          this mapper.  The new default behavior is that the object is
          auto-expunged when it is de-associated with *any* of its parents
          that specify ``delete-orphan`` cascade.  This behavior is more
          consistent with that of a persistent object, and allows behavior to
          be consistent in more scenarios independently of whether or not an
          orphan object has been flushed yet or not.

          See the change note and example at :ref:`legacy_is_orphan_addition`
          for more detail on this change.

        :param non_primary: Specify that this :class:`_orm.Mapper`
          is in addition
          to the "primary" mapper, that is, the one used for persistence.
          The :class:`_orm.Mapper` created here may be used for ad-hoc
          mapping of the class to an alternate selectable, for loading
          only.

         .. seealso::

            :ref:`relationship_aliased_class` - the new pattern that removes
            the need for the :paramref:`_orm.Mapper.non_primary` flag.

        :param passive_deletes: Indicates DELETE behavior of foreign key
           columns when a joined-table inheritance entity is being deleted.
           Defaults to ``False`` for a base mapper; for an inheriting mapper,
           defaults to ``False`` unless the value is set to ``True``
           on the superclass mapper.

           When ``True``, it is assumed that ON DELETE CASCADE is configured
           on the foreign key relationships that link this mapper's table
           to its superclass table, so that when the unit of work attempts
           to delete the entity, it need only emit a DELETE statement for the
           superclass table, and not this table.

           When ``False``, a DELETE statement is emitted for this mapper's
           table individually.  If the primary key attributes local to this
           table are unloaded, then a SELECT must be emitted in order to
           validate these attributes; note that the primary key columns
           of a joined-table subclass are not part of the "primary key" of
           the object as a whole.

           Note that a value of ``True`` is **always** forced onto the
           subclass mappers; that is, it's not possible for a superclass
           to specify passive_deletes without this taking effect for
           all subclass mappers.

           .. versionadded:: 1.1

           .. seealso::

               :ref:`passive_deletes` - description of similar feature as
               used with :func:`_orm.relationship`

               :paramref:`.mapper.passive_updates` - supporting ON UPDATE
               CASCADE for joined-table inheritance mappers

        :param passive_updates: Indicates UPDATE behavior of foreign key
           columns when a primary key column changes on a joined-table
           inheritance mapping.   Defaults to ``True``.

           When True, it is assumed that ON UPDATE CASCADE is configured on
           the foreign key in the database, and that the database will handle
           propagation of an UPDATE from a source column to dependent columns
           on joined-table rows.

           When False, it is assumed that the database does not enforce
           referential integrity and will not be issuing its own CASCADE
           operation for an update.  The unit of work process will
           emit an UPDATE statement for the dependent columns during a
           primary key change.

           .. seealso::

               :ref:`passive_updates` - description of a similar feature as
               used with :func:`_orm.relationship`

               :paramref:`.mapper.passive_deletes` - supporting ON DELETE
               CASCADE for joined-table inheritance mappers

        :param polymorphic_load: Specifies "polymorphic loading" behavior
          for a subclass in an inheritance hierarchy (joined and single
          table inheritance only).   Valid values are:

            * "'inline'" - specifies this class should be part of the
              "with_polymorphic" mappers, e.g. its columns will be included
              in a SELECT query against the base.

            * "'selectin'" - specifies that when instances of this class
              are loaded, an additional SELECT will be emitted to retrieve
              the columns specific to this subclass.  The SELECT uses
              IN to fetch multiple subclasses at once.

         .. versionadded:: 1.2

         .. seealso::

            :ref:`with_polymorphic_mapper_config`

            :ref:`polymorphic_selectin`

        :param polymorphic_on: Specifies the column, attribute, or
          SQL expression used to determine the target class for an
          incoming row, when inheriting classes are present.

          This value is commonly a :class:`_schema.Column` object that's
          present in the mapped :class:`_schema.Table`::

            class Employee(Base):
                __tablename__ = 'employee'

                id = Column(Integer, primary_key=True)
                discriminator = Column(String(50))

                __mapper_args__ = {
                    "polymorphic_on":discriminator,
                    "polymorphic_identity":"employee"
                }

          It may also be specified
          as a SQL expression, as in this example where we
          use the :func:`.case` construct to provide a conditional
          approach::

            class Employee(Base):
                __tablename__ = 'employee'

                id = Column(Integer, primary_key=True)
                discriminator = Column(String(50))

                __mapper_args__ = {
                    "polymorphic_on":case([
                        (discriminator == "EN", "engineer"),
                        (discriminator == "MA", "manager"),
                    ], else_="employee"),
                    "polymorphic_identity":"employee"
                }

          It may also refer to any attribute
          configured with :func:`.column_property`, or to the
          string name of one::

                class Employee(Base):
                    __tablename__ = 'employee'

                    id = Column(Integer, primary_key=True)
                    discriminator = Column(String(50))
                    employee_type = column_property(
                        case([
                            (discriminator == "EN", "engineer"),
                            (discriminator == "MA", "manager"),
                        ], else_="employee")
                    )

                    __mapper_args__ = {
                        "polymorphic_on":employee_type,
                        "polymorphic_identity":"employee"
                    }

          When setting ``polymorphic_on`` to reference an
          attribute or expression that's not present in the
          locally mapped :class:`_schema.Table`, yet the value
          of the discriminator should be persisted to the database,
          the value of the
          discriminator is not automatically set on new
          instances; this must be handled by the user,
          either through manual means or via event listeners.
          A typical approach to establishing such a listener
          looks like::

                from sqlalchemy import event
                from sqlalchemy.orm import object_mapper

                @event.listens_for(Employee, "init", propagate=True)
                def set_identity(instance, *arg, **kw):
                    mapper = object_mapper(instance)
                    instance.discriminator = mapper.polymorphic_identity

          Where above, we assign the value of ``polymorphic_identity``
          for the mapped class to the ``discriminator`` attribute,
          thus persisting the value to the ``discriminator`` column
          in the database.

          .. warning::

             Currently, **only one discriminator column may be set**, typically
             on the base-most class in the hierarchy. "Cascading" polymorphic
             columns are not yet supported.

          .. seealso::

            :ref:`inheritance_toplevel`

        :param polymorphic_identity: Specifies the value which
          identifies this particular class as returned by the
          column expression referred to by the ``polymorphic_on``
          setting.  As rows are received, the value corresponding
          to the ``polymorphic_on`` column expression is compared
          to this value, indicating which subclass should
          be used for the newly reconstructed object.

        :param properties: A dictionary mapping the string names of object
           attributes to :class:`.MapperProperty` instances, which define the
           persistence behavior of that attribute.  Note that
           :class:`_schema.Column`
           objects present in
           the mapped :class:`_schema.Table` are automatically placed into
           ``ColumnProperty`` instances upon mapping, unless overridden.
           When using Declarative, this argument is passed automatically,
           based on all those :class:`.MapperProperty` instances declared
           in the declared class body.

           .. seealso::

               :ref:`orm_mapping_properties` - in the
               :ref:`orm_mapping_classes_toplevel`

        :param primary_key: A list of :class:`_schema.Column`
           objects which define
           the primary key to be used against this mapper's selectable unit.
           This is normally simply the primary key of the ``local_table``, but
           can be overridden here.

           .. seealso::

                :ref:`mapper_primary_key` - background and example use

        :param version_id_col: A :class:`_schema.Column`
           that will be used to keep a running version id of rows
           in the table.  This is used to detect concurrent updates or
           the presence of stale data in a flush.  The methodology is to
           detect if an UPDATE statement does not match the last known
           version id, a
           :class:`~sqlalchemy.orm.exc.StaleDataError` exception is
           thrown.
           By default, the column must be of :class:`.Integer` type,
           unless ``version_id_generator`` specifies an alternative version
           generator.

           .. seealso::

              :ref:`mapper_version_counter` - discussion of version counting
              and rationale.

        :param version_id_generator: Define how new version ids should
          be generated.  Defaults to ``None``, which indicates that
          a simple integer counting scheme be employed.  To provide a custom
          versioning scheme, provide a callable function of the form::

              def generate_version(version):
                  return next_version

          Alternatively, server-side versioning functions such as triggers,
          or programmatic versioning schemes outside of the version id
          generator may be used, by specifying the value ``False``.
          Please see :ref:`server_side_version_counter` for a discussion
          of important points when using this option.

          .. versionadded:: 0.9.0 ``version_id_generator`` supports
             server-side version number generation.

          .. seealso::

             :ref:`custom_version_counter`

             :ref:`server_side_version_counter`


        :param with_polymorphic: A tuple in the form ``(<classes>,
            <selectable>)`` indicating the default style of "polymorphic"
            loading, that is, which tables are queried at once. <classes> is
            any single or list of mappers and/or classes indicating the
            inherited classes that should be loaded at once. The special value
            ``'*'`` may be used to indicate all descending classes should be
            loaded immediately. The second tuple argument <selectable>
            indicates a selectable that will be used to query for multiple
            classes.

            .. seealso::

              :ref:`with_polymorphic` - discussion of polymorphic querying
              techniques.

        class_.NFc                     | xs ddz   S )Nr   r   r,   )xs    r.   <lambda>z!Mapper.__init__.<locals>.<lambda>c  s    16Q, r-   polymorphic_on)argnameconstructed)Dr   assert_arg_typetyper;   
__module____name__	_sort_keyclass_managerto_list_primary_key_argumentr9   always_refresh
isinstancer   version_id_propversion_id_colversion_id_generatorconcretesingleinheritsr    expectr#   StrictFromClauseRolelocal_tableinherit_conditioninherit_foreign_keys_init_properties_delete_orphansbatcheager_defaultscolumn_prefixColumnArgumentOrKeyRoler@   _dependency_processors
EMPTY_DICT
validatorspassive_updatespassive_deleteslegacy_is_orphan_clause_adapter_requires_row_aliasing_inherits_equated_pairs_memoized_values_compiled_cache_size_reconstructorallow_partial_pksconfirm_deleted_rows_set_with_polymorphicpolymorphic_loadpolymorphic_identitypolymorphic_mapto_setinclude_propertiesexclude_propertiesr)   dispatch_events_new_mapper_instance_configure_inheritance _configure_class_instrumentation_configure_properties_configure_polymorphic_setter_configure_pksregistry_flag_new_mapper_log_expire_memoizations)selfr;   rU   r   primary_keyr9   rR   rV   rW   rK   rN   rO   r@   _polymorphic_maprn   rP   with_polymorphicrm   rj   rZ   r\   rq   rr   ra   rb   rk   r[   rc   rh   s                                r.   __init__zMapper.__init__m   s   B **64BKK""KK  

 "%)\\+%>"&,nn5#1D "&D"0D5((-D%!)(>D%(<D%  "(//**K D  $D!2$8! * 0b!
,* ) --(  	 ')#//.. 0#&+#'+$ "$8!"!2==(-D%(<D%""#34 0
 %9!
 ##%D #3D )&*kk2D&ED#&*D#&*kk2D&ED#&*D#
  		(MM!!66vtD'')113&&(..0!MM**40IIm$%%'		( 		( 		(s   ;B3L77M c                     | S )z<Part of the inspection API.

        Returns self.

        r,   r   s    r.   r3   zMapper.mapper  s	     r-   c                     | fS r(   r,   )r   anon_map
bindparamss      r.   _gen_cache_keyzMapper._gen_cache_key  s	    wr-   c                     | j                   S )zDPart of the inspection API.

        Returns self.class\_.

        r;   r   s    r.   entityzMapper.entity  s     {{r-   r8   zUse .persist_selectablec                     | j                   S r(   )persist_selectabler   s    r.   mapped_tablezMapper.mapped_table  s     &&&r-   c                 ,    t        j                  |       S r(   )r   
per_mapperr   s    r.   _path_registryzMapper._path_registry  s    &&t,,r-   c                    t        j                         | _        | j                  rWt	        | j                  t
              rt        | j                  d      | _        t        | j                  | j                  j                        sNt        j                  d| j                  j                  d| j                  j                  j                  d      | j                  j                  | j                  j                         | j                  | j                  j                  k7  rH| j                   xr dxs d}t        j                  d|d	| j                  j                  d
|d      | j                  ?| j                  j                  | _        | j                  j                   | _        d| _        nU| j                  | j                  j                  ur!| j$                  r;| j                  | _        | j'                         D ]  }|j(                  d|_         n| j,                  :	 t/        j0                  | j                  j                  | j                        | _        t;        j<                  | j                  j                   | j                  | j,                        | _        t        j>                  | j@                        }t/        jB                  | j                   jD                  |      | _#        n| j                  | _        | jH                  l| j                  | _%        | j                  jL                  j(                  tt        jN                  d| d| j                  jL                  j(                  d       n9| j$                  r| j                  | _%        n| j                  jJ                  | _%        | jP                  7| j                  jP                  | _(        | j                  jR                  | _)        n| j                  jP                  p| jP                  | j                  jP                  urNt        jN                  d| jP                  j6                  d| j                  jP                  j6                  d       | j                  jT                  | _*        | j                  jV                  | _+        | j                  j                  jY                  |        | j                  jL                  | _&        | j                  jZ                  | _-        | j                  j\                  xs | j\                  | _.        | j                  j^                  | _/        | jH                  ~| jH                  | jT                  v rMt        jN                  d| jH                  d| jT                  | jH                     d| d| jH                  d	       | | jT                  | jH                  <   | j`                  r!| j$                  rt        j                  d      | j`                  d k(  r| j                  jc                  |        n| j`                  d!k(  rn| j`                  t        j                  d"| j`                  z        te               | _/        | | _&        | j                  | _        | jH                  | | jT                  | jH                  <   | j                  | _%        | j                   t        j                  d#| z        y# t        j2                  $ r}| j                  j                  J | j                  J t        j4                  t        j2                  d| j                  j                  j6                  d| j                  j6                  d      |       Y d}~8d}~wt        j8                  $ r}| j                  j                  J | j                  J t        j4                  t        j8                  d| j                  j                  j6                  d| j                  j6                  d      |       Y d}~d}~ww xY w)$zXConfigure settings related to inheriting and/or inherited mappers
        being present.F)	configurezClass 'z' does not inherit from ''primaryznon-primaryzInheritance of z mapper for class 'z' is only allowed from a z mapperNTz?Can't determine the inherit condition between inherited table 'z' and inheriting table 'z'; tables have no foreign key relationships established.  Please ensure the inheriting table has a foreign key relationship to the inherited table, or provide an 'on clause' using the 'inherit_condition' mapper argument.replace_contextz'; tables have more than one foreign key relationship established.  Please specify the 'on clause' using the 'inherit_condition' mapper argument.)consider_as_foreign_keysMapper zx does not indicate a polymorphic_identity, yet is part of an inheritance hierarchy that has a polymorphic_on column of 'aJ  '.  Objects of this type cannot be loaded polymorphically which can lead to degraded or incorrect loading behavior in some scenarios.  Please establish a polmorphic_identity for this class, or leave it un-mapped.  To omit mapping an intermediary class when using declarative, set the '__abstract__ = True' attribute on that class.zInheriting version_id_col 'z+' does not match inherited version_id_col 'z' and will not automatically populate the inherited versioning column. version_id_col should only be specified on the base-most mapper that includes versioning.z1Reassigning polymorphic association for identity z from z to z: Check for duplicate use of z# as value for polymorphic_identity.zKpolymorphic_load is not currently supported with concrete table inheritanceinlineselectinz)unknown argument for polymorphic_load: %rz9Mapper '%s' does not have a persist_selectable specified.)3r   WeakSequence_inheriting_mappersrR   rL   rD   r   
issubclassr;   sa_excArgumentErrorrF   rs   _updater9   rU   r   rQ   rP   iterate_to_rootr@   re   rV   sql_utiljoin_conditionNoForeignKeysErrorraise_descriptionAmbiguousForeignKeysErrorr   joinrp   rW   criterion_as_pairsonclauserf   rn   _identity_classbase_mapperwarnrN   rO   ro   rZ   appendra   rb   _all_tablesrm   _add_with_polymorphic_subclassr*   )r   npr3   nfeafefkss         r.   rv   zMapper._configure_inheritance  s   
 $(#4#4#6 ==$--. ,T]]e Ldkk4==+?+?@**{{++T]]-A-A-J-JL 
 MM!!$--"8"894==#<#<<)))7iH=** 4;;//5  '#'==#<#< *.--*J*J'"!!)B)BB==.2.>.>D+"&"6"6"8 A!00<<@F9A --5
-5=5L5L $ 9 94;K;K6D2Z /2hh88((../D+ ++d&?&?@C3;3N3N//88144D0
 +/*:*:'((0'+{{$==,,;;GII  !:!:!I!I
K '+{{$'+}}'D'D$""*&*mm&B&B#,0MM,N,N),,8''t}}/K/KK		 ++7744@@
 $(==#@#@D ,,DJMM--44T:#}}88D#'==#@#@D --E1E1E    $}}88D((4,,0D0DDII
 !55 001J1JK  55
 CG$$T%>%>?$$**6  $$0<<TB&&*4&&2**?++,   #uD#D&*&6&6D#((4BF$$T%>%>?#';;D ""*&&K  +c  &88 #'==#<#<#HH#H#'#3#3#??#? KK & 9 9 )-(A(A(M(M(,(8(8(D(D%&!"" 14% (  &?? #'==#<#<#HH#H#'#3#3#??#? KK & @ @ )-(A(A(M(M(,(8(8(D(D
%&!" 14 s&   19\   aB	^""a8B	aac                    |dk(  rd| _         npt        |t        t        f      r<t        |d   t        j
                  t        t        fz         r|| _         n(|d f| _         n|t        j                  d      d | _         | j                   rV| j                   d   G| j                   d   t        j                  t        j                  | j                   d   d      f| _         | j                  r| j                          y y )N*)r   Nr   z$Invalid setting for with_polymorphicr   Tallow_select)r   rL   tuplelistr   string_typesr   r   r    rS   r#   rT   
configuredr~   )r   r   s     r.   rl   zMapper._set_with_polymorphic  s    s"$/D!(5$-8 #T%6%6%%F )9%)94(@%)&&'MNN$(D!  T%:%:1%=%I%%a(  ..))!,!%%D! ??%%' r-   c                     |j                   }| j                  | j                  |f       y | j                  d   dk7  r2| j                  | j                  d   |fz   | j                  d   f       y y )Nr   r   r   )r;   r   rl   )r   r3   subcls      r.   r   z%Mapper._add_with_polymorphic_subclass  sr      (&&x0""1%,&&&&q)UH4d6K6KA6NO -r-   c                 L   | j                   sJ | j                  rJ t        |t              sJ || _        | j                  j                  j                  | j                         | j                  j                  | _        | j                         D ]  }|j                  d|_         | j                  j                  | _	        | j                  D ]  }| j                  j                  |_         | j                  j                  j                  |        | j                  j                  | _        | j                  j                  | _        |j                   j#                         D ]=  \  }}|| j                   vs| j%                  ||dd      r+| j'                  ||d       ? y)zSet the given :class:`_orm.Mapper` as the 'inherits' for this
        :class:`_orm.Mapper`, assuming this :class:`_orm.Mapper` is concrete
        and does not already have an inherits.NTFlocalcolumn)rP   rR   rL   r7   ro   updater   r@   re   rZ   self_and_descendantsr   r   r   ra   r   _propsitems_should_exclude_adapt_inherited_property)r   r3   mpkeyprops        r.   _set_concrete_basezMapper._set_concrete_base  sc   
 }}}==  &&)))%%,,T-A-AB#}}<<**, 	5F$$004-	5 ]]((
++ 	7B!]]66BN	7))006#}}<<==44,,. 	AIC$++%d.B.BSd /C / ..sD%@		Ar-   c                 4    || _         | j                  d       y )NT)r@   ry   )r   r@   s     r.   _set_polymorphic_onzMapper._set_polymorphic_on  s    ,**40r-   c           	         t        j                  | j                        }| j                  r|r|j                  s"t        j                  d| j                  z        || _        |j                  | _        |j                  j                  | _
        |j                  j                  |        y|H|j                  | j                  u sJ |j                  r"t        j                  d| j                  z        | j                  j                  | | j                         t        j                   | j                  | t#        j$                  t&        j(                  |       d      }|j                  s2t#        j*                  d       t,        J t,        j/                  |       || _        |j                  | _        |j                  yt1        j2                  |dt4        d       t#        j6                  | j                        D ]  \  }}|d	k(  r0t9        |d
      r$|j:                  }t9        |d      r|j<                  }t?        |      sGt9        |d      r%|| _         t1        j2                  |dtB        d       xt9        |d      s|jD                  }|jF                  D ]P  }|| jH                  v rt        j                  d|d| d      | jH                  jK                  |||fi      | _$        R  y)a  If this mapper is to be a primary mapper (i.e. the
        non_primary flag is not set), associate this Mapper with the
        given class and entity name.

        Subsequent calls to ``class_mapper()`` for the ``class_`` / ``entity``
        name combination will return this mapper.  Also decorate the
        `__init__` method on the mapped class to include optional
        auto-session attachment logic.

        ztClass %s has no primary mapper configured.  Configure a primary mapper first before setting up a non primary Mapper.Nz1Class '%s' already has a primary mapper defined. T)r3   expired_attribute_loaderfinalizezCalling the mapper() function directly outside of a declarative registry is deprecated. Please use the sqlalchemy.orm.registry.map_imperatively() function for a classical mapping.init)rawr   _sa_original_init__func____sa_reconstructor__load__sa_validators__z+A validation function for mapped attribute z on mapper z already exists.)&r   manager_of_classr;   r9   	is_mappedr   InvalidRequestErrorrH   r{   r3   r   _add_non_primary_mapperr   rs   instrument_classr	   register_classr   partialr
   load_scalar_attributeswarn_deprecated_20_legacy_registry_add_managerr   listen_event_on_inititerate_attributeshasattrr   r   callableri   _event_on_load__sa_validation_opts__r   r`   union)r   managerr   methodvalidation_optsnames         r.   rw   z'Mapper._configure_class_instrumentation  s     --dkk:'"3"300 $, 
 ")D#,,DM#*>>#A#AD 44T:>>T[[000   **Gkk"  	&&tT[[9 "00KK%)\\..&
 	
 ##4 $///))'2$(( >>!Wfn$?224;;? 	KCj WV5H%I116:.#__F6#9:*0D'LL&.dKV%89&,&C&CO & 8 8 	4??2"("<"< $(!/# 
 +///*?*?!FO#<=+		r-   c                 f    d| _         d| _        d| _        | j                  j	                  dd        y )NT_configure_failed)r   _ready_for_configure_dispose_called__dict__popr   s    r.   _set_dispose_flagszMapper._set_dispose_flagsJ  s.    $(!#-t4r-   c                     t        j                   j                         _        i  _        i  _        t        j                  t         j                  D cg c]  }|j                   c}       }t        j                  d |D              }t         j                   j                  gz         } j                  j                  |       |D ]  }|j                  rV|j                  |j                        r;t        j                   |j                        j#                  |       j                  |<   t        j                   |j$                        j#                  |       j
                  |<     j&                  r} j&                  D ]m  }|j(                   j                  vr+t        j*                          j                  |j(                  <    j                  |j(                     j-                  |       o nՉ j                   j                  vs%t/         j                   j                           dk(  r0t1        j2                  d d j                  j4                  d       j6                   j                  vrPt9         j6                  t:        j<                        r,t        j>                  d j6                  j4                  z          j@                  r4 jB                  s( j&                  s j@                  j                   _        n͉ j&                  r3 j&                  D cg c]  } j                  jE                  |       }}n.t        jF                   j                   j                     d      }t/        |      dk(  r0t1        j2                  d d j                  j4                  d      tI        |       _         jK                  d	|       t         fd
 j                  D               _&        y c c}w c c}w )Nc              3   :   K   | ]  }|j                   s|  y wr(   )r   ).0cs     r.   	<genexpr>z(Mapper._configure_pks.<locals>.<genexpr>[  s     !G!!Gs   r   r   z> could not assemble any primary key columns for mapped table 'r   zlCould not assemble any primary keys for locally mapped table '%s' - no rows will be persisted in this Table.T)ignore_nonexistent_tablesz"Identified primary key columns: %sc              3      K   | ]R  }j                   |   j                  vr5t        |d       r|j                  j                  vrj                   |    T yw)tableN)_columntoproperty_identity_key_propsr   r   _cols_by_tabler   colr   s     r.   r   z(Mapper._configure_pks.<locals>.<genexpr>  sY      #
%%c*$2J2JJC)99D$7$77 ""3'#
s   AA)'r   find_tablesr   tables_pks_by_tabler  r   
column_setr   r  	proxy_setr*   r   r   r   
issupersetordered_column_setintersectionr   rJ   r   
OrderedSetaddlenr   r   r   rU   rL   r   Tabler   rR   rP   corresponding_columnreduce_columnsr   r}   _readonly_props)	r   r  all_colspk_colsr  tkr   r   s	   `        r.   rz   zMapper._configure_pksQ  sb   **4+B+BC ??T-C-CDcCMMDE
 //!GX!GG T[[D$;$;#<<=' 		A}}!3!3AMM!B )-(?(?MM),w' ""1% &*%<%<QSS%A%N%N&D"		 %%// 377$"4"4426//2CD&&qww/""177+//23 ##4+=+==4%%d&=&=>?1D&& 00<<> 
 T%7%77Jfll=
 II; ""../ MMMM..  $}}88D )) "77 ++@@C  '55&&t'>'>?.2
 ;1$** T44@@B   %[1DII:KH  # #
--#
  
i Ets   O>'"Pc                    t        j                         x| _        | _        t	        j
                         | _        t        |       | _        | j                  r5| j                  j                         D ]  \  }}| j                  ||d        | j                  rd| j                  j                  j                         D ]=  \  }}|| j                  vs| j                  ||dd       r+| j                  ||d       ? | j                  j                  D ]  }|| j                  v r| j                   xs d|j"                  z   }| j                  |j"                  || j$                  j                  j'                  |      |      rr| j)                         D ]*  }||j                  v s|j                  |   j"                  }, | j                  ||dd        y )NFr    Tr   	setparent)sql_baseColumnCollectioncolumnsr   r   OrderedDictr   _ColumnMappingr  rX   r   _configure_propertyrR   r   r   r   r\   r   rU   contains_columnr   )r   r   r   r   
column_keyr3   s         r.   rx   zMapper._configure_properties  s    !) 9 9 ;;tv &&( "0!5   !2288: ;	T((dE:; ==!]]11779 E	Tdkk)$2F2FE$ 3G 3 223eD	E --55 	F///,,2fjj@J##

&&((88@	 $   ..0 FV555!'!9!9&!A!E!EJF $$F$ % )	r-   c                    d}| j                   Cd}t        | j                   t        j                        r	 | j                  | j                      | _         | j                   | j                  v r| j                  | j                      }nt        | j                   t              rGt        | j                   t        j                        st        j                  d      | j                   }nI| j                  j                  | j                         }|wd}d}| j                   }t        |t        j                         rO| j"                  | j"                  d   j                  |      	 $t        j$                  d|j&                  z        d}t)        |d	d      }|rJ| j+                  |j,                  |j,                  d|      rFt        j$                  d
|j,                  z        |j/                  d      x| _         }|j,                  }t        j                  ||      }| j1                  |||d       |j2                  d   | _         |j,                  n| j5                         D ]  }|j                   | j                  |j                  u r|j                   | _         n*| j                  j                  |j                         | _         | j                   $|j6                  | _        |j8                  | _         yd| _         y |rfd}	fd}
|	| _        |
| _        yd| _        y# t
        $ rB}t        j                  t        j                  d| j                   z        |       Y d}~d}~ww xY w)a  Configure an attribute on the mapper representing the
        'polymorphic_on' column, if applicable, and not
        already generated by _configure_properties (which is typical).

        Also create a setter function which will assign this
        attribute to the value of the 'polymorphic_identity'
        upon instance construction, also if applicable.  This
        routine will run when an instance is created.

        FNTzPCan't determine polymorphic_on value '%s' - no attribute is mapped to this name.r   zUOnly direct column-mapped property or SQL expression can be passed for polymorphic_onr   zkCould not map polymorphic_on column '%s' to the mapped table - polymorphic loads will not function properlyr   z6Cannot exclude or override the discriminator column %r_sa_polymorphic_on)_instrumentr  r   c                     | j                   }| j                        j                  | || j                  j                  j
                  d        y r(   )dictget_implr*   r   r3   rn   )statedict_polymorphic_keys     r.   _set_polymorphic_identityzGMapper._configure_polymorphic_setter.<locals>._set_polymorphic_identityv  s?    

/33MM((==	r-   c                 |    |v r7|   | j                   vr%t        j                  dt        |      |   f       y y y )NznFlushing object %s with incompatible polymorphic identity %r; the object may not refresh and/or load correctly)"_acceptable_polymorphic_identitiesr   warn_limitedr   )r3   r+  r,  r-  s      r.   _validate_polymorphic_identityzLMapper._configure_polymorphic_setter.<locals>._validate_polymorphic_identity  sW    #u,o.!DDE %%G #5)5+AB	E -r-   )r@   rL   r   r   r   KeyErrorr   r   r   r  r   r   ColumnPropertyr   r  r   Columnr   r   r   getattrr   r   labelr"  r  r   r.  r2  )r   r   settererrr   r  
instrumentr   r3   r.  r2  r-  s              @r.   ry   z$Mapper._configure_polymorphic_setter  sZ    *F$--t/@/@A
*.++d6I6I*JD' ""d&<&<< --d.A.ABD//@ "'')B)B !..; 
 ** --BB'' ; #F!&J--C!#v}}5--5003HHM  %88? "oo.  "&Jc5$/++CGGSWWeSI$8868;@ 
 14		:N0OOD'#''C!00*M((d(N #',,q/D"hhO
 ..0  ((4..&2K2KK.4.C.C+ !33..v/D/DE + **6"<< 6 #AA ;
  :>636  .GD*. / .2D*i   KK,,3595H5HI
 ), s   L% %	M0.7M++M0c                 N    | j                   | j                  | j                      S y r(   )rN   r  r   s    r.   _version_id_propzMapper._version_id_prop  s(    *))$*=*=>>r-   c                     t               }t        | g      }|ra|j                         }|j                  | j                  u r6|j	                  |j
                         |j                  |j                         |ra|S r(   )r*   r   popleftr   r  rn   extendr   )r   
identitiesstackitems       r.   r0  z)Mapper._acceptable_polymorphic_identities  sg    U
tf==?D&&$*A*AAt889T556	  r-   c                 H    t        | j                  j                               S r(   )	frozensetr   valuesr   s    r.   	_prop_setzMapper._prop_set  s    ++-..r-   zsqlalchemy.orm.descriptor_propsc                    t         j                  j                  }| j                  s| j	                  ||dd       y || j
                  vrx| j                  j                  ||      }||u s2t        |t        j                        r=|j                  |j                  u r$| j	                  ||j                         |d       y y y y )NFr  T)r   	preloadedorm_descriptor_propsrP   r"  r   rH   _get_class_attr_mrorL   r   InstrumentedAttribute_parententityparentConcreteInheritedProperty)r   r   r   r   descriptor_propsimplementing_attributes         r.   r   z Mapper._adapt_inherited_property  s    >>>>}}$$S$Ue$L# &*%7%7%K%KT&" &-*J,L,L +88DKKG(($>>@"	 )  H $r-   c           
      &	   t         j                  j                  }| j                  d||j                  j
                         t        |t              s| j                  ||      }t        |t        j                        rT| j                  j                  |j                  d         }|| j                  r| g}| j                  j                         D ]  }|j                   j                  |j                  d         }|L|D ]  }	|	j                  j#                  |        | j                  j                  |j                  d         } n|j%                  |        |[|j                  d   }t'        | d      rt'        |d      r|j(                  | j*                  vr| j,                  j/                  |       ngt'        | d      r[|j(                  | j*                  v rC|| j*                  |j(                     vr(| j*                  |j(                     j/                  |       t'        |d      s0|| j0                  u xs |j                  d   | j0                  u |_        t        |t4        j6                        r|x|_        |_        | j                  j/                  ||       |j                  D ]"  }|j<                  D ]  }|| j>                  |<    $ ||_        |r|jA                  | |       || jB                  v rTtE        | jB                  |   dd      r:| jB                  |   jF                  }
tI        jJ                  d	|
d
|d|d|
      || jB                  v rt        |t        j                        st        | jB                  |   t        j                  |jL                  f      sWt        jN                  d| jB                  |   d| d|d       | jB                  |   }| jP                  jS                  |d        || jB                  |<   | jT                  s|jW                  |        | jX                  D ]  }|j[                  |||        |r!|j]                          |j_                  |        | j`                  r| jc                          y y )Nz_configure_property(%s, %s)r   r  r   r  _is_polymorphic_discriminator_mapped_by_synonymFz'Can't call map_column=True for synonym =z4, a ColumnProperty already exists keyed to the name z for column z	Property z on z" being replaced with new property z$; the old property will be discarded)2r   rH  rI  r}   	__class__rF   rL   r   _property_from_columnr   r4  r   r  r  rR   r   rU   _refresh_for_new_columnr   r   r   r  r  r  r@   rR  r!   Labelr   _tq_key_labelr
  r  
set_parentr   r6  rS  r   r   rN  r   r   r   r9   r   r   r   r   post_instrument_classr   r~   )r   r   r   r   r  rO  r  pathmm2synoldpropr3   s                r.   r"  zMapper._configure_property  s   >>>>		/dnn6M6MN$/--c48DdJ556))>>t||AOC
 {t}}v668 	#A--<<T\\!_MC"& OB11II#NO"55JJ LLO KKN	# {ll1o 4!23W-yy(;(;;((,,T2 D"23		T%8%884#6#6syy#AA''		266s;
 4!@A4... >||A$*=*== 2
 #z//0 /21#+LLS#&|| 7== 7C26D**3/77 OOD$'$++'KK2E#
 ++c"55C&& '*3S:  4;;tZ%>%>?C --$>> II ;;s#T41
 kk#&G##GT2C!!$'.. 	>F,,S$=	> IIK&&t,??%%' r-   c                    t         j                  j                  }t        j                  |      }|d   }t	        |t
        j                        sJ | j                  j                  |d      }t	        |t        j                        r| j                  r|j                  d   |f| j                  vr|j                  d   j                  |      s}|j                  d   | j                  urb|| j                  urT|j                  | u}d|j                  d   d|d|d}|rt        j                   |       nt#        j$                  |      |j'                         }|j                  j)                  d|       | j+                  d|z         |S |t	        ||j,                        rg }|D ]  }	| j.                  j1                  |	      }
|
t| j2                  j1                  |	      }
|
| j.                  j5                  |
       | j.                  j1                  |	      }
|
t#        j6                  d	|d
| d|	d      |j9                  |
        t        j                  | S t#        j6                  d|d
| d|j:                  d|d	      )zZgenerate/update a :class:`.ColumnProperty` given a
        :class:`_schema.Column` object.r   NzImplicitly combining column z with column z under attribute 'zT'.  Please configure one or more attributes for these same-named columns explicitly.zAinserting column to existing list in properties.ColumnProperty %szWhen configuring property 'z' on z
, column 'z' is not represented in the mapper's table. Use the `column_property()` function to force this column to be mapped as a read-only attribute.z$WARNING: when configuring property 'z' conflicts with property 'aG  '. To resolve this, map the column to the class under a different name in the 'properties' dictionary.  Or, to remove all awareness of the column entirely (including its availability as a foreign key), use the 'include_properties' or 'exclude_properties' mapper arguments to control specifically which table columns get mapped.)r   rH  rI  rI   rL   r!   ColumnElementr   getr   r4  rf   r  shares_lineagerN   rM  r   r   r   copyinsertr}   rN  r   r  rU   rW  r   r   r   )r   r   r   rO  r  r   	warn_onlymsgmapped_columnr   mcs              r.   rV  zMapper._property_from_column@  sZ     >>>> ,,t$&*":":;;;{{sD)dJ556 44Q0778 Q66v>LLO4+>+>>$"5"55 KKt3	
 &*\\"%5vsD  IIcN 44S99 99;DLL6*II258: K\Z"<<
 M ),,AA!D:))>>qAB~
 //GGK00EEaHBz$22
 -0q	:  $$R(')( ,,m<<&& *-dFJJF
 
r-   c                 b    | j                   j                  rt        | j                   hd       y y )NTcascade)r{   _new_mappers_configure_registriesr   s    r.   _check_configurezMapper._check_configure  s$    ==%%!4==/4@ &r-   c                    | j                  d       | j                  j                         D cg c]	  \  }}||f }}}|D ]_  \  }}| j                  d|       |j                  | u r|j                  s|j                          |j                  sO|j                  |        a | j                  d       d| _        yc c}}w )zCall the ``init()`` method on all ``MapperProperties``
        attached to this mapper.

        This is a deferred configuration step which is intended
        to execute once all mappers have been constructed.

        z$_post_configure_properties() startedzinitialize prop %sz%_post_configure_properties() completeTN)	r}   r   r   rM  _configure_startedr   _configure_finishedr[  r   )r   r   r   ls       r.   _post_configure_propertiesz!Mapper._post_configure_properties  s     			89*.++*;*;*=>YS$c4[>> 	1ICII*C0{{d"4+B+B		''**40	1 			9: ?s   B=c                 X    |j                         D ]  \  }}| j                  ||        y)z^Add the given dictionary of properties to this mapper,
        using `add_property`.

        N)r   add_property)r   dict_of_propertiesr   values       r.   add_propertieszMapper.add_properties  s0    
 -224 	*JCc5)	*r-   c                 ^    || j                   |<   | j                  ||| j                         y)aA  Add an individual MapperProperty to this mapper.

        If the mapper has not been configured yet, just adds the
        property to the initial properties dictionary sent to the
        constructor.  If this Mapper has already been configured, then
        the given MapperProperty is configured immediately.

        )r   N)rX   r"  r   )r   r   r   s      r.   rx  zMapper.add_property  s-     &*c"  d Ar-   c                 N    | j                         D ]  }|j                           y r(   )r   _reset_memoizationsr   r3   s     r.   r~   zMapper._expire_memoizations  s&    **, 	)F&&(	)r-   c                     d| j                   j                  z   dz   | j                  d uxr | j                  j                  xs t	        | j                        z   | j
                  xr dxs dz   dz   S )N(|z|non-primaryr  ))r;   rF   rU   r   strr9   r   s    r.   	_log_desczMapper._log_desc  s     kk""#   , 1$$00)t''( 2N8b: 		
r-   c                 `     | j                   j                  d|z   g| j                  f|z     y Nz%s )loggerinfor  r   ri  argss      r.   r}   zMapper._log  s+    B(9D(@Br-   c                 `     | j                   j                  d|z   g| j                  f|z     y r  )r  debugr  r  s      r.   
_log_debugzMapper._log_debug  s+    %#+C$..):T)ACr-   c                 J    dt        |       | j                  j                  fz  S )Nz<Mapper at 0x%x; %s>)idr;   rF   r   s    r.   __repr__zMapper.__repr__  s     %D4;;3G3G(HHHr-   c                     d| j                   j                  | j                  xr dxs dd| j                  | j                  j                  S | j
                  j                  S )Nzmapped class z (non-primary)r  z->)r;   rF   r9   rU   r   r   r   s    r.   __str__zMapper.__str__  sr    KK  1!17R7+ (( 5
 	

 ((445
 	
r-   c                 "   d}| j                         D ]l  }|j                  D ][  \  }}d}t        j                  |      j	                  |||j
                        }| j                  r|r  y| j                  rW|rZ  y n | j                  r|S y)NFT)
optimistic)r   rY   r   r   
has_parenthas_identityrc   )r   r+  orphan_possibler3   r   clsr  s          r.   
_is_orphanzMapper._is_orphan  s    **, 	 F$44 
 
c"&'88=HH35+=+= I 
 ((Z ..z
 	    ""r-   c                     || j                   v S r(   )r   )r   r   s     r.   has_propertyzMapper.has_property  s    dkk!!r-   c           
          |r| j                          	 | j                  |   S # t        $ r;}t        j                  t        j                  d| d|d      |       Y d}~yd}~ww xY w)z6return a MapperProperty associated with the given key.zMapper 'z' has no property 'r   r   N)rq  r   r3  r   r   r   r   )r   r   _configure_mappersr9  s       r.   get_propertyzMapper.get_property  sc     !!#	;;s## 	KK**:>D !$	 	s   # 	A'1A""A'c                      | j                   |   S )zkGiven a :class:`_schema.Column` object, return the
        :class:`.MapperProperty` which maps this column.)r  )r   r   s     r.   get_property_by_columnzMapper.get_property_by_column  s     %%f--r-   c                 h    | j                          t        | j                  j                               S )z1return an iterator of all MapperProperty objects.)rq  iterr   rE  r   s    r.   iterate_propertieszMapper.iterate_properties  s(     	DKK&&())r-   c                 0   |dk(  rt        | j                        }n|rt               }t        j                  |      D ]k  }t        |      }|j                  |       st        j                  |d|       | |j                  |j                                [|j                  |       m | j                  D cg c]	  }||v s| }}ng }|>t        t        j                  |d            }|D cg c]  }|j                  |v s| }}|S c c}w c c}w )zgiven a with_polymorphic() argument, return the set of mappers it
        represents.

        Trims the list of mappers to just those represented within the given
        selectable, if present. This helps some more legacy-ish mappings.

        r   z does not inherit from T)include_aliases)r   r   r*   r   rI   r   isar   r   r   r   r  r   r  rU   )r   spec
selectablemappersr]  r  s         r.   _mappers_from_speczMapper._mappers_from_spec  s    3;4445GeG\\$' 
#$Q'uuT{ 449:DA  %NN1#4#4#67KKN
# #'";";LQqG|qLGLG!$$ZFF #*EQQ]]f-DqEGE M Fs   9	DD2DDc                 0   | j                   }|D ]  }|| u r|j                  rt        j                  d      |j                  r6|r'|j                  |j                  |j                        }_|j                  |j                  |j                        } |S )zgiven a list of mappers (assumed to be within this mapper's
        inheritance hierarchy), construct an outerjoin amongst those mapper's
        mapped tables.

        z^'with_polymorphic()' requires 'selectable' argument when concrete-inheriting mappers are used.)	r   rP   r   r   rQ   r   rU   rV   	outerjoin)r   r  	innerjoinfrom_objr]  s        r.   _selectable_from_mapperszMapper._selectable_from_mappers=  s     ** 	ADyzz00A  XX'}}q':': H  (11q':': H	$ r-   c                     | j                   rV| j                  rJ| j                  >| j                  j                  | | d      j	                  d | j
                  D              S y )N)parententityparentmapperc              3   4   K   | ]  }|j                     y wr(   )rn   )r   r]  s     r.   r   z1Mapper._single_table_criterion.<locals>.<genexpr>]  s     LQ!((Ls   )rQ   rR   r@   	_annotatein_r   r   s    r.   _single_table_criterionzMapper._single_table_criterionX  sW    ;;4==T-@-@-L&&00!%t<cL$2K2KLLM r-   c                     | j                   xs< | j                  xs. | j                  j                   xs | j                  j                  S )a;  determine if _MapperEntity or _ORMColumnEntity will need to use
        polymorphic adaption when setting up a SELECT as well as fetching
        rows for mapped classes and subclasses against this Mapper.

        moved here from context.py for #8456 to generalize the ruleset
        for this condition.

        )r   re   r   r   s    r.    _should_select_with_poly_adapterz'Mapper._should_select_with_poly_adaptera  sJ    : !! 7**7007 66		
r-   c                 p    | j                          | j                  sg S  | j                  | j                   S r(   )rq  r   r  r   s    r.   _with_polymorphic_mappersz Mapper._with_polymorphic_mappers  s5    $$I&t&&(=(=>>r-   c                 $    | j                          y)zThis hook is invoked by attribute inspection.

        E.g. when Query calls:

            coercions.expect(roles.ColumnsClauseRole, ent, keep_inspect=True)

        This allows the inspection process run a configure mappers hook.

        N)rq  r   s    r.   _post_inspectzMapper._post_inspect  s     	r-   c                     | j                   s| j                  S | j                   \  }}||S | j                  | j                  ||      d      S NF)r   r   r  r  )r   r  r  s      r.   _with_polymorphic_selectablez#Mapper._with_polymorphic_selectable  sX    $$***00j!00''j95 r-   c                 V    t        d | j                  j                         D              S )Nc              3   J   K   | ]  \  }}|t        d  |D              f  yw)c              3   N   K   | ]  }|j                   j                  s|  y wr(   )rD   should_evaluate_noner   r  s     r.   r   z@Mapper._insert_cols_evaluating_none.<locals>.<genexpr>.<genexpr>  s!      chh.K.KCs   %%NrD  r   r   r  s      r.   r   z6Mapper._insert_cols_evaluating_none.<locals>.<genexpr>  s8      
 w  #* 
   !#r)  r  r   r   s    r.   _insert_cols_evaluating_nonez#Mapper._insert_cols_evaluating_none  s-     
 #'"5"5";";"=
 
 	
r-   c                 V    t        d | j                  j                         D              S )Nc              3   J   K   | ]  \  }}|t        d  |D              f  yw)c              3      K   | ]J  }|j                   s<|j                  s0|j                  s$|j                  j                  s|j
                   L y wr(   )r   server_defaultdefaultrD   r  r   r  s     r.   r   z8Mapper._insert_cols_as_none.<locals>.<genexpr>.<genexpr>  s@      ??..KKHH99 GGs   AANr  r  s      r.   r   z.Mapper._insert_cols_as_none.<locals>.<genexpr>  s8      
 w  & 

r  r  r   s    r.   _insert_cols_as_nonezMapper._insert_cols_as_none  s-     
 #'"5"5";";"=
 
 	
r-   c                 \     t         fd j                  j                         D              S )Nc              3   P   K   | ]  \  }}|t        fd |D              f  yw)c              3   T   K   | ]  }j                   |   j                  |f ! y wr(   )r  r   r  s     r.   r   z3Mapper._propkey_to_col.<locals>.<genexpr>.<genexpr>  s,      ?BT++C044c:s   %(N)r)  )r   r   r  r   s      r.   r   z)Mapper._propkey_to_col.<locals>.<genexpr>  s9      
 w  FM 
s   #&r  r   s   `r.   _propkey_to_colzMapper._propkey_to_col  s.     
 #'"5"5";";"=
 
 	
r-   c                 V    t        d | j                  j                         D              S )Nc              3   v   K   | ],  \  }}|t        |D cg c]  }|j                   c}      f . y c c}w wr(   )rD  r   )r   r   pksr  s       r.   r   z+Mapper._pk_keys_by_table.<locals>.<genexpr>  s8      
s I#63sww678
6s   949r)  r  r   r   s    r.   _pk_keys_by_tablezMapper._pk_keys_by_table  s+     
"00668
 
 	
r-   c                 \     t         fd j                  j                         D              S )Nc           	   3      K   | ]9  \  }}|t        |D cg c]  }j                  |   j                   c}      f ; y c c}w wr(   )rD  r  r   )r   r   r  r  r   s       r.   r   z0Mapper._pk_attr_keys_by_table.<locals>.<genexpr>  sN      

 s cJs411#6::JK
 Ks   A AAr  r   s   `r.   _pk_attr_keys_by_tablezMapper._pk_attr_keys_by_table  s.     

 #00668
 
 	
r-   c                 V    t        d | j                  j                         D              S )Nc              3      K   | ]8  \  }}|t        |D cg c]  }|j                  |j                   c}      f : y c c}w wr(   )rD  r  r   r   r   r  r  s       r.   r   z.Mapper._server_default_cols.<locals>.<genexpr>  sX      
 w  $+--9 	
   AA Ar  r   s    r.   _server_default_colszMapper._server_default_cols  -     
 #'"5"5";";"=
 
 	
r-   c                    t               }| j                  j                         D ]\  \  }}|D ]R  }|j                  |j                  || j
                  v s+|j                  | j
                  |   j                         T ^ |S r(   )r*   r  r   r  server_onupdater  r  r   )r   resultr   r  r  s        r.   &_server_default_plus_onupdate_propkeysz-Mapper._server_default_plus_onupdate_propkeys  s    "11779 	@NE7 @&&2**6T333JJt55c:>>?@	@ r-   c                 V    t        d | j                  j                         D              S )Nc              3      K   | ]8  \  }}|t        |D cg c]  }|j                  |j                   c}      f : y c c}w wr(   )rD  r  r   r  s       r.   r   z7Mapper._server_onupdate_default_cols.<locals>.<genexpr>	  sX      
 w  $+..: 	
r  r  r   s    r.   _server_onupdate_default_colsz$Mapper._server_onupdate_default_cols	  r  r-   c                     | | | d}| j                   | j                  ur4| j                  j                  | | | d      j                  d| d      |d<   | j                  j                  |      j                  d| d      S )N)entity_namespacer  r  ormcompile_state_pluginplugin_subject	dml_table)r   rU   r  _set_propagate_attrsr  )r   annotationss     r.   __clause_element__zMapper.__clause_element__	  s     !%  

 ""$*:*:: (,'7'7'A'A(,$($(( #").$G $ ((5JJ%*dC
 	
r-   c                 v    t        j                         j                  | | | dd      j                  d| d      S )NT)r  r  r  identity_tokenr  r  )r!   nullr  r  r   s    r.   select_identity_tokenzMapper.select_identity_token-	  sC     OOY(,$($(&*	 "!).$G	
r-   c                     | j                   S )a4  The :class:`_schema.FromClause` construct this
        :class:`_orm.Mapper` selects from by default.

        Normally, this is equivalent to :attr:`.persist_selectable`, unless
        the ``with_polymorphic`` feature is in use, in which case the
        full "polymorphic" selectable is returned.

        )r  r   s    r.   r  zMapper.selectable>	  s     000r-   c                    |dvr&t        j                  t        j                  |d      }| j                  r%|s| j                  d   }|du r| j                  d   }n|du rd }| j                  ||      }|||fS || j                  ||      fS )Nr  Tr   r   Fr   )r    rS   r#   rT   r   r  r  )r   r  r  r  r  s        r.   _with_polymorphic_argszMapper._with_polymorphic_argsJ	  s     ]*"))**JTJ   ,,Q/U"!2215
5 J))$
;!J&&D99'9MMMr-   c                 J    t        | j                  | j                              S r(   )r   _iterate_polymorphic_propertiesr  r   s    r.   _polymorphic_propertieszMapper._polymorphic_properties_	  s&    00..
 	
r-   c                     | j                   }| j                  }|D cg c]U  }t        |t        j                        r9|j
                  r-|r|j                  |j                  d      n|j                  d   W c}S c c}w Nr   )r  _polymorphic_adapterrL   r   r4  _renders_in_subqueriesr  )r   poly_propertiesadapterr   s       r.   _all_column_expressionszMapper._all_column_expressionsg	  ss    66++ (
$
 9 9:++ 18GOODLLO,T\\!_L
 	
 
s   AA:c                     |r| j                  |      }n| j                  }|D cg c]7  }t        |t        j                        r|j
                  |j                  d   f9 c}S c c}w r  )r  r  rL   r   r4  r   r  )r   polymorphic_mappersr  r   s       r.   _columns_plus_keyszMapper._columns_plus_keyss	  sh    "BB#O #::O (
$
 9 9: XXt||A'
 	
 
s   <A$c                 r    | j                   r+t        j                  | j                  | j                        S y )N)equivalents)r   r   ColumnAdapterr  _equivalent_columnsr   s    r.   r   zMapper._polymorphic_adapter	  s2      ))T-E-E  r-   c           
   #   ^  K   || j                   }|s| j                  D ]  }|  yt        j                  t	        | g|z   D cg c]  }t        |j                         c}       D ];  }t        |dd      r(| j                  |j                  d   | j                  ur8| = yc c}w w)zUReturn an iterator of MapperProperty objects which will render into
        a SELECT.NrR  Fr   )	r  r  r   unique_listr   r   r6  r@   r  )r   r  r   r3   s       r.   r  z&Mapper._iterate_polymorphic_properties	  s      ?44G,,  %% (,fw&6" V667  1=uE''/yy|4+>+>>s   AB-B(!AB-c                 `    | j                          t        j                  | j                        S )ai  A namespace of all :class:`.MapperProperty` objects
        associated this mapper.

        This is an object that provides each property based on
        its key name.  For instance, the mapper for a
        ``User`` class which has ``User.name`` attribute would
        provide ``mapper.attrs.name``, which would be the
        :class:`.ColumnProperty` representing the ``name``
        column.   The namespace object can also be iterated,
        which would yield each :class:`.MapperProperty`.

        :class:`_orm.Mapper` has several pre-filtered views
        of this attribute which limit the types of properties
        returned, including :attr:`.synonyms`, :attr:`.column_attrs`,
        :attr:`.relationships`, and :attr:`.composites`.

        .. warning::

            The :attr:`_orm.Mapper.attrs` accessor namespace is an
            instance of :class:`.OrderedProperties`.  This is
            a dictionary-like object which includes a small number of
            named methods such as :meth:`.OrderedProperties.items`
            and :meth:`.OrderedProperties.values`.  When
            accessing attributes dynamically, favor using the dict-access
            scheme, e.g. ``mapper.attrs[somename]`` over
            ``getattr(mapper.attrs, somename)`` to avoid name collisions.

        .. seealso::

            :attr:`_orm.Mapper.all_orm_descriptors`

        )rq  r   ImmutablePropertiesr   r   s    r.   attrszMapper.attrs	  s&    F 	''44r-   c                 n    t        j                  t        | j                  j	                                     S )ay  A namespace of all :class:`.InspectionAttr` attributes associated
        with the mapped class.

        These attributes are in all cases Python :term:`descriptors`
        associated with the mapped class or its superclasses.

        This namespace includes attributes that are mapped to the class
        as well as attributes declared by extension modules.
        It includes any Python descriptor type that inherits from
        :class:`.InspectionAttr`.  This includes
        :class:`.QueryableAttribute`, as well as extension types such as
        :class:`.hybrid_property`, :class:`.hybrid_method` and
        :class:`.AssociationProxy`.

        To distinguish between mapped attributes and extension attributes,
        the attribute :attr:`.InspectionAttr.extension_type` will refer
        to a constant that distinguishes between different extension types.

        The sorting of the attributes is based on the following rules:

        1. Iterate through the class and its superclasses in order from
           subclass to superclass (i.e. iterate through ``cls.__mro__``)

        2. For each class, yield the attributes in the order in which they
           appear in ``__dict__``, with the exception of those in step
           3 below.  In Python 3.6 and above this ordering will be the
           same as that of the class' construction, with the exception
           of attributes that were added after the fact by the application
           or the mapper.

        3. If a certain attribute key is also in the superclass ``__dict__``,
           then it's included in the iteration for that class, and not the
           class in which it first appeared.

        The above process produces an ordering that is deterministic in terms
        of the order in which attributes were assigned to the class.

        .. versionchanged:: 1.3.19 ensured deterministic ordering for
           :meth:`_orm.Mapper.all_orm_descriptors`.

        When dealing with a :class:`.QueryableAttribute`, the
        :attr:`.QueryableAttribute.property` attribute refers to the
        :class:`.MapperProperty` property, which is what you get when
        referring to the collection of mapped properties via
        :attr:`_orm.Mapper.attrs`.

        .. warning::

            The :attr:`_orm.Mapper.all_orm_descriptors`
            accessor namespace is an
            instance of :class:`.OrderedProperties`.  This is
            a dictionary-like object which includes a small number of
            named methods such as :meth:`.OrderedProperties.items`
            and :meth:`.OrderedProperties.values`.  When
            accessing attributes dynamically, favor using the dict-access
            scheme, e.g. ``mapper.all_orm_descriptors[somename]`` over
            ``getattr(mapper.all_orm_descriptors, somename)`` to avoid name
            collisions.

        .. seealso::

            :attr:`_orm.Mapper.attrs`

        )r   r  r)  rH   _all_sqla_attributesr   s    r.   all_orm_descriptorszMapper.all_orm_descriptors	  s/    D ''##88:;
 	
r-   c                 ^   t         j                  j                  }| j                  D ch c]  }|j                   }}| j
                  j                         D ci c]@  \  }}t        ||j                        r%|j                  |v r|j                  |j                  B c}}S c c}w c c}}w )z~return a dictionary of {syn_attribute_name: pk_attr_name} for
        all synonyms that refer to primary key columns

        )
r   rH  rI  r  r   r   r   rL   SynonymPropertyr   )r   rO  r   pk_keysr  r_  s         r.   _pk_synonymszMapper._pk_synonyms
  s      >>>>(,(@(@A488AA ++++-
3#/??@G# GGSXX
 	
 B
s   B$AB)c                 l    t         j                  j                  }| j                  |j                        S )a  Return a namespace of all :class:`.SynonymProperty`
        properties maintained by this :class:`_orm.Mapper`.

        .. seealso::

            :attr:`_orm.Mapper.attrs` - namespace of all
            :class:`.MapperProperty`
            objects.

        )r   rH  rI  _filter_propertiesr  )r   rO  s     r.   synonymszMapper.synonyms$
  s,      >>>>&&'7'G'GHHr-   c                     | j                   S r(   r   r   s    r.   r  zMapper.entity_namespace5
  s    {{r-   c                 @    | j                  t        j                        S )a  Return a namespace of all :class:`.ColumnProperty`
        properties maintained by this :class:`_orm.Mapper`.

        .. seealso::

            :attr:`_orm.Mapper.attrs` - namespace of all
            :class:`.MapperProperty`
            objects.

        )r  r   r4  r   s    r.   column_attrszMapper.column_attrs9
  s     &&z'@'@AAr-   zsqlalchemy.orm.relationshipsc                 h    | j                  t        j                  j                  j                        S )aL  A namespace of all :class:`.RelationshipProperty` properties
        maintained by this :class:`_orm.Mapper`.

        .. warning::

            the :attr:`_orm.Mapper.relationships` accessor namespace is an
            instance of :class:`.OrderedProperties`.  This is
            a dictionary-like object which includes a small number of
            named methods such as :meth:`.OrderedProperties.items`
            and :meth:`.OrderedProperties.values`.  When
            accessing attributes dynamically, favor using the dict-access
            scheme, e.g. ``mapper.relationships[somename]`` over
            ``getattr(mapper.relationships, somename)`` to avoid name
            collisions.

        .. seealso::

            :attr:`_orm.Mapper.attrs` - namespace of all
            :class:`.MapperProperty`
            objects.

        )r  r   rH  orm_relationshipsRelationshipPropertyr   s    r.   relationshipszMapper.relationshipsG
  s*    2 &&NN,,AA
 	
r-   c                 h    | j                  t        j                  j                  j                        S )a  Return a namespace of all :class:`.CompositeProperty`
        properties maintained by this :class:`_orm.Mapper`.

        .. seealso::

            :attr:`_orm.Mapper.attrs` - namespace of all
            :class:`.MapperProperty`
            objects.

        )r  r   rH  rI  CompositePropertyr   s    r.   
compositeszMapper.compositesd
  s*     &&NN//AA
 	
r-   c                     | j                          t        j                  t        j                  fd| j                  j                         D                    S )Nc              3   F   K   | ]  \  }}t        |      s||f  y wr(   )rL   )r   r  vtype_s      r.   r   z,Mapper._filter_properties.<locals>.<genexpr>x
  s'      1a*Q:NAs   !	!)rq  r   r  r   r   r   )r   r(  s    `r.   r  zMapper._filter_propertiesu
  sJ    '' #';;#4#4#6 
 	
r-   c           	      ,   t        | j                  d      D cg c]+  \  }}|t        j                  d|z  |j                        f- }}}t        j
                  |D cg c]
  \  }}||k(   c}} t        j                  |      fS c c}}w c c}}w )zcreate a "get clause" based on the primary key.  this is used
        by query.get() and many-to-one lazyloads to load this item
        by primary key.

        r   zpk_%dr(  )	enumerater   r   	bindparamrD   and_r   column_dict)r   idxr   paramsr  r'  s         r.   _get_clausezMapper._get_clause}
  s     %.d.>.>$B

 ![ gm;3C3CD
 
 HHF3&1aqAv34V$
 	

 4s   0B
!B
c                     t        j                         fd}| j                  j                  D ]2  }|j                  t        j                  |j                  i d|i       4 S )a  Create a map of all equivalent columns, based on
        the determination of column pairs that are equated to
        one another based on inherit condition.  This is designed
        to work with the queries that util.polymorphic_union
        comes up with, which often don't include the columns from
        the base table directly (including the subclass table columns
        only).

        The resulting structure is a dictionary of columns mapped
        to lists of equivalent columns, e.g.::

            {
                tablea.col1:
                    {tableb.col1, tablec.col1},
                tablea.col2:
                    {tabled.col2}
            }

        c                    | j                   t        j                  k(  r| j                  v r)| j                     j	                  | j
                         n-t        j                  | j
                  f      | j                  <   | j
                  v r)| j
                     j	                  | j                         y t        j                  | j                  f      | j
                  <   y y r(   )operatorr"   eqleftr  rightr   r	  )binaryr  s    r.   visit_binaryz0Mapper._equivalent_columns.<locals>.visit_binary
  s    ),,.;;&(6;;'++FLL9*.//6<</*JF6;;'<<6)6<<(,,V[[9+/??FKK>+JF6<<( /r-   r8  )r   r.  r   r   rV   r$   traverse)r   r9  r3   r  s      @r.   r  zMapper._equivalent_columns
  si    * !!#		K &&;; 	F''3!!,,b8\2J	 r-   c                 ~    t        |t        t        j                  t        j
                  f      ry|| j                  vS r  )rL   r   r	   ClassManagerr!   rc  _dataclass_fields)r   assigned_nameobjs      r.   _is_userland_descriptorzMapper._is_userland_descriptor
  s=     ,,((
  (>(>>>r-   c                 z    t        j                  | j                        D cg c]  }|j                   c}S c c}w r(   )r   dataclass_fieldsr;   r   )r   fs     r.   r=  zMapper._dataclass_fields
  s)     $ 5 5dkk BC1CCCs   8c                    |rQ| j                   j                  j                  |d      	 [| j                  || j                   j                  |         r2y| j                  j                  |d      }|| j                  ||      ry| j                  3|| j                  vr%||| j                  vr| j                  d|z         y| j                  3|| j                  v s|#|| j                  v r| j                  d|z         yy)zdetermine whether a particular property should be implicitly
        present on the class.

        This occurs when properties are propagated from an inherited class, or
        are applied from the columns present in the mapped table.

        NTznot including property %szexcluding property %sF)	r;   r   rd  r@  rH   rJ  rq   r}   rr   )r   r   r>  r   r   attrs         r.   r   zMapper._should_exclude
  s    {{##''t"::t{{33MB %%99-NDD$@$@t%  ##/D33361H1H#HII1T:;"".D+++"v1H1H'HII-67r-   c                 2    | j                   |j                   u S )zXReturn true if the given mapper shares a
        common inherited parent as this mapper.)r   r   others     r.   common_parentzMapper.common_parent
  s     5#4#444r-   c                     | j                   |j                   u xr& | j                  |       xr |j                  |        S )z{return true if the other mapper is an inheriting sibling to this
        one.  common parent but different branch

        )r   r  rG  s     r.   
is_siblingzMapper.is_sibling
  sC      1 11 $HHUO#$IIdO#	
r-   c                     | j                         }| j                  |rt        |      j                  |      S t        |      |u S r(   )primary_mapperr@   r   r  )r   r+  allow_subtypesss       r.   _canloadzMapper._canload  sD    !*n '++A.. '1,,r-   c                 N    | }|r||ur|j                   }|r||urt        |      S )z>Return True if the this mapper inherits from the given mapper.)rR   bool)r   rH  r]  s      r.   r  z
Mapper.isa  s/     AUN

A AUNAwr-   c              #   <   K   | }|r| |j                   }|ry y wr(   )rR   )r   r]  s     r.   r   zMapper.iterate_to_root  s!     G

A s   c                     g }t        | g      }|r?|j                         }|j                  |       |j                  |j                         |r?t        j                  |      S )zThe collection including this mapper and all descendant mappers.

        This includes not just the immediately inheriting mappers but
        all their inheriting mappers as well.

        )r   r>  r   r?  r   r   r   )r   descendantsrA  rB  s       r.   r   zMapper.self_and_descendants  sZ     tf==?Dt$LL112    --r-   c                 ,    t        | j                        S )aC  Iterate through the collection including this mapper and
        all descendant mappers.

        This includes not just the immediately inheriting mappers but
        all their inheriting mappers as well.

        To iterate through an entire hierarchy, use
        ``mapper.base_mapper.polymorphic_iterator()``.

        )r  r   r   s    r.   polymorphic_iteratorzMapper.polymorphic_iterator,  s     D--..r-   c                 .    | j                   j                  S )zSReturn the primary mapper corresponding to this mapper's class key
        (class).)rH   r3   r   s    r.   rM  zMapper.primary_mapper9  s     !!(((r-   c                 B    | j                   j                  j                  S r(   )rH   r3   r   r   s    r.   primary_base_mapperzMapper.primary_base_mapper?  s    !!((444r-   c                     | j                   }|r|D cg c]  }|j                  |    }}|j                         }|D ]  }||vs y yc c}w )NFT)r   r  keys)r   r  r  r  r   rkr  s          r.   _result_has_identity_keyzMapper._result_has_identity_keyC  sZ    ""3:;awq);G;[[] 	C"}	  <s   A	c                     | j                   }|r|D cg c]  }|j                  |    }}| j                  t        fd|D              |fS c c}w )a  Return an identity-map key for use in storing/retrieving an
        item from the identity map.

        :param row: A :class:`.Row` instance.  The columns which are
         mapped by this :class:`_orm.Mapper` should be locatable in the row,
         preferably via the :class:`_schema.Column`
         object directly (as is the case
         when a :func:`_expression.select` construct is executed), or
         via string names of the form ``<tablename>_<colname>``.

        c              3   (   K   | ]	  }|     y wr(   r,   )r   r   rows     r.   r   z/Mapper.identity_key_from_row.<locals>.<genexpr>`  s     4&#f+4s   )r   r  r   r   )r   ra  r  r  r  r   s    `    r.   identity_key_from_rowzMapper.identity_key_from_rowN  sZ     ""3:;awq);G;   4G44
 	
 <s   Ac                 2    | j                   t        |      |fS )zReturn an identity-map key for use in storing/retrieving an
        item from an identity map.

        :param primary_key: A list of values indicating the identifier.

        )r   r   )r   r   r  s      r.   identity_key_from_primary_keyz$Mapper.identity_key_from_primary_keyd  s     ##U;%7GGr-   c                 l    t        j                  |      }| j                  |t         j                        S )a  Return the identity key for the given instance, based on
        its primary key attributes.

        If the instance's state is expired, calling this method
        will result in a database check to see if the object has been deleted.
        If the row no longer exists,
        :class:`~sqlalchemy.orm.exc.ObjectDeletedError` is raised.

        This value is typically also found on the instance state under the
        attribute name `key`.

        r   instance_state_identity_key_from_statePASSIVE_OFF)r   instancer+  s      r.   identity_key_from_instancez!Mapper.identity_key_from_instancem  s-     ))(3,,UJ4J4JKKr-   c                     |j                   }|j                  }| j                  t        | j                  D cg c],  }||j
                     j                  j                  |||      . c}      |j                  fS c c}w r(   )	r)  r   r   r   r  r   implrd  r  )r   r+  passiver,  r   r   s         r.   rh  zMapper._identity_key_from_state}  s}     

--   !% 8 8 DHH%**..ueWE   	
 		
s   1A;
c                 v    t        j                  |      }| j                  |t         j                        }|d   S )aG  Return the list of primary key values for the given
        instance.

        If the instance's state is expired, calling this method
        will result in a database check to see if the object has been deleted.
        If the row no longer exists,
        :class:`~sqlalchemy.orm.exc.ObjectDeletedError` is raised.

        r   rf  )r   rj  r+  identity_keys       r.   primary_key_from_instancez Mapper.primary_key_from_instance  s;     ))(344:))
 Ar-   c                     | j                   D cg c]  }|j                  j                   c}t              j	                  d g      rfd}|S d }|S c c}w )Nc                 V    t        d t        | j                  d         D              S )Nc              3   :   K   | ]  \  }}| ||      n|  y wr(   r,   )r   key_fnvals      r.   r   z=Mapper._persistent_sortkey_fn.<locals>.key.<locals>.<genexpr>  s*      # $*#5F3K3>s   r   )r   zipr   )r+  key_fnss    r.   r   z*Mapper._persistent_sortkey_fn.<locals>.key  s,     '*7EIIaL'A  r-   c                      | j                   d   S )Nr   )r   )r+  s    r.   r   z*Mapper._persistent_sortkey_fn.<locals>.key  s    yy|#r-   )r   rD   sort_key_functionr*   
difference)r   r  r   rx  s      @r.   _persistent_sortkey_fnzMapper._persistent_sortkey_fn  sU    9=9I9IJ#388--Jw<""D6* 
$ 
 Ks   Ac                 Z    | j                   D cg c]  }| j                  |    c}S c c}w r(   )r   r  r   r  s     r.   r  zMapper._identity_key_props  s'    7;7G7GH&&s+HHHs   (c                 x    t               }| j                  D ]   }|j                  | j                  |          " |S r(   )r*   r  r   r  )r   
collectionr   s      r.   _all_pk_colszMapper._all_pk_cols  s;    U
[[ 	9Ed0078	9r-   c                 ~    t        | j                        }| j                  |j                  | j                         |S r(   )r*   r   r@   r  )r   colss     r.   _should_undefer_in_wildcardz"Mapper._should_undefer_in_wildcard  s5    4##$*HHT(()r-   c                 n    | j                   D ch c]  }| j                  |   j                   c}S c c}w r(   )r  r  r   r~  s     r.   _primary_key_propkeyszMapper._primary_key_propkeys  s-    ;?;L;LMC&&s+//MMMs    2c                     | j                   |   }|j                  |j                     j                  j	                  |||      S Nrn  )r  r   r   rm  rd  r   r+  r,  r   rn  r   s         r.   _get_state_attr_by_columnz Mapper._get_state_attr_by_column  s?     %%f-}}TXX&++//ug/NNr-   c                     | j                   |   }|j                  |j                     j                  j	                  |||       y r(   )r  r   r   rm  set_committed_valuer   r+  r,  r   rz  r   s         r.   #_set_committed_state_attr_by_columnz*Mapper._set_committed_state_attr_by_column  s7    %%f-dhh$$88uMr-   c                     | j                   |   }|j                  |j                     j                  j	                  |||d        y r(   )r  r   r   rm  r*   r  s         r.   _set_state_attr_by_columnz Mapper._set_state_attr_by_column  s9    %%f-dhh$$((udCr-   c                     t        j                  |      }t        j                  |      }| j                  |||t         j                        S r  )r   rg  instance_dict#_get_committed_state_attr_by_columnri  )r   r?  r   r+  r,  s        r.   _get_committed_attr_by_columnz$Mapper._get_committed_attr_by_column  sI    ))#.((-775&**@*@ 8 
 	
r-   c                     | j                   |   }|j                  |j                     j                  j	                  |||      S r  )r  r   r   rm  get_committed_valuer  s         r.   r  z*Mapper._get_committed_state_attr_by_column  sG     %%f-}}TXX&++??5' @ 
 	
r-   c                       j                   }t        |      j                  j                  j                  j                               }t        t        |D cg c]-  }||   j                  D ]  }t        j                  |d       / c}}        j                  j                  v ry fd}g }d}	t        t         j                                     D ]  }
|
j                  v rd}	n&t        |
j                  t         j"                        s y|	s=|
j$                  rJ|j'                  |
j(                         j+                  |
j                          	 t-        j.                  |d   i d|i      |d<   t3        j4                  | }g }|D ]   }|j7                  ||   j                         " t3        j8                  | j;                  |      j=                  t>              S c c}}w # t0        $ r Y yw xY w)al  assemble a WHERE clause which retrieves a given state by primary
        key, using a minimized set of tables.

        Applies to a joined-table inheritance mapper where the
        requested attribute names are only present on joined tables,
        not the base table.  The WHERE clause attempts to include
        only those tables to minimize joins.

        T)check_columnsNc                 d   | j                   }| j                  }||y |j                  vr{j                  j                  |t
        j                        }|t        j                  v r
t               t        j                  d || j                  j                        | _         y |j                  vr{j                  j                  |t
        j                        }|t        j                  v r
t               t        j                  d || j                  j                        | _        y y )Nr  r*  )r6  r7  r   r  r)  r   PASSIVE_NO_INITIALIZEorm_util	_none_set_OptGetColumnsNotAvailabler   r,  rD   )r8  leftcolrightcolleftvalrightvalr   r+  r  s        r.   r9  z5Mapper._optimized_get_statement.<locals>.visit_binary   s   kkG||H("2}}F*BBJJ&<<	 C  h000466!mm'):): v-CCJJ&<<	 D  x111466"}}(&,,*;*;  .r-   Fr   r8  ) r   r*   r  r3   r  r\  r   r  r   r  r   rU   reversedr   r   rL   r!   TableClauserQ   r   rV   r  r$   cloned_traverser  r   r-  r?  selectwhereset_label_styler%   )r   r+  attribute_namespropscol_attribute_namesr   r   r9  allcondsstartr3   condr  r  s   ``           @r.   _optimized_get_statementzMapper._optimized_get_statement  s    !/2??LL%%**,
   3"3Z//  (($??
 ''61	> 
 tD$8$8$:;< 	/F!!V+ 2 2J4J4JKV]] 8 89

6--.	/	"22R(L!9HQK xx"& 	,CKKc
**+	, JJU4[_;<	
UD * 		s   2G+G1 1	G=<G=c              #      K   | j                  |      r8| }| j                         D ]"  }| ||ur||j                  vr y |}||u s" y  y y wr(   )r  r   r  )r   r3   prevr]  s       r.   _iterate_to_target_viawpolyz"Mapper._iterate_to_target_viawpolyE  s_     88FD))+ D=T1L1L%L; s   AAAc                 x   |s,|}| j                  |      D ]  }|j                  dk(  s|c S  y t        |      }|D ci c]  }|j                  | }}|j	                  |g      D ]M  }|j                  }| j                  |      D ]+  }|j                  dk(  s||v s|j                  ||      c c S  O y c c}w )Nr   )r  rm   r*   r3   r   rd  )r   enabled_via_optpolymorphic_fromr3   r]  eenabled_via_opt_mappersr   s           r.   _should_selectin_loadzMapper._should_selectin_loadR  s    %F55f= %%3H   "/2O<K&Lqqxx{&L#&L)//1A0BC A99&A AA**j8 776::1a@@AA  'Ms   B7zsqlalchemy.orm.strategy_optionsc           	         t         j                  j                  }| j                  sJ | j                  3| j
                  | j                     }t        |g| j                  z         }nt        | j                        }|j                  |      }|j                  |      }| j                  D ]  }|j                  | j                  vr|j                  | u s||v rVt        |t              s?|j                  t!        |j"                  |j                        ft%        |j&                               |j                  t!        |j"                  |j                        fddi        | j(                  D cg c]  }t+        j,                  |ddi       }	}t/        |	      dkD  rt1        j2                  |	 }
n|	d   }
|j4                  r|j6                  | u sJ t1        j8                  |      j;                  t<              }|j>                  jA                  |
      }
|	D cg c]  }|j>                  jA                  |       }	} |jC                  |
jE                  t1        jF                  dd                  jH                  |	 }njt1        j8                  |       j;                  t<              } |jC                  |
jE                  t1        jF                  dd                  jH                  |	 }|||fS c c}w c c}w )zbAssemble a that can load the columns local to
        this subclass as a SELECT with IN.

        
do_nothingT
_orm_adaptr   r   primary_keys)	expanding)%r   rH  orm_strategy_optionsrR   r@   r  r*   r  Loadr  r   rH   rM  rL   r   set_generic_strategyr6  r  r)  strategy_keyr   r   _deep_annotater  r   tuple_is_aliased_classr3   r  r  r%   _adapterr:  r  r  r,  order_by)r   r   strategy_optionspolymorphic_prop
keep_propsdisable_opt
enable_optr   pkr   in_exprqr  s                r.   _subclass_load_via_inzMapper._subclass_load_via_inh  s     >>>>}}}*#55d6I6IJ./$2J2JJKJT556J&++F3%**62
JJ 	D
 xxt111{{d"dj&8 "$(;<// V44dhh?A**+ 00 V44dhh?A!4(3	F &&
 ##Bt(<=
 

 {ajj+.G!!nG""==D(((

6"22.A oo..w7G@KL16??33A6LKLCMM.DIJh%A
 

4 00.ACMM.DIJh%A *k))?
$ Ms   2K2"K7c                 $    | j                  |       S r(   )r  r   s    r.   _subclass_load_via_in_mapperz#Mapper._subclass_load_via_in_mapper  s    ))$//r-   c           	   #     K   t               }t               t               }}|j                  j                  |       sJ t	        t	        |j                  j
                  j                               |||j                  fg      }|r|d   \  }}	}
}|s|j                          |	|u rU|j                         }||j                  vrBt	        |j                  ||
|||            }|rm|j                  ||ddf       nW|	|u rS|j                         \  }}}}||||f |j                  t	        |j
                  j                               |||f       |ryyw)a.  Iterate each element and its mapper in an object graph,
        for all relationships that meet the given cascade rule.

        :param type\_:
          The name of the cascade rule (i.e. ``"save-update"``, ``"delete"``,
          etc.).

          .. note::  the ``"all"`` cascade is not accepted here.  For a generic
             object traversal function, see :ref:`faq_walk_objects`.

        :param state:
          The lead InstanceState.  child items will be processed per
          the relationships defined for this object's mapper.

        :return: the method yields individual object instances.

        .. seealso::

            :ref:`unitofwork_cascades`

            :ref:`faq_walk_objects` - illustrates a generic function to
            traverse all objects without relying on cascades.

        rb  N)r*   objectr3   r  r   r   rE  r)  r   r>  rn  cascade_iteratorr   )r   r(  r+  halt_onvisited_statesprpmpp
visitablesiterator	item_typeparent_stateparent_dictr   queuerj  instance_mappercorresponding_statecorresponding_dicts                     r.   r  zMapper.cascade_iterator  sr    2 8VXS||%%%ELL''..013uzzJK

 =G^:Hi{ C''),))$#& %%uc4&>?c! $$&#'& #'&	  !!o44;;=>+*	E s   EEEc                 @    t        j                  | j                        S r(   )r   LRUCacherh   r   s    r.   _compiled_cachezMapper._compiled_cache  s    }}T6677r-   c                   
 i 
| j                   j                  D ]%  }|j                  D ]  }
j                  ||        ' g }
j	                         D ]?  \  }}|j
                  }|s|j                  |j                  D cg c]  }||f c}       A 
fd}t        j                  
||      }t        j                         }	|D ]
  }
|   |	|<    |	S c c}w )Nc                    j                  | j                  j                        }j                  | j                  j                        }||||ur|j                  t        t        j                  |j                              }|j                  L|j                  t        j                  |j                              }| j                  |vxr | j                  |vS | j                  |vS yr  )	rd  rM  r   r   rV   r*   r   _find_columnsr   )fkrM  depr  table_to_mappers       r.   skipz#Mapper._sorted_tables.<locals>.skip"  s     %((9F!%%biioo6C"Ov%))5811#2G2GHI++7:: ..v/G/GHD 99D0JRYYd5JJ99D00r-   )skip_fnextra_dependencies)r   r   r  
setdefaultr   rR   r?  r   sort_tablesr   r   )r   r3   r  r  r   super_super_tabler  sorted_retr  s             @r.   _sorted_tableszMapper._sorted_tables  s    &&;; 	6F]] 6**1f56	6  ,224 	ME6__F"))=C]]Kkk5)K		0 &&1
   	(A$Q'CF	(
I Ls   C
c                 l    || j                   v r| j                   |   S  |       x| j                   |<   }|S r(   )rg   )r   r   	callable_rz  s       r.   _memozMapper._memoE  s=    $'''((--1:<D!!#&Lr-   c                    t        j                  t              }| j                  D ]  }t	        |j
                        }| j                         D ]  }|j                  s|j                  t        j                  t        j                  |j                  D cg c]  \  }}|j                   c}}            sk||   j                  ||j                  f         |S c c}}w )zgmemoized map of tables to collections of columns to be
        synchronized upwards to the base mapper.)r   defaultdictr   r  r*   r   r   rf   r  reducer   r
  r   )r   r  r   r  r]  ru  rs          r.   _table_to_equatedzMapper._table_to_equatedL  s    
 !!$'(( 		IEuww<D))+ I,,1B1BKK		121J1JKAK2 5M((!Q-F-F)GHI		I  Ls   C)NNNFNNNFNNNNNFNNTTNNNTFTFFd   )F)TT)T)NFF)r,   r(   )NN)rF   rE   __qualname____doc__r   r   r   deprecated_paramsr   	is_mapperrepresents_outer_joinpropertyr3   r   r   rU   r   rR   r   rP   r  r   r;   rH   rQ   r9   r@   ro   rn   r   r  r`   r   
deprecatedr   memoized_propertyr   rv   rl   r   r   r   rw   r   rz   rx   ry   r2  r&   memoized_attributer<  r0  rF  preload_moduler   r"  rV  rq  rv  r{  rx  r~   r  r}   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  with_polymorphic_mappersr  r  r  r  r  r  r  r  memoized_instancemethodr  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r!  r$  r  r1  r  r@  r=  r   rI  rK  rP  r  r   r   rW  rM  rZ  r^  rb  rd  rk  r   PASSIVE_RETURN_NO_VALUErh  rq  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r,   r-   r.   r7   r7   W   s   	 O T
	 !!!! ;A	(	A	(L I%!    K, 8 H J	 H F K. F M F K N O  
 K
 G  J 	A4T__U56' 7 ' 
- -CJ(8A61kZ5c
J0di2V &*"## $ ##
 $
 ##/ $/ T:; <8 T:;s( <s(j T:;P <PdA.*
B) 
 
CDI
(" . * * D6 ## $ ## 
 $ 
D ##? $? ##
  $
  ##
 $
  9
 ##	
 $	
 ##
 $
  ##	
 $	
 ##
 $
 ##
 $
 ##
 $
 ## $ ##
 $
 ((
 )
0 

 
  	1 	1 6;N* ##
 $
 	
 	

 ## $8 ###5 $#5J ##C
 $C
J ##T:;
 < $
  ##T:;I < $I   ##B $B T78##
 $ 9
6 ##T:;
 < $

 ##
 $
$ ##' $'R? ##D $D)V5	
- ##. $./) 5 5	
,HL" (??
   ## $$ ##I $I ## $ ## $ ##N $N -7,N,NOND
 -7,N,N
_
B, T:;R* <R*h ##0 $0KZ ##8 $8 ##0 $0d 
 r-   r7   c                       e Zd Zy)r  N)rF   rE   r  r,   r-   r.   r  r  a  s    r-   r  c                  .    t        t               d       y)a  Initialize the inter-mapper relationships of all mappers that
    have been constructed thus far across all :class:`_orm.registry`
    collections.

    The configure step is used to reconcile and initialize the
    :func:`_orm.relationship` linkages between mapped classes, as well as to
    invoke configuration events such as the
    :meth:`_orm.MapperEvents.before_configured` and
    :meth:`_orm.MapperEvents.after_configured`, which may be used by ORM
    extensions or user-defined extension hooks.

    Mapper configuration is normally invoked automatically, the first time
    mappings from a particular :class:`_orm.registry` are used, as well as
    whenever mappings are used and additional not-yet-configured mappers have
    been constructed. The automatic configuration process however is local only
    to the :class:`_orm.registry` involving the target mapper and any related
    :class:`_orm.registry` objects which it may depend on; this is
    equivalent to invoking the :meth:`_orm.registry.configure` method
    on a particular :class:`_orm.registry`.

    By contrast, the :func:`_orm.configure_mappers` function will invoke the
    configuration process on all :class:`_orm.registry` objects that
    exist in memory, and may be useful for scenarios where many individual
    :class:`_orm.registry` objects that are nonetheless interrelated are
    in use.

    .. versionchanged:: 1.4

        As of SQLAlchemy 1.4.0b2, this function works on a
        per-:class:`_orm.registry` basis, locating all :class:`_orm.registry`
        objects present and invoking the :meth:`_orm.registry.configure` method
        on each. The :meth:`_orm.registry.configure` method may be preferred to
        limit the configuration of mappers to those local to a particular
        :class:`_orm.registry` and/or declarative base class.

    Points at which automatic configuration is invoked include when a mapped
    class is instantiated into an instance, as well as when ORM queries
    are emitted using :meth:`.Session.query` or :meth:`_orm.Session.execute`
    with an ORM-enabled statement.

    The mapper configure process, whether invoked by
    :func:`_orm.configure_mappers` or from :meth:`_orm.registry.configure`,
    provides several event hooks that can be used to augment the mapper
    configuration step. These hooks include:

    * :meth:`.MapperEvents.before_configured` - called once before
      :func:`.configure_mappers` or :meth:`_orm.registry.configure` does any
      work; this can be used to establish additional options, properties, or
      related mappings before the operation proceeds.

    * :meth:`.MapperEvents.mapper_configured` - called as each individual
      :class:`_orm.Mapper` is configured within the process; will include all
      mapper state except for backrefs set up by other mappers that are still
      to be configured.

    * :meth:`.MapperEvents.after_configured` - called once after
      :func:`.configure_mappers` or :meth:`_orm.registry.configure` is
      complete; at this stage, all :class:`_orm.Mapper` objects that fall
      within the scope of the configuration operation will be fully configured.
      Note that the calling application may still have other mappings that
      haven't been produced yet, such as if they are in modules as yet
      unimported, and may also have mappings that are still to be configured,
      if they are in other :class:`_orm.registry` collections not part of the
      current scope of configuration.

    Trm  N)rp  r/   r,   r-   r.   configure_mappersr  e  s    H /+T:r-   c                    | D ]  }|j                   s n y t        5  t        r
	 d d d        y da	 | D ]  }|j                   s n 	 dad d d        y t        j                  j                  t              j                          t        | |       da	 d d d        t        j                  j                  t              j                          y # daw xY w# 1 sw Y   BxY w)NTF)	ro  r)   _already_compilingr7   rs   
_for_classbefore_configured_do_configure_registriesafter_configured)
registriesrn  r2   s      r.   rp  rp    s      		 '' ' "	' " ##  "'-' ' OO&&v.@@B %Z9!&-'. OOv&779 "'-' 's9   CCCCC=CCCCCzsqlalchemy.orm.decl_apic                 f   t         j                  j                  j                  }t	        |       }|j                  |       D ]5  }d}|j                         D ]  }d }|j                  j                  D ]!  } |||j                        }|t        u sd} n |t        u rHt        |dd      r8t        j                  d|d|j                        }	|j                  |	_        |	|j                  r	 |j!                          |j#                          |j                  j%                  ||j                          |sd|_        |r|j0                  j3                  |      s#t        j                  d       y # t&        $ r, t)        j*                         d   }
t-        |
d      s|
|_         w xY w)NFTr   zsOne or more mappers failed to initialize - can't proceed with initialization of other mappers. Triggering mapper: 'z'. Original exception was: r   zHconfigure was called with cascade=False but additional registries remain)r   rH  orm_decl_apir{   r*   _recurse_with_dependenciesr1   rs   before_mapper_configuredr;   r   r6  r   r   r   r   rv  r~   mapper_configured	Exceptionsysexc_infor   ro  _dependenciesr{  )r  rn  r{   origr2   has_skipr3   run_configurefnr  r   s              r.   r  r    s    ~~**33Hz?D22:> )//1 	F Moo>>  "66== 9 H,#H	
 (v2E:..
 v77	9 '-&>&>#$$557//1OO55ffmmL3	> $C3,,77=,,/ M): ! ,,.+C"3(;<360	s   2AE;;5F0c                    t         j                  j                  j                  }t	        |       }|j                  |       D ]  }|s0|j                  j                  |      rt        j                  d      |j                  r<	 |j                  j                         \  }}|j                  |       |j                  r<|j                  j                          |j                  j                          |j                   D ]  }|j                  j#                  |        |j                   j                          d|_         y # t        $ r Y w xY w)Nz^Registry has dependent registries that are not disposed; pass cascade=True to clear these alsoF)r   rH  r  r{   r*   _recurse_with_dependents_dependentsr{  r   r   	_managerspopitem_dispose_manager_and_mapperr3  _non_primary_mappersclearr  discardro  )r  rn  r{   r  r2   r   _r  s           r.   _dispose_registriesr,     s     ~~**33Hz?D00< !3??55d;,,8 
 mm9 ]]224

 //8 mm 	  &&($$ 	)COO##C(	)!
 !3!  s   E	EEc                     d| _         | S )a  Decorate a method as the 'reconstructor' hook.

    Designates a single method as the "reconstructor", an ``__init__``-like
    method that will be called by the ORM after the instance has been
    loaded from the database or otherwise reconstituted.

    .. tip::

        The :func:`_orm.reconstructor` decorator makes use of the
        :meth:`_orm.InstanceEvents.load` event hook, which can be
        used directly.

    The reconstructor will be invoked with no arguments.  Scalar
    (non-collection) database-mapped attributes of the instance will
    be available for use within the function.  Eagerly-loaded
    collections are generally not yet available and will usually only
    contain the first element.  ORM state changes made to objects at
    this stage will not be recorded for the next flush() operation, so
    the activity within a reconstructor should be conservative.

    .. seealso::

        :meth:`.InstanceEvents.load`

    T)r   )r!  s    r.   reconstructorr.  #  s    4 #BIr-   c                  b     |j                  dd      |j                  dd       fd}|S )a  Decorate a method as a 'validator' for one or more named properties.

    Designates a method as a validator, a method which receives the
    name of the attribute as well as a value to be assigned, or in the
    case of a collection, the value to be added to the collection.
    The function can then raise validation exceptions to halt the
    process from continuing (where Python's built-in ``ValueError``
    and ``AssertionError`` exceptions are reasonable choices), or can
    modify or replace the value before proceeding. The function should
    otherwise return the given value.

    Note that a validator for a collection **cannot** issue a load of that
    collection within the validation routine - this usage raises
    an assertion to avoid recursion overflows.  This is a reentrant
    condition which is not supported.

    :param \*names: list of attribute names to be validated.
    :param include_removes: if True, "remove" events will be
     sent as well - the validation function must accept an additional
     argument "is_remove" which will be a boolean.

    :param include_backrefs: defaults to ``True``; if ``False``, the
     validation function will not emit if the originator is an attribute
     event related via a backref.  This can be used for bi-directional
     :func:`.validates` usage where only one validator should emit per
     attribute operation.

     .. versionadded:: 0.9.0

    .. seealso::

      :ref:`simple_validators` - usage examples for :func:`.validates`

    include_removesFinclude_backrefsTc                 *    | _         d| _        | S )N)r0  r1  )r   r   )r!  r1  r0  namess    r.   wrapzvalidates.<locals>.wrapg  s"    $. 0%
! 	r-   )r   )r3  kwr4  r1  r0  s   `  @@r.   	validatesr6  A  s5    F ff.6Ovv0$7 Kr-   c                     | j                   j                  }|j                  r |j                  | j                                y y r(   )r   r3   ri   r?  )r+  ctxinstrumenting_mappers      r.   r   r   r  s4     ==//**++EIIK8 +r-   c                     | j                   j                  }|r/|j                          |j                  r|j                  |        yyy)zRun init_instance hooks.

    This also includes mapper compilation, normally not needed
    here but helps with some piecemeal configuration
    scenarios (such as in the ORM tutorial).

    N)r   r3   rq  r.  )r+  r  kwargsr9  s       r.   r   r   y  sD     !==//--/99 ::5A : r-   c                        e Zd ZdZdZd Zd Zy)r!  z4Error reporting helper for mapper._columntoproperty.r3   c                     || _         y r(   r=  r  s     r.   r   z_ColumnMapping.__init__  s	    r-   c           
      .   | j                   j                  j                  |      }|rIt        j                  d|j
                  j                  d|j                  d|j                  d|      t        j                  d|d| j                   d      )NzColumn 'r<   z1' is not available, due to conflicting property 'z':z
No column z is configured on mapper z...)r3   r   rd  orm_excUnmappedColumnErrorr   r   r   )r   r   r   s      r.   __missing__z_ColumnMapping.__missing__  sx    {{!!%%f--- <<$$fkk6::tE 
 ))t{{$
 	
r-   N)rF   rE   r  r  	__slots__r   rB  r,   r-   r.   r!  r!    s    >I
r-   r!  )Mr  
__future__r   collectionsr   	itertoolsr   r  weakrefr  r   r   r@  r	   r
   r   r   r  r   r   r   r   r   
interfacesr   r   r   r   r   r   r   path_registryr   r   r   r   r   r   r   r  r    r!   r"   r#   r   r$   sql.selectabler%   r&   WeakKeyDictionaryr+   r   r/   r4   r  symbolr5   	threadingRLockr)   _self_inspectsclass_loggerMemoizedHasCacheKeyr7   r  r  r  rp  r  r  r,  r.  r6  r   r   r)  r!  r,   r-   r.   <module>rR     s   '   
        "    (   & & 2 ) + '        "     "  ; .W..0  '
   t{{>* >>'')  E4  	E4  E4Ph	 	D;N:B .// 0/d ./! 0!D<.b9B 
T 
r-   