
    ,h                   J   % S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	r	SSK
r
SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK r SSK!J"r"  SSK!J#r$  SSK!J%r%  SSK!J&r&  SS K!J'r'  SS!K!J(r)  SS"K*J+r+  SS#K,J-r-  SS$K,J.r.  SS%K,J/r/  SS&K,J0r0  SS'K,J1r1  SS(K2J3r3  SS)K2J4r4  SS*K2J5r5  SS+K2J6r6  SS,K2J7r7  SS-K2J8r8  SS.K2J9r9  SS/K:J;r;  S0S1K!J<r<  S0SK!J#r=  S0S2K!J>r>  S0S3K!J?r?  S0S4K!J@r@  S0S5K!JArA  S0S!K!J(r(  S0S6K<JBrB  S0S7K<JCrC  S0S8KAJ,rD  S0S9KAJErE  S0S:KAJFrF  S0S;KAJGrG  S0S<KAJHrH  S0S=KAJIrI  S0S!KAJ(rJ  S0S>KAJKrK  S0S?KLJMrM  S0S@KNJOrO  S0SAKPJQrQ  S0SBKPJRrR  S0SCKSJTrT  S0SDK(JUrU  S0SEK(JVrV  S0SFKWJXrX  \(       a  SSGK*JYrY  SSHK*JZrZ  SSIK*J[r[  SSJK*J\r\  SSKK]J^r^  SSLK_J`r`  SSMKaJbrb  SSNKaJcrc  SSOKdJere  SSPK%Jfrf  SSQK:Jgrg  SSRK'Jhrh  SSSKiJjrj  SSTKkJlrl  SSUK(Jmrm  S0SVKnJoro  S0SWKnJprp  S0SXKqJrrr  S0SYKqJsrs  S0SZKtJuru  S0S[KNJvrv  S0S\KNJwrw  S0S]KSJxrx  S0S^K(Jyry  \" S_\S`9rz\" SaSbS`9r{\" ScSdS`9r|\\XSe   \\\XSe   \\Sf\\   4      4   \Sg   4   \\Sf\\   4      4   r}\ R                  " 5       rSh\Si'   SSj jrSSk jrSlq\(GR                  " Sm5      r\
GR                  " 5       r\>GR                  \?GR                   " Sn So\8\7\+   \M\5\?GR                  \>GR                  Sp   \C\\+   5
      5       5       r " Sq Sr\5      rSSs jr      SSt jr\(GR"                  " Su5            SSv j5       r\(GR"                  " Su5      SSw j5       rSSx jrSlSySz.       SS{ jjrS| rS} r " S~ S\S   5      rg)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.`.

    )annotations)deque)reduce)chainN)Any)Callable)cast)
Collection)Deque)Dict)	FrozenSet)Generic)Iterable)Iterator)List)Mapping)Optional)Sequence)Set)Tuple)Type)TYPE_CHECKING)TypeVar)Union   )
attributes)exc)instrumentation)loading)
properties)util)_O)_class_to_mapper)_parse_mapper_argument)_state_mapper)PassiveFlag)	state_str)_MappedAttribute)EXT_SKIP)InspectionAttr)MapperProperty)ORMEntityColumnsClauseRole)ORMFromClauseRole)StrategizedProperty)PathRegistry   )event)
inspection)log)schema)sql)
dispatcher)EventTarget)base)	coercions)
expression)	operators)roles)TableClause)visitors)MemoizedHasCacheKey)KeyedColumnElement)Column)Table)LABEL_STYLE_TABLENAME_PLUS_COL)HasMemoized)!HasMemoized_ro_memoized_attribute)Literal)_IdentityKeyType)_InstanceDict)_ORMColumnExprArgument)_RegistryType)registry)DependencyProcessor)CompositeProperty)SynonymProperty)MapperEvents)ClassManager)CachingEntityRegistry)ColumnProperty)RelationshipProperty)InstanceState)
ORMAdapter)Row)
RowMapping)_ColumnExpressionArgument)_EquivalentColumnMap)ReadOnlyColumnCollection)ColumnClause)ColumnElement)
FromClause)
OrderedSet_T)bound_MPMapperProperty[Any]_FnzCallable[..., Any]*Mapper[Any]r]   z.weakref.WeakKeyDictionary[_RegistryType, bool]_mapper_registriesc                 b    [            [        [        5      sS S S 5        $ ! , (       d  f       g = fN)_CONFIGURE_MUTEXsetrf        M/var/www/auris/envauris/lib/python3.13/site-packages/sqlalchemy/orm/mapper.py_all_registriesrn      s    	%& 
		s    
.c               #  b   #    [        5        H  n U R                  5        S h  vN   M     g  N	7frh   )rn   _mappers_to_configure)regs    rm   _unconfigured_mappersrr      s'      ,,... !.s   !/-
/FNO_ATTRIBUTEc                     \ rS rSr% SrS\S'   SrSrS\S'   Sr\	R                  " SS	9                            S                                                         SS jj5       rS  rS! rSr SrS"\S#'   \SS$ j5       r\S% 5       rS\S'    S\S&'   S'\S('   S)\S*'   S+\S,'   S-\S.'   S/\S0'   S\S1'   S2\S3'   S4\S5'   S6\S7'   S8\S9'   S:\S;'   S<\S='   S>\S?'   S@\SA'    SB\SC'    S\S'   S\S'   SD\S'   SE\S'   S\S'   SF\S'    SF\SG'    SH\S'    SI\S'   SrS\SJ'    S\S'    SK\S'    SL\SM'    S\SN'    S\S'    SO\S'    SP\SQ'    S\S'    SR\SS'    ST\SU'    ST\SV'    \	R(                  \	R*                  " SWSX5      SY 5       5       r\	R.                  SSZ j5       rS[ r    SS\ jrS] rS^ rS_ rS` rSSa jrSSb jr SSc jr!SSd jr"SSe jr#S
r$\%RL                  Sf 5       r'\%RL                  Sg 5       r(\%RL                  Sh 5       r)\	RT                  " Si5      Sj 5       r+\	RT                  " Si5      SSSSk.           SSl jj5       r,      SSm jr-  S           SSn jjr.\	RT                  " Si5            SSo j5       r/\	R`                  Rc                  Sp\2Rf                  5      SSq j5       r4SSr jr5Ss r6      SSt jr7SSu jr8\SSv j5       r9SSw jr:SSx jr;SSy jr<SSz jr=SS{ jr>SS| jr? S     SS} jjr@    SS~ jrA\S 5       rB      SS jrC      SS jrD\%RL                  SS j5       rE\%RL                  S 5       rF\%RL                  S 5       rG\%RL                  S 5       rH\%RL                  SS j5       rI\%RL                  S 5       rJ\KSS j5       rL\IrM \KS 5       rN\%RL                  S 5       rO\%RL                  S 5       rP\%RL                  S 5       rQ\%RL                  S 5       rR\%RL                    SS j5       rS\%RL                    SS j5       rT\%RL                  SS j5       rU\%RL                    SS j5       rV\%RL                  SS j5       rW\%R                  S 5       rY\	R.                  S 5       rZ\SS j5       r[   S       SS jjr\\%RL                  S 5       r]\S 5       r^SS jr_\%RL                  SS j5       r`SS jra\%RL                  SS j5       rb\%RL                  SS j5       rc\%RL                  \	RT                  " Si5      SS j5       5       rd\%RL                  \	RT                  " Si5      SS j5       5       re\S 5       rf\%RL                  SS j5       rg\%RL                  \	RT                  " S5        SS j5       5       rh\%RL                  \	RT                  " Si5      SS j5       5       ri    SS jrj\%RL                  S 5       rk\%RL                  SS j5       rlSS jrm\%RL                  S 5       rnS roSS jrpSS jrq      SS jrrSS jrsGS S jrt\%RL                  SS j5       ruGS S jrvGSS jrw\GSS j5       rxSS jry  S       GSS jjrz S     GSS jjr{GSS jr|\}R                  4     GSS jjrGSS jr\%RL                  S 5       r\%RL                  S 5       r\%RL                  S 5       r\%RL                  S 5       r\%RL                  S 5       r\}R                  4         GSS jjrS rS rS r\}R                  4S jrS rS r\%RL                  S 5       rS rS r\	RT                  " S5      S 5       r\%RL                  S 5       r S       GSS jjr\%RL                  S 5       r\%RL                  S 5       r\%RL                  S 5       rGS	S jr\	R.                  S 5       rSrg
(
  Mapper   a~  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`.

zdispatcher[Mapper[_O]]dispatchFr   _configure_failed)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_primaryNTclass_Type[_O]local_tableprimary_keyrz   boolinheritsinherit_conditionalways_refreshversion_id_colversion_id_generator5Optional[Union[Literal[False], Callable[[Any], Any]]]polymorphic_onpolymorphic_identityOptional[Any]concretewith_polymorphicallow_partial_pksOptional[str]c                   [         R                  " U[        S5      U l        U R                  R                  < SU R                  R
                  < 3U l        [         R                  " U5      U l        XPl	        Xl
        [        U
[        5      (       a  Xl        SU l        O.U
b$  [        R                   " ["        R$                  U
SS9OSU l        USL a  SU l        OUc	  S U l        OXl        Xl        SU l        Ub  [-        U5      U l        OSU l        Ub+  [        R                   " ["        R0                  USS	S
9U l        ObU R.                  (       a#  U R.                  R2                  U l        SU l        O.[4        R6                  " SU R                  R
                   S35      eUb+  [        R                   " ["        R8                  U5      U l        OSU l        Xl        U(       a  [?        U5      O0 U l         / U l!        UU l"        UU l#        UU l$        Ub$  [        R                   " ["        R$                  USS9OSU l%        UU l&        / U l'        [         RP                  U l)        UU l*        UU l+        UU l,        SU l-        SU l.        SU l/        0 U l0        UU l1        SU l2        UU l3        U R.                  (       a  U R(                  (       d  SU l4        OUU l4        U Rk                  U5        UU l6        Xl7        Uc  0 U l8        OXl8        Ub  [         Rr                  " U5      U l:        OSU l:        U(       a  [         Rr                  " U5      U l;        OSU l;        [x           [{        SU R|                  R~                  5      R                  X5        U R                  5         U R                  5         U R                  5         U R                  5         U R                  5         U R                  R                  U 5        U R                  S5        U R                  5         SSS5        U R|                  R                  X R                  5        g! , (       d  f       N4= f)aM  Direct constructor for a new :class:`_orm.Mapper` object.

The :class:`_orm.Mapper` constructor is not called directly, and
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:: 2.0 The public facing ``mapper()`` function is
   removed; for a classical mapping configuration, use the
   :meth:`_orm.registry.map_imperatively` method.

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
   :class:`_sql.FromClause` (i.e. 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 :attr:`_orm.DeclarativeBase.__table__` attribute
   or via the :class:`_schema.Table` produced as a result of
   the :attr:`_orm.DeclarativeBase.__tablename__` attribute being
   present.

:param polymorphic_abstract: Indicates this class will be mapped in a
    polymorphic hierarchy, but not directly instantiated. The class is
    mapped normally, except that it has no requirement for a
    :paramref:`_orm.Mapper.polymorphic_identity` within an inheritance
    hierarchy. The class however must be part of a polymorphic
    inheritance scheme which uses
    :paramref:`_orm.Mapper.polymorphic_on` at the base.

    .. versionadded:: 2.0

    .. seealso::

        :ref:`orm_inheritance_abstract_poly`

: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.

   The :paramref:`.orm.Mapper.allow_partial_pks` parameter also
   indicates to the ORM relationship lazy loader, when loading a
   many-to-one related object, if a composite primary key that has
   partial NULL values should result in an attempt to load from the
   database, or if a load attempt is not necessary.

   .. versionadded:: 2.0.36 :paramref:`.orm.Mapper.allow_partial_pks`
      is consulted by the relationship lazy loader strategy, such that
      when set to False, a SELECT for a composite primary key that
      has partial NULL values will not be emitted.

: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.

: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.

  The fetch of values occurs either by using ``RETURNING`` inline
  with the ``INSERT`` or ``UPDATE`` statement, or by adding an
  additional ``SELECT`` statement subsequent to the ``INSERT`` or
  ``UPDATE``, if the backend does not support ``RETURNING``.

  The use of ``RETURNING`` is extremely performant in particular for
  ``INSERT`` statements where SQLAlchemy can take advantage of
  :ref:`insertmanyvalues <engine_insertmanyvalues>`, whereas the use of
  an additional ``SELECT`` is relatively poor performing, adding
  additional SQL round trips which would be unnecessary if these new
  attributes are not to be accessed in any case.

  For this reason, :paramref:`.Mapper.eager_defaults` defaults to the
  string value ``"auto"``, which indicates that server defaults for
  INSERT should be fetched using ``RETURNING`` if the backing database
  supports it and if the dialect in use supports "insertmanyreturning"
  for an INSERT statement. If the backing database does not support
  ``RETURNING`` or "insertmanyreturning" is not available, server
  defaults will not be fetched.

  .. versionchanged:: 2.0.0rc1 added the "auto" option for
     :paramref:`.Mapper.eager_defaults`

  .. seealso::

        :ref:`orm_server_defaults`

  .. versionchanged:: 2.0.0  RETURNING now works with multiple rows
     INSERTed at once using the
     :ref:`insertmanyvalues <engine_insertmanyvalues>` feature, which
     among other things allows the :paramref:`.Mapper.eager_defaults`
     feature to be very performant on supporting backends.

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

  .. seealso::

    :ref:`include_exclude_cols`

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

  .. seealso::

    :ref:`include_exclude_cols`

: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.

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

  May be specified as a string attribute name, or as a SQL
  expression such as a :class:`_schema.Column` or in a Declarative
  mapping a :func:`_orm.mapped_column` object.  It is typically
  expected that the SQL expression corresponds to a column in the
  base-most mapped :class:`.Table`::

    class Employee(Base):
        __tablename__ = "employee"

        id: Mapped[int] = mapped_column(primary_key=True)
        discriminator: Mapped[str] = mapped_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: Mapped[int] = mapped_column(primary_key=True)
        discriminator: Mapped[str] = mapped_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 using its string name,
  which is of particular use when using annotated column
  configurations::

        class Employee(Base):
            __tablename__ = "employee"

            id: Mapped[int] = mapped_column(primary_key=True)
            discriminator: Mapped[str]

            __mapper_args__ = {
                "polymorphic_on": "discriminator",
                "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 :paramref:`_orm.Mapper.polymorphic_on` setting. As
  rows are received, the value corresponding to the
  :paramref:`_orm.Mapper.polymorphic_on` column expression is compared
  to this value, indicating which subclass should be used for the newly
  reconstructed object.

  .. seealso::

    :ref:`inheritance_toplevel`

: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, or alternatively string names of attribute names which
   refer to :class:`_schema.Column`, 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.

   .. versionchanged:: 2.0.2 :paramref:`_orm.Mapper.primary_key`
      arguments may be indicated as string attribute names as well.

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

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

    The :paramref:`_orm.Mapper.polymorphic_load` parameter may be
    preferable over the use of :paramref:`_orm.Mapper.with_polymorphic`
    in modern mappings to indicate a per-subclass technique of
    indicating polymorphic loading styles.

    .. seealso::

        :ref:`with_polymorphic_mapper_config`

r{   .Nr   argnameFc                    U =(       d    SS-   $ )Nr   r   rk   )xs    rm   <lambda>!Mapper.__init__.<locals>.<lambda>  s    16Q,rl   Tr}   )disable_inspectionr   Mapper[zM(None)] has None for a primary table argument and does not specify 'inherits'r   rO   constructed)Kr!   assert_arg_typetyper{   
__module____name__	_sort_keyto_list_primary_key_argumentrz   r   
isinstancer+   version_id_propr   r9   expectr<   ColumnArgumentOrKeyRoler   r   singler$   r   StrictFromClauseRoler}   sa_excArgumentErrorOnClauseRoler   inherit_foreign_keysdict_init_properties_delete_orphansbatcheager_defaultscolumn_prefixr   polymorphic_abstract_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_reconstructorr   confirm_deleted_rows_set_with_polymorphicpolymorphic_loadr   polymorphic_mapto_setinclude_propertiesexclude_propertiesri   r	   rw   _events_new_mapper_instance_configure_inheritance _configure_class_instrumentation_configure_properties_configure_polymorphic_setter_configure_pksrK   _flag_new_mapper_log_expire_memoizationsafter_mapper_constructed)selfr{   r}   r    r~   rz   r   r   r   r   r   r   r   _polymorphic_mapr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   s                                 rm   __init__Mapper.__init__   s   r **64BKK""KK  

 &*\\+%>"&,nn55#1 "&D "-   11",    5((-D%!)(>D%(<% 28<DM DM"(//**#'%	 D ]]  $}}88DDK&&$++../ 0I I 
 (%.%5%5""$5&D" &*D"$8!4>Z 0B!
,* ) --(  	 %9!&(#//.. 0#&+#'+$ "$8!"!2==(-D%(<D%""#34 0
 %9!
 ##%D #3 )&*kk2D&ED#&*D#&*kk2D&ED#&*D#
 !6!67LL '')113&&(..0!MM**40IIm$%%'  	..t[[A s   $B<Q
Qc                    U R                   S:X  a3  UR                  (       d  gX R                  ;   =(       a    UR                  $ U R                   $ )NautoF)r   implicit_returning_server_default_col_keysinsert_executemany_returning)r   dialecttables      rm   _prefer_eager_defaultsMapper._prefer_eager_defaultsi  sK    &(++ 666 988
 &&&rl   c                    U 4$ rh   rk   )r   anon_map
bindparamss      rm   _gen_cache_keyMapper._gen_cache_keyu  s	    wrl   rJ   rK   c                    U $ )z,Part of the inspection API.

Returns self.

rk   r   s    rm   mapperMapper.mapper  s	     rl   c                    U R                   $ )z4Part of the inspection API.

Returns self.class\_.

r{   r   s    rm   entityMapper.entity  s     {{rl   _identity_classzList[Tuple[str, Type[Any]]]r   zList[DependencyProcessor]r   zDict[Any, Callable[[], Any]]r   zutil.WeakSequence[Mapper[Any]]_inheriting_mapperszSet[TableClause]_all_tables_polymorphic_attr_keyz/Dict[FromClause, OrderedSet[ColumnClause[Any]]]_pks_by_tablez0Dict[FromClause, OrderedSet[ColumnElement[Any]]]_cols_by_tablez*util.OrderedDict[str, MapperProperty[Any]]_propszDict[str, MapperProperty[Any]]r   _ColumnMapping_columntopropertyz-Optional[Callable[[InstanceState[_O]], None]]_set_polymorphic_identityzHOptional[Callable[[Mapper[_O], InstanceState[_O], _InstanceDict], None]]_validate_polymorphic_identityzSequence[TableClause]tablesz3util.immutabledict[str, Tuple[str, Dict[str, Any]]]r   zOptional[ColumnElement[Any]]zcOptional[Tuple[Union[Literal['*'], Sequence[Union[Mapper[Any], Type[Any]]]], Optional[FromClause]]]r]   persist_selectablezOptional[Mapper[Any]]zOptional[ColumnElement[bool]]
configuredzTuple[Column[Any], ...]zClassManager[_O]class_managerr   !Optional[KeyedColumnElement[Any]]zDict[Any, Mapper[Any]]r   re   base_mapperz*ReadOnlyColumnCollection[str, Column[Any]]columnscry   zUse .persist_selectablec                    U R                   $ rh   )r   r   s    rm   mapped_tableMapper.mapped_table  s     &&&rl   c                .    [         R                  " U 5      $ rh   )r/   
per_mapperr   s    rm   _path_registryMapper._path_registry  s    &&t,,rl   c                   [         R                  " 5       U l        U R                  (       Ga  [	        U R
                  U R                  R
                  5      (       dQ  [        R                  " SU R
                  R                  < SU R                  R
                  R                  < S35      eU R                  R                  U R                  R                  5        U R                  U R                  R                  :w  aZ  U R                  (       + =(       a    S=(       d    Sn[        R                  " SU< SU R
                  R                  < SU< S	35      eU R                  (       a  U R                  R                  U l        GO{U R                  U R                  R                  LGaF  U R                  (       a@  U R                  U l        U R!                  5        H  nUR"                  c  M  SUl        M     GOU R&                  c;   [(        R*                  " U R                  R                  U R                  5      U l        U R                  R                  c   e[2        R4                  " U R                  R                  U R                  U R&                  5      U l        [         R6                  " U R8                  5      n[(        R:                  " U R                  R<                  US9U l        OU R                  U l        U R@                  c~  U R
                  U l!        U RD                  (       d[  U R                  RF                  R"                  b:  [         RH                  " U  SU R                  RF                  R"                   S35        O>U R                  (       a  U R
                  U l!        OU R                  RB                  U l!        U RJ                  c7  U R                  RJ                  U l%        U R                  RL                  U l&        OU R                  RJ                  bt  U RJ                  U R                  RJ                  LaQ  [         RH                  " SU RJ                  R.                  < SU R                  RJ                  R.                  < S35        U R                  RN                  U l'        U R                  RP                  U l(        U R                  R                  RS                  U 5        U R                  RF                  U l#        U R                  RT                  U l*        U R                  RV                  =(       d    U RV                  U l+        U R                  RX                  U l,        U R@                  b  U R@                  U RN                  ;   aR  [         RH                  " SU R@                  < SU RN                  U R@                     < SU < SU R@                  < S3	5        X RN                  U R@                  '   U RZ                  (       a'  U R                  (       a  [        R                  " S5      eU RZ                  S:X  a  U R                  R]                  U 5        OU RZ                  S:X  a  OU RZ                  b#  [        R                  " SU RZ                  -  5      eOk[_        5       U l,        X l#        U R                  c   eU R                  U l        U R@                  b  X RN                  U R@                  '   U R
                  U l!        U R                  c  [        R                  " SU -  5      eg
! [        R,                   a  nU R                  R                  c   eU R                  c   e[        R,                  " SU R                  R                  R.                  < SU R                  R.                  < S35      UeS
nAf[        R0                   a  nU R                  R                  c   eU R                  c   e[        R0                  " SU R                  R                  R.                  < SU R                  R.                  < S35      UeS
nAff = f) zPConfigure settings related to inheriting and/or inherited mappers
being present.z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.z'; tables have more than one foreign key relationship established.  Please specify the 'on clause' using the 'inherit_condition' mapper argument.)consider_as_foreign_keysz| does not indicate a 'polymorphic_identity', yet is part of an inheritance hierarchy that has a 'polymorphic_on' column of 'a'  '. If this is an intermediary class that should not be instantiated, the class may either be left unmapped, or may include the 'polymorphic_abstract=True' parameter in its Mapper arguments. To leave the class unmapped when using Declarative, set the '__abstract__ = True' attribute on the 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.)0r!   WeakSequencer   r   
issubclassr{   r   r   r   rw   _updaterz   r   r   r}   r   iterate_to_rootr   r   r   sql_utiljoin_conditionNoForeignKeysErrordescriptionAmbiguousForeignKeysErrorr5   joinr   r   criterion_as_pairsonclauser   r   r   r   r   warnr   r   r   r   appendr   r   r   r   _add_with_polymorphic_subclassrj   )r   npr   nfeafefkss         rm   r   Mapper._configure_inheritance  sr   
 $(#4#4#6 ===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!00<<@F9 #9 --5
''5=5L5L $ 9 94;K;K6D2N  ==;;GGG.1hh88((../D+ ++d&?&?@C3;3N3N//88144D0
 +/*:*:'((0'+{{$ 1111@@LII& ! !MM55DDE FH	H '+{{$'+}}'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**?++,  3  #uD###///&*&6&6D#((4BF$$T%>%>?#';;D ""*&&K  +_  &88 '#'==#<#<#HH#H#'#3#3#??#?"(";"; %)MM$=$=$I$I$($4$4$@$@!"#  $'!'"  &?? '#'==#<#<#HH#H#'#3#3#??#?"("B"B %)MM$=$=$I$I$($4$4$@$@
!"# $'''s&   :\> >a"A:_a"#A:aa"c                ,   US:X  a  SU l         O~[        U[        [        45      (       a?  [        US   [        [        [        45      (       a  [        SU5      U l         O.US 4U l         O$Ub  [        R                  " SU< 35      eS U l         U R                   (       aU  U R                   S   bE  U R                   S   [        R                  " [        R                  U R                   S   SS94U l         U R                  (       a  U R                  5         g g )	Nrd   )rd   Nr   zTuple[
                        Union[
                            Literal["*"],
                            Sequence[Union["Mapper[Any]", Type[Any]]],
                        ],
                        Optional["FromClause"],
                    ]z&Invalid setting for with_polymorphic: r   Tallow_select)r   r   tupleliststrr	   r   r   r9   r   r<   r   r   r   )r   r   s     rm   r   Mapper._set_with_polymorphicm  s    s"$/D!(5$-88*1-UD/ABB(, %	)% *:4(@%)&&89I8LM  %)D!  T%:%:1%=%I%%a(  ..))!,!%%D! ??%%' rl   c                .   UR                   nU R                  c  U R                  U45        g U R                  S   S:w  aV  [        U R                  S   [        5      (       d   eU R                  U R                  S   U4-   U R                  S   45        g g )Nr   rd   r   )r{   r   r   r   r  )r   r   subcls      rm   r  %Mapper._add_with_polymorphic_subclass  s      (&&x0""1%,d33A6>>>>&&&&q)UH4d6K6KA6NO -rl   c                |   U R                   (       d   eU R                  (       a   e[        U[        5      (       d   eXl        U R                  R                  R                  U R                  5        U R                  R                  U l        U R                  5        H  nUR                  c  M  SUl        M     U R                  R                  U l	        U R                   H  nU R                  R                  Ul        M      U R                  R                  R                  U 5        U R                  R                  U l        U R                  R                  U l        UR                   R#                  5        H@  u  p4X0R                   ;  d  M  U R%                  X3SSS9(       a  M.  U R'                  X4S5        MB     g)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)r   r   r   ru   r   updater  r   r   r   self_and_descendantsr   r   r  r   r   r   items_should_exclude_adapt_inherited_property)r   r   mpkeyprops        rm   _set_concrete_baseMapper._set_concrete_base  sP   
 }}}==  &&))))%%,,T-A-AB#}}<<**,F$$004- - ]]((
++B!]]66BN ,))006#}}<<==44,,.IC++%d.B.Bd /C / / ..s%@	 /rl   c                2    Xl         U R                  S5        g )NT)r   r   )r   r   s     rm   _set_polymorphic_onMapper._set_polymorphic_on  s    ,**40rl   c           	        [         R                  " U R                  5      nU R                  (       a  U(       a  UR                  (       d#  [
        R                  " SU R                  -  5      eXl        UR                  c   eUR                  U l        UR                  R                  U l
        UR                  R                  U 5        gUb  UR                  (       d  [
        R                  " S5      eU R                  R                  X R                  5        [        R                  " U R                  U [         R"                  " [$        R&                  U 5      SS9nXl        UR                  c   eUR                  U l        UR                  c  g[(        R*                  " US[,        SS9  [         R.                  " U R                  5       GH  u  p#US:X  a:  [1        US	5      (       a)  UR2                  n[1        US
5      (       a  UR4                  n[7        U5      (       d  MX  [1        US5      (       a#  X0l        [(        R*                  " US[:        SS9  M  [1        US5      (       d  M  UR<                  nUR>                   HT  nXPR@                  ;   a  [
        R                  " SU< SU < S35      eU R@                  RC                  XSU405      U l         MV     GM     g)al  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.NzThe _mapper() function and Mapper() constructor may not be invoked directly outside of a declarative registry. Please use the sqlalchemy.orm.registry.map_imperatively() function for a classical mapping.T)r   expired_attribute_loaderfinalize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   opt_manager_of_classr{   rz   	is_mappedr   InvalidRequestErrorr   rK   r   r   _add_non_primary_mapperrw   instrument_classr   register_classr!   partialr   load_scalar_attributesr1   listen_event_on_inititerate_attributeshasattrr<  r=  callabler   _event_on_load__sa_validation_opts__r@  r   union)r   managerr0  methodvalidation_optsnames         rm   r   'Mapper._configure_class_instrumentation  sU    11$++>'"3"300 $, 
 ")##///#,,DM#*>>#A#AD 44T:?'"2"2,,4  	&&t[[9 "00KK%)\\..&
 	
 %+++(( >>!Wfn$?224;;?KCj WV5H%I%I116:..#__F6#9::*0'LL&.dKV%899&,&C&CO & 8 8??2"("<"< $(!/# 
 +///*?*?!O#<=+ !9 @rl   c                f    SU l         SU l        SU l        U R                  R	                  SS 5        g )NTrx   )r   _ready_for_configure_dispose_called__dict__popr   s    rm   _set_dispose_flagsMapper._set_dispose_flags  s.    $(!#-t4rl   c                d    U R                   U   n UR                  n[        U[        5      (       d  [        R                  " SU SU S35      eU$ ! [         a#  n[        R                  " SU SU S35      UeS nAff = f! [
         a#  n[        R                  " SU SU S35      UeS nAff = f)NzCan't determine z	 column 'z(' - no attribute is mapped to this name.z4'; property does not refer to a single mapped Column)r   KeyErrorr   r   r:   AttributeErrorr   rA   )r   r   r0  r1  errexpraes          rm   _str_arg_to_mapped_colMapper._str_arg_to_mapped_col!  s    	;;s#D	??D $''&&"7)9SE :    
 %  	&&"7)9SE :7 7 	  	&&"7)9SE :D D 	s.   A B 
A?A::A?
B/B**B/c                	  ^  [         R                  " T R                  5      T l        T R                  R                  S T R                   5       5        0 T l        0 T l        [        R                  " [        T R                   Vs/ s H  oR                  PM     sn6 5      n[        R                  " S U 5       5      n[        T R                  5      R                  T R                  /5       H  nUR                  (       a\  UR!                  UR                  5      (       a<  [        R"                  " UR                  5      R%                  U5      T R                  U'   [        R"                  " UR&                  5      R%                  U5      T R                  U'   M     T R(                  (       aK  S T R(                   5        Vs/ s H,  n[+        U[,        5      (       a  T R/                  SU5      OUPM.     nnOS nU(       ax  U Hq  nUR0                  T R                  ;  a,  [        R2                  " 5       T R                  UR0                  '   T R                  UR0                     R5                  U5        Ms     OT R                  T R                  ;  d&  [7        T R                  T R                     5      S:X  a3  [8        R:                  " ST < ST R                  R<                  < S35      eT R>                  T R                  ;  aV  [+        T R>                  [@        RB                  5      (       a-  [        RD                  " S	T R>                  R<                  -  5        T RF                  (       a>  T RH                  (       d-  T R(                  (       d  T RF                  R                  T l        OU(       a&  U 4S
 jU 5        VVs/ s H  u  pUb  UOUPM     n	nnO,[         RJ                  " T R                  T R                     SS9n	[7        U	5      S:X  a3  [8        R:                  " ST < ST R                  R<                  < S35      e[M        U	5      T l        T RO                  SU	5        T R                   Vs1 s H^  nT R                  U   T RP                  ;  d  M"  [S        US5      (       a  UR0                  T R                  ;  d  MO  T R                  U   iM`     snT l*        g s  snf s  snf s  snnf s  snf )Nc              3  $   #    U  H  ov   M     g 7frh   rk   ).0ts     rm   	<genexpr>(Mapper._configure_pks.<locals>.<genexpr>;  s     7;a;s   c              3  J   #    U  H  oR                   (       d  M  Uv   M     g 7frh   )r~   )rg  r   s     rm   ri  rj  D  s     !GX!!Xs   #	#c              3  j   #    U  H)  n[         R                  " [        R                  US S9v   M+     g7f)r~   r   N)r9   r   r<   DDLConstraintColumnRole)rg  	coerce_pks     rm   ri  rj  [  s7       &@	 $$55! -
 &@s   13r~   r   zMapper 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.c              3  ^   >#    U  H"  nTR                   R                  U5      U4v   M$     g 7frh   )r   corresponding_column)rg  r   r   s     rm   ri  rj    s.      "!/A 00EEaH!L!/s   *-T)ignore_nonexistent_tablesz"Identified primary key columns: %sr   )+r  find_tablesr   r   r   r*  r   r   r!   
column_setr   r   	proxy_setrj   rP  r~   
issupersetordered_column_setintersectionr   r   r   r!  rc  r   r^   addlenr   r   r  r}   r4   rB   r  r   r   reduce_columnsr  r   _identity_key_propsrL  _readonly_props)
r   colall_colspk_colsfcr   coerced_pk_argkccr~   s
   `         rm   r   Mapper._configure_pks8  s0   **4+B+BC74;;77 ??T-C-CD-CcMM-CDE
 //!GX!GG dkk"(($*A*A)BCB~~'"4"4R^^"D"D *.)@)@NN*, ""2&
 '+&=&=bdd&C&P&P'D# D %% &*%?%?A "!S)) //qA  N  "N #77$"4"4426//2CD&&qww/""177+//2 $ ##4+=+==4%%d&=&=>?1D&& 00<<> 
 T%7%77Jfll=
 =
 II; ""../ MMMM..  $}}88D
 "!/"" .Ba/"   '55&&t'>'>?.2
 ;1$** T44@@B   %[1DII:KH -- 
-%%c*$2J2JJ ( C))99D$7$77 (D""3'- 
Y E(v: 
s$   S%3S*S/7!S5)S5	S5c                   [         R                  " 5       =U l        U l        [        R
                  " 5       U l        [        U 5      U l        0 n0 nU R                  (       a  U R                  R                  5        H  u  p4[        U[        5      (       d  U R                  X45      nOUnSn[        U[        R                  5      (       aK  UR                   H;  nU R                   R                  R#                  U5      (       d  M/  SnXRU'   UU4X'   M=     U(       d  M  U R%                  UUSS9  M     U R&                  (       a  U R&                  R                  R                  5        H  u  p8U R)                  X3SS S9(       a  M  UR+                  U5      n	U	(       a1  U R-                  UUSU	S9n
XU'   U	R                   H	  nUU
4X'   M     Mf  X0R                  ;  d  Mw  U R/                  X8S5        M     U R0                  R                   H  nX;   a  X   u  p=U R%                  X=SS9  M   XR                  ;   a  M1  U R2                  =(       d    SUR4                  -   nU R)                  UR4                  UU R                   R                  R#                  U5      US9(       a  M  U R7                  5        H-  nXR                  ;   d  M  UR                  U   R4                  nM/     U R%                  UUSSS9  M     g )NTF)r:  r'  )	warn_onlyincoming_prop r:  	setparent)sql_baseColumnCollectionr   r   r!   OrderedDictr   r   r   r   r,  r   r+   _make_prop_from_columnr    rR   r}   contains_column_configure_propertyr   r-  get%_reconcile_prop_with_incoming_columnsr.  r   r   r0  r  )r   explicit_col_props_by_columnexplicit_col_props_by_keyr0  prop_argpossible_col_prop_map_as_property_now	given_colinherited_propr  new_propinc_colr)  r1  
column_keyr   s                   rm   r   Mapper._configure_properties  s    ( 9 9 ;;tv &&( "0!5  	% EG!   !%!6!6!<!<!>!(N;;(,(C(C)% )1% (,$/1J1JKK%6%>%>	++--==iHH380=Nc: # 1G8C	 &? (',,)" - 3 "?D =='+}}';';'A'A'C#''d'K 9 = =c B #II&"'&3	  J  H 6>c2#0#8#8$A4= $9
 +223N) (D8 --55F5 9@	(((?111,,2fjj@J##

&&((88@	 $   ..0555!'!9!9&!A!E!EJ 1 $$	 % 7 6rl   c                  ^ SnSmU R                   GbK  Sn[        U R                   [        5      (       a   U R                  U R                      U l         U R                   U R                  ;   a  U R                  U R                      nGO[        U R                   [        5      (       aM  [        U R                   [        R                  5      (       d  [
        R                  " S5      eU R                   nGOIU R                  R                  U R                   5      nUc  SnSnU R                   n[        U[        R                  5      (       a`  U R                  b0  U R                  S   b   U R                  S   R                  U5       c#  [
        R                   " SUR"                  -  5      eOSn[%        USS5      nU(       a2  U R'                  XwSU5      (       a  [
        R                   " S	U-  5      eO$UR)                  S
5      =U l         nUR*                  n[        R                  " XVS9nU R-                  XtUSS9  UR.                  S   U l         UR*                  mOU R1                  5        H  nUR                   c  M  U R                  UR                  L a  UR                   U l         O*U R                  R                  UR                   5      U l         U R                   b5  UR2                  U l        UR4                  U l        UR6                  U l          gSU l        SU l          g   U R8                  (       a#  U R                   c  [
        R                   " S5      eU(       a!  U4S jn	TU l        U4S jn
Xl        U
U l        gSU l        SU l        g! [         a)  n[
        R                  " SU R                   -  5      UeSnAff = f)au  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.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 properlyr0  z6Cannot exclude or override the discriminator column %r_sa_polymorphic_on)_instrumentr  r   zThe Mapper.polymorphic_abstract parameter may only be used on a mapper hierarchy which includes the Mapper.polymorphic_on parameter at the base of the hierarchy.c                P  > U R                   nU R                  R                  R                  nUcS  U R                  R                  R                  (       a.  [
        R                  " SU R                  R                   S35      eU R                  T5      R                  U UUS 5        g )NzCan't instantiate class for z,; mapper is marked polymorphic_abstract=True)	r   rQ  r   r   r   r   rC  get_implrj   )statedict_r   polymorphic_keys      rm   r   GMapper._configure_polymorphic_setter.<locals>._set_polymorphic_identity  s    


 MM((== % )0,,AA 446u}}7K7K6L ME E 
 /33(	rl   c                   > TU;   a:  UT   U R                   ;  a&  [        R                  " S[        U5      UT   45        g g g )NznFlushing object %s with incompatible polymorphic identity %r; the object may not refresh and/or load correctly)"_acceptable_polymorphic_identitiesr!   warn_limitedr'   )r   r  r  r  s      rm   r   LMapper._configure_polymorphic_setter.<locals>._validate_polymorphic_identity  sW    #u,o.!DDE %%G #5)5+AB	E -rl   )r   r   r!  r   r^  r   r   r   r+   r    rR   r   rp  r4   rA   r   rC  r  getattrr-  labelr0  r  r   r  r   r   r   r   )r   r:  setterr`  r1  r}  
instrumentr0  r   r   r   r  s              @rm   r   $Mapper._configure_polymorphic_setter+  s    )-*F$--s33*.++d6I6I*JD' ""d&<&<< --d.A.ABD//@@ "'')B)B  !..; 
 ** --BB'' ; #F!&J--C!#v}}55--5003;003HHM  %88? "oo.  "&Jc5$/++CeSAA$8868;<  B 14		:N0OOD'#''C!00M(((N #',,q/D"hhO ..0 ((4..&2K2KK.4.C.C+ !33..v/D/DE + **6"<< 6 #88 2 #AA ;  :>6592; 1> $$)<)<)D,,P  0 *9D& .G*. / *.D&-1D*]    ../151D1DE 	s   N 
O$OOc                P    U R                   b  U R                  U R                      $ g rh   )r   r   r   s    rm   _version_id_propMapper._version_id_prop  s(    *))$*=*=>>rl   c                   [        5       n[        U /5      nU(       ah  UR                  5       nUR                  U R                  L a6  UR	                  UR
                  5        UR                  UR                  5        U(       a  Mh  U$ rh   )rj   r   popleftr   rx  r   extendr   )r   
identitiesstackitems       rm   r  )Mapper._acceptable_polymorphic_identities  si    U
tf==?D&&$*A*AAt889T556	 e rl   c                H    [        U R                  R                  5       5      $ rh   )	frozensetr   valuesr   s    rm   	_prop_setMapper._prop_set  s    ++-..rl   zsqlalchemy.orm.descriptor_propsc                   [         R                  R                  nU R                  (       d  U R	                  XSSS9  g XR
                  ;  az  U R                  R                  X5      nXRL d8  [        U[        R                  5      (       a;  UR                  UR                  L a!  U R	                  UUR                  5       USS9  g g g g )NFr  T)r!   	preloadedorm_descriptor_propsr   r  r   r   _get_class_attr_mror   r   InstrumentedAttribute_parententityparentConcreteInheritedProperty)r   r0  r1  r:  descriptor_propsimplementing_attributes         rm   r.   Mapper._adapt_inherited_property  s    >>>>}}$$SUe$L# &*%7%7%K%K&" &-*J,L,L  +88DKKG(($>>@"	 )  H $rl   )r:  r  warn_for_existingc                   [         R                  R                  nU R                  SXR                  R
                  5        [        U[        5      (       d  U R                  X5      nOUn[        U[        R                  5      (       Ga  U R                  R                  UR                  S   5      nUc  U R                  (       a  U /n	U R                  R                  5        H  n
U
R                   R                  UR                  S   5      nUbN  U	 H  nUR                  R#                  U5        M      U R                  R                  UR                  S   5      n  OU	R%                  U
5        M     Ucg  UR                  S   n['        U S5      (       aF  ['        US5      (       a  UR(                  U R*                  ;  a  U R,                  R/                  U5        Oo['        U S5      (       a^  UR(                  U R*                  ;   aD  XR*                  UR(                     ;  a(  U R*                  UR(                     R/                  U5        ['        US5      (       d4  XR0                  L =(       d    UR                  S   U R0                  L Ul        [        U[4        R6                  5      (       a  U=Ul        Ul        U R                  R/                  X5        UR                   H$  nUR<                   H  nXpR>                  U'   M     M&     [A        USU5      U:w  a[  [         RB                  " SU RD                  R
                   S	UR8                   S
U< SUR8                  < SUR8                  < S	35        Xl        U(       a  URG                  X5        XRH                  ;   a^  [A        U RH                  U   SS5      (       a?  U RH                  U   RJ                  n[L        RN                  " SU< SU< SU< SU< 35      eXRH                  ;   a  [        U RH                  U   URP                  5      (       d  [        XvRR                  5      (       dh  U(       a5  [         RT                  " SU RD                  R
                   S	U SU  S3S5        U RH                  U   nU RV                  RY                  US 5        OU(       a  U RD                  RZ                  R]                  US 5      b  [        XvRR                  5      (       dj  [        U RH                  R]                  US 5      URP                  5      (       d5  [         RT                  " SU RD                  R
                   S	U SU  S3S5        XpRH                  U'   U R^                  (       d  URa                  U 5        U Rb                   H  nURe                  XU5        M     U(       a!  URg                  5         URi                  U 5        U Rj                  (       a  U Rm                  5         U$ )Nz_configure_property(%s, %s)r   r|  r   r   _is_polymorphic_discriminatorr0  zORM mapped property r   z being assigned to attribute z& is already associated with attribute z+. The attribute will be de-associated from _mapped_by_synonymFz'Can't call map_column=True for synonym =z4, a ColumnProperty already exists keyed to the name z for column zUser-placed attribute z on z is replacing an existing ORM-mapped attribute.  Behavior is not fully defined in this case.  This use is deprecated and will raise an error in a future releasez2.0z is replacing an existing class-bound attribute of the same name.  Behavior is not fully defined in this case.  This use is deprecated and will raise an error in a future release)7r!   r  r  r   	__class__r   r   r+   _property_from_columnr    rR   r   rp  r   r   r  r}   _refresh_for_new_columnr  rL  r   r   r|  rx  r   r  r:   Labelr0  _tq_key_labelrt  r   r  r  r{   
set_parentr   r  r   r   r  rN   warn_deprecatedr   rZ  rY  r  rz   rE  r   r.  r:  post_instrument_classr   r   )r   r0  r  r:  r  r  r  r1  r}  pathmm2	proxy_colsynoldpropr   s                   rm   r  Mapper._configure_property(  s
     >>>>		)30B0B0K0K	
 (N33(,(B(B)D DdJ5566))>>t||AOC
 {t}}v668A--<<T\\!_MC"&B11II#N #'"55JJ LLO KKN 9 {ll1o 4!233W--yy(;(;;((,,T2 D"233		T%8%88#6#6syy#AA''		266s;
 4!@AA... >||A$*=*== 2
 #z//00 /21#+LLS&||!$I8<**95 "/ $ 4$+II&t{{';';&<AdhhZ H)' !XXL )|1	& OOD'++'KK2E#
 #
 ++c"55C&& '*3S:  ;;C "2"L"L  t%E%EFF $$,T[[-A-A,B!C5f 
  kk#&G##GT2 $$((d3?t%E%EFFT* :: 
   ()=)=(>auD&    C!!$'..F,,S= / IIK&&t,??%%'rl   c           
        [         R                  " U5      n/ nU H  nU R                  R                  U5      nUcz  U R                  R                  U5      nUb  U R                  R                  U5        U R                  R                  U5      nUc#  [        R                  " SU< SU < SU< S35      eUR                  U5        M     [        R                  " U6 $ )NzWhen configuring property '' on 
, 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.)r!   r   r   rp  r}   r  r   r   r  r    rR   )r   r0  r)  r   mapped_columnr   mcs          rm   r  Mapper._make_prop_from_column  s     ,,v&A((==a@Bz%%::1=>
 ++CCBG,,AA!D: ..
 ),T1	6    $' ( ((-88rl   c                   U(       a2  U R                   (       d  [        U[        R                  5      (       d  U$ UR                  S   nU(       a  XdR                  ;   a  U$ Uc  Uc   eUnUR                  S   U4nO$Ub   eUR                  S   nXrR                  S   4nU R
                  (       a  XR
                  ;  a  UR                  U5      (       dl  X`R                  La^  XpR                  LaP  SUR                  S   < SU< SU< S3n	U(       a  [        R                  " U	5        O[        R                  " U	5      eUR                  5       n
U
R                  R                  SU5        U R                  SU5        U
$ )Nr   z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 %s)r   r   r    rR   r   r   shares_lineager   r!   r  r   rC  copyinsertr   )r   r0  existing_propr  r  single_columnexisting_columnincoming_columnequated_pair_keymsgr  s              rm   r  ,Mapper._reconcile_prop_with_incoming_columns  sj    MMmZ-F-FGG  '//2_0E0EE    ,,,+O - 5 5a 8/J (((+33A6O /1F1Fq1IJ 00$,H,HH#22?CC':'::':':: "))"-#  		#0055
 !%%'?3		.	

 rl   c                   [         R                  R                  nU R                  R	                  U5      n[        U[        R                  5      (       a  U R                  UUUUR                  U LS9$ Ub  [        XCR                  5      (       a  U R                  X5      $ [        R                  " SU< SU < SUR                  < SU< S3	5      e)zjgenerate/update a :class:`.ColumnProperty` given a
:class:`_schema.Column` or other SQL expression object.)r  r  z$WARNING: when configuring property 'r  r  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!   r  r  r   r  r   r    rR   r  r  r  r  r   r   r0  )r   r0  r)  r  r1  s        rm   r  Mapper._property_from_column4	  s      >>>>{{s#dJ5566==$++T1	 >   \Z<<
 
 ..s;;&& *-dFJJF
 
rl   zThis warning originated from the `configure_mappers()` process, which was invoked automatically in response to a user-initiated operation.c                f    U R                   R                  (       a  [        U R                   1SS9  g g )NTcascade)rK   _new_mappers_configure_registriesr   s    rm   _check_configureMapper._check_configureY	  s&     ==%%!4==/4@ &rl   c                   U R                  S5        U R                  R                  5        VVs/ s H  u  pX4PM
     nnnU Hk  u  pU R                  SU5        UR                  U L a!  UR                  (       d  UR                  5         UR                  (       d  MZ  UR                  U 5        Mm     U R                  S5        SU l        gs  snnf )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,  r  _configure_startedr:  _configure_finishedr  r   )r   r0  r1  ls       rm   _post_configure_properties!Mapper._post_configure_propertiesc	  s     			89*.++*;*;*=>*=YSc[*=>ICII*C0{{d"4+B+B		'''**40  			9: ?s   Cc                X    UR                  5        H  u  p#U R                  X#5        M     g)zNAdd the given dictionary of properties to this mapper,
using `add_property`.

N)r,  add_property)r   dict_of_propertiesr0  values       rm   add_propertiesMapper.add_propertiesz	  s'    
 -224JCc) 5rl   c                    U R                  XU R                  SS9n[        U[        5      (       d   eX R                  U'   g)a  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.

T)r:  r  N)r  r   r   r+   r   )r   r0  r1  s      rm   r   Mapper.add_property	  sG     ''DOOt ( 
 $////%)c"rl   c                R    U R                  5        H  nUR                  5         M     g rh   )r  _reset_memoizationsr   r   s     rm   r   Mapper._expire_memoizations	  s!    **,F&&( -rl   c                   SU R                   R                  -   S-   U R                  S L=(       a    U R                  R                  =(       d    [	        U R                  5      -   U R
                  =(       a    S=(       d    S-   S-   $ )N(|z|non-primaryr  ))r{   r   r}   r  r!  rz   r   s    rm   	_log_descMapper._log_desc	  s     kk""#   , 1$$00)t''( 2N8b: 		
rl   c                `    U R                   R                  " SU-   /U R                  4U-   Q76   g Nz%s )loggerinfor  r   r  argss      rm   r   Mapper._log	  s)    B(9D(@Brl   c                `    U R                   R                  " SU-   /U R                  4U-   Q76   g r  )r  debugr  r  s      rm   
_log_debugMapper._log_debug	  s)    %#+C$..):T)ACrl   c                J    S[        U 5      U R                  R                  4-  $ )Nz<Mapper at 0x%x; %s>)idr{   r   r   s    rm   __repr__Mapper.__repr__	  s     %D4;;3G3G(HHHrl   c                    SU R                   R                  < U R                  =(       a    S=(       d    S< SU R                  b  U R                  R                  OU R
                  R                  < S3$ )Nr   z (non-primary)r  r  z)])r{   r   rz   r}   r  r   r   s    rm   __str__Mapper.__str__	  sc    KK  1!17R7 ##/   ,,,,889	
 	
rl   c                V   SnU R                  5        H  nUR                   Hm  u  pESn[        R                  " U5      R	                  XUR
                  S9nU R                  (       a
  U(       a      gU R                  (       a  Mc  U(       a  Ml      g   M     U R                  (       a  U$ g)NFT)
optimistic)r  r   r   manager_of_class
has_parenthas_identityr   )r   r  orphan_possibler   r0  clsr&  s          rm   
_is_orphanMapper._is_orphan	  s    **,F"22"&'88=HH5+=+= I 
 ((Z ...zz 3 -   ""rl   c                    XR                   ;   $ rh   )r   )r   r0  s     rm   has_propertyMapper.has_property	  s    kk!!rl   c                    U(       a  U R                  5          U R                  U   $ ! [         a#  n[        R                  " SU  SU S35      UeSnAff = f)z6return a MapperProperty associated with the given key.zMapper 'z' has no property 'zw'.  If this property was indicated from other mappers or configure events, ensure registry.configure() has been called.N)r  r   r^  r   rC  )r   r0  _configure_mappersr`  s       rm   get_propertyMapper.get_property	  sg    
 !!#	;;s## 	,,4& 3C5 98 8 		s   ( 
AAAc                     U R                   U   $ )zcGiven a :class:`_schema.Column` object, return the
:class:`.MapperProperty` which maps this column.)r   )r   r)  s     rm   get_property_by_columnMapper.get_property_by_column	  s     %%f--rl   c                H    [        U R                  R                  5       5      $ )z1return an iterator of all MapperProperty objects.)iterr   r  r   s    rm   iterate_propertiesMapper.iterate_properties	  s     DKK&&())rl   c                h   US:X  a  [        U R                  5      nOU(       a  [        5       n[        R                  " U5       Hv  n[        U5      nUR                  U 5      (       d  [        R                  " U< SU < 35      eUc!  UR                  UR                  5       5        Me  UR                  U5        Mx     U R                   Vs/ s H  oUU;   d  M
  UPM     nnO/ nUbA  [        [        R                  " USS95      nU Vs/ s H  oUR                  U;   d  M  UPM     nnU$ s  snf s  snf )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.

rd   z does not inherit from T)include_aliases)r   r+  rj   r!   r   r#   isar   rC  r*  r  rx  r  rr  r}   )r   spec
selectablemappers
mapper_setr  r   s          rm   _mappers_from_specMapper._mappers_from_spec	  s    3;4445GJ\\$'$Q'uuT{{ 449:DA  %%%a&7&7&9:NN1% ( #'";";O";QJq";GOGG!$$ZFF #*E'Q]]f-Dq'GE P Fs   	D*D*	D/ D/c                Z   U R                   nU H  nX@L a  M	  UR                  (       a  [        R                  " S5      eUR                  (       a  MC  U(       a(  UR                  UR                  UR                  5      nMr  UR                  UR                  UR                  5      nM     U$ )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   r   r   rC  r   r  r}   r   	outerjoin)r   r?  	innerjoinfrom_objr  s        rm   _selectable_from_mappersMapper._selectable_from_mappers
  s     **Ayzz00A  XXX'}}q':': H  (11q':': H $ rl   c                   U R                   nUc  g[        U[        5      (       d  gUR                  S L=(       dR    UR                  S L=(       a=    UR                  R
                  (       + =(       a    UR                  R                  (       + $ NFT)r   r   rA   server_defaultdefault	is_scalaris_callable)r   vid_cols     rm   !_version_id_has_server_side_value(Mapper._version_id_has_server_side_value1
  ss    %%?GV,,))5 t+ 111 8#OO777	rl   c                4   U R                   (       a  U R                  (       aq  U R                  bd  U R                  R                  X S.5      R	                  U R
                   Vs/ s H"  nUR                  (       a  M  UR                  PM$     sn5      $ g s  snf )N)parententityparentmapper)r   r   r   	_annotatein_r+  r   r   r   r  s     rm   _single_table_criterionMapper._single_table_criterionC
  s    ;;4==T-@-@-L&&00!%<c "66611 +A**6 s   $B=Bc                v    U R                   =(       a'    [        U R                   S   [        R                  5      $ )zreturn True if with_polymorphic[1] is an aliased fromclause,
like a subquery.

As of #8168, polymorphic adaption with ORMAdapter is used only
if this is present.

r   )r   r   r:   AliasedReturnsRowsr   s    rm   #_has_aliased_polymorphic_fromclause*Mapper._has_aliased_polymorphic_fromclauseR
  s5     $$ 
!!!$))*
 	
rl   c                    U R                   =(       dF    U R                  =(       d3    U R                  R                   =(       d    U R                  R                  $ )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\  r   r   r   s    rm    _should_select_with_poly_adapter'Mapper._should_select_with_poly_adapter`
  sK    V 44 7**7  DD7 66		
rl   c                z    U R                  5         U R                  (       d  / $ U R                  " U R                  6 $ rh   )r  r   rA  r   s    rm   _with_polymorphic_mappers Mapper._with_polymorphic_mappers
  s3    $$I&&(=(=>>rl   c                $    U R                  5         g)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)r  r   s    rm   _post_inspectMapper._post_inspect
  s     	rl   c                    U R                   (       d  U R                  $ U R                   u  pUb  U$ U R                  U R                  X5      S5      $ NF)r   r   rG  rA  )r   r=  r>  s      rm   _with_polymorphic_selectable#Mapper._with_polymorphic_selectable
  sT    $$***00!00''95 rl   c           	         U R                   R                  5        VVs0 s H  u  pU[        S U 5       5      _M     snn$ s  snnf )Nc              3  ^   #    U  H#  oR                   R                  (       d  M  Uv   M%     g 7frh   )r   should_evaluate_nonerg  r}  s     rm   ri  6Mapper._insert_cols_evaluating_none.<locals>.<genexpr>
  s      &((*G*Gws   -	-r   r,  r  r   r   r   s      rm   _insert_cols_evaluating_none#Mapper._insert_cols_evaluating_none
  sW     #'"5"5";";"=	
 #> 9 &   #>	
 	
 
   Ac           	         U R                   R                  5        VVs0 s H  u  pU[        S U 5       5      _M     snn$ s  snnf )Nc              3     #    U  Hg  nUR                   (       a  M  UR                  (       a  M)  UR                  (       a  M<  UR                  R                  (       a  MY  UR
                  v   Mi     g 7frh   )r~   rK  rL  r   rm  r0  rn  s     rm   ri  .Mapper._insert_cols_as_none.<locals>.<genexpr>
  sV      "C  **  	 
 55 "s   A1A1A1A1A1rp  rq  s      rm   _insert_cols_as_noneMapper._insert_cols_as_none
  sW     #'"5"5";";"=

 #> 9 "   #>

 
	
 

rt  c                    U R                   R                  5        VVVs0 s H/  u  pX Vs0 s H  o0R                  U   R                  U_M     sn_M1     snnn$ s  snf s  snnnf rh   )r   r,  r   r0  r   r   r   r}  s       rm   _propkey_to_colMapper._propkey_to_col
  se     #'"5"5";";"=
"= GLGS**3/33S8GLL"=
 	
L
s   A#AAAc                    U R                   R                  5        VVVs0 s H+  u  pU[        U Vs/ s H  o3R                  PM     sn5      _M-     snnn$ s  snf s  snnnf rh   )r   r,  r  r0  r   r   pksr}  s       rm   _pk_keys_by_tableMapper._pk_keys_by_table
  sX     #00668
8
 95#gg5668
 	
5
s   AAAAc                    U R                   R                  5        VVVs0 s H8  u  pU[        U Vs/ s H  o0R                  U   R                  PM     sn5      _M:     snnn$ s  snf s  snnnf rh   )r   r,  r  r   r0  r  s       rm   _pk_attr_keys_by_tableMapper._pk_attr_keys_by_table
  se     #00668
8
 9M#44S9==MNN8
 	
M
s   A("A#A(#A(c                8   U R                   R                  5        VVVs0 s He  u  pU[        [        SU5       Vs/ s H>  nUR                  c,  UR
                  c  M  UR
                  R                  (       d  M<  UPM@     sn5      _Mg     snnn$ s  snf s  snnnf NzIterable[Column[Any]])r   r,  r  r	   rK  rL  is_clause_elementr{  s       rm   _server_default_colsMapper._server_default_cols
  s      #'"5"5";";"=
 #> 9  $$;WEE))5	 
  KK99 E
 
 #>
 	

"   BBB:B BBc                8   U R                   R                  5        VVVs0 s He  u  pU[        [        SU5       Vs/ s H>  nUR                  c,  UR
                  c  M  UR
                  R                  (       d  M<  UPM@     sn5      _Mg     snnn$ s  snf s  snnnf r  )r   r,  r  r	   server_onupdateonupdater  r{  s       rm   _server_onupdate_default_cols$Mapper._server_onupdate_default_cols
  s      #'"5"5";";"=
 #> 9  $$;WEE**6	 
  LL:: E
 
 #>
 	

r  c           	         U R                   R                  5        VVs0 s H  u  pU[        S U 5       5      _M     snn$ s  snnf )Nc              3  V   #    U  H  oR                   c  M  UR                   v   M!     g 7frh   r0  rn  s     rm   ri  2Mapper._server_default_col_keys.<locals>.<genexpr>       LWSWW   )))r  r,  r  r   r   colss      rm   r   Mapper._server_default_col_keys  sJ      $88>>@
@ 9LLLL@
 	
 
rt  c           	         U R                   R                  5        VVs0 s H  u  pU[        S U 5       5      _M     snn$ s  snnf )Nc              3  V   #    U  H  oR                   c  M  UR                   v   M!     g 7frh   r  rn  s     rm   ri  ;Mapper._server_onupdate_default_col_keys.<locals>.<genexpr>  r  r  )r  r,  r  r  s      rm   !_server_onupdate_default_col_keys(Mapper._server_onupdate_default_col_keys  sJ      $AAGGI
I 9LLLLI
 	
 
rt  c                h  ^ [        5       nU R                  mU R                  R                  5        H/  u  p#UR	                  U4S jUR                  T5       5       5        M1     U R                  R                  5        H/  u  p#UR	                  U4S jUR                  T5       5       5        M1     U$ )Nc              3  B   >#    U  H  nTU   R                   v   M     g 7frh   r  rg  r}  col_to_propertys     rm   ri  @Mapper._server_default_plus_onupdate_propkeys.<locals>.<genexpr>!  #      @C  $((@   c              3  B   >#    U  H  nTU   R                   v   M     g 7frh   r  r  s     rm   ri  r  &  r  r  )rj   r   r  r,  r*  rw  r  )r   resultr   r   r  s       @rm   &_server_default_plus_onupdate_propkeys-Mapper._server_default_plus_onupdate_propkeys  s    500"77==?NEMM "//@  @
 #@@FFHNEMM "//@  I
 rl   c                   U U U S.nU R                   U R                  La4  U R                  R                  U U U S.5      R                  SU S.5      US'   U R                  R                  U5      R                  SU S.5      $ )N)entity_namespacerS  rT  ormcompile_state_pluginplugin_subject	dml_table)r   r}   rU  _set_propagate_attrsr>  )r   r   s     rm   __clause_element__Mapper.__clause_element__,  s     !%  '

 ""$*:*:: (,'7'7'A'A(,$($(( #").$G $ ((5JJ%*dC
 	
rl   c                x    [         R                  " 5       R                  U U U SS.5      R                  SU S.5      $ )NT)r  rS  rT  identity_tokenr  r  )r:   nullrU  r  r   s    rm   select_identity_tokenMapper.select_identity_tokenD  sC     OOY(,$($(&*	 "!).$G	
rl   c                    U R                   $ )a  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.

)ri  r   s    rm   r>  Mapper.selectableU  s     000rl   c                .   US;  a$  [         R                  " [        R                  USS9nU R                  (       a+  U(       d  U R                  S   nUSL a  U R                  S   nOUSL a  S nU R                  X5      nUb  XB4$ X@R                  XC5      4$ )Nrh  Tr  r   Fr   )r9   r   r<   r   r   rA  rG  )r   r=  r>  rE  r?  s        rm   _with_polymorphic_argsMapper._with_polymorphic_argsa  s     ]*"))**JTJ   ,,Q/U"!2215
5 J))$;!&&99'MMMrl   c                J    [        U R                  U R                  5      5      $ rh   )r   _iterate_polymorphic_propertiesrb  r   s    rm   _polymorphic_propertiesMapper._polymorphic_propertiesy  s&    00..
 	
rl   c                $   U R                   nU R                  nU VVs/ s Hc  n[        U[        R                  5      (       d  M$  UR
                  (       d  M7  UR                    H  nU(       a  UR                  U   OUPM     Me     snn$ s  snnf rh   )r  _polymorphic_adapterr   r    rR   _renders_in_subqueriesr   )r   poly_propertiesadapterr1  r   s        rm   _all_column_expressionsMapper._all_column_expressions  s    66++ (
'$
 9 9: 1 ++ 1 \\	 #*GOOAq0 "	 1'
 	
 
s   #BB0Bc                    U(       a  U R                  U5      nOU R                  nU Vs/ s H?  n[        U[        R                  5      (       d  M$  UR
                  UR                  S   4PMA     sn$ s  snf )Nr   )r  r  r   r    rR   r0  r   )r   polymorphic_mappersr  r1  s       rm   _columns_plus_keysMapper._columns_plus_keys  so    "BB#O #::O (
'$
 9 9: (TXXt||A''
 	
 
s   #A3A3c                    U R                   (       aD  [        R                  " [        R                  R                  U U R
                  U R                  SS9$ g )NF)r>  equivalentslimit_on_entity)r\  orm_utilrU   _TraceAdaptRoleMAPPER_POLYMORPHIC_ADAPTERr>  _equivalent_columnsr   s    rm   r  Mapper._polymorphic_adapter  sH    33&&((CC?? 44 %  rl   c           
   #    #    Uc  U R                   nU(       d  U R                   H  nUv   M	     g[        R                  " [	        U /U-    Vs/ s H  n[        UR                  5      PM     sn6 5       HD  n[        USS5      (       a+  U R                  b  UR                  S   U R                  La  M@  Uv   MF     gs  snf 7f)zMReturn an iterator of MapperProperty objects which will render into
a SELECT.Nr  Fr   )	rb  r8  r!   unique_listr   r   r  r   r   )r   r?  r   r   s       rm   r  &Mapper._iterate_polymorphic_properties  s      ?44G,, - %% (,fw&6&6F V667&6 1=uEE''/yy|4+>+>>s   ACB>-ACc                b    U R                  5         [        R                  " U R                  5      $ )a  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`

)r  r!   ReadOnlyPropertiesr   r   s    rm   attrsMapper.attrs  s&    F 	&&t{{33rl   c                p    [         R                  " [        U R                  R	                  5       5      5      $ )a	  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   r   _all_sqla_attributesr   s    rm   all_orm_descriptorsMapper.all_orm_descriptors  s/    D &&##88:;
 	
rl   c                z   [         R                  R                  nU R                   Vs1 s H  o"R                  iM     nnU R
                  R                  5        VVs0 s HJ  u  pE[        XQR                  5      (       d  M!  UR                  U;   d  M3  UR                  UR                  _ML     snn$ s  snf s  snnf )znreturn a dictionary of {syn_attribute_name: pk_attr_name} for
all synonyms that refer to primary key columns

)
r!   r  r  r{  r0  r   r,  r   rN   rT  )r   r  r1  pk_keysr  r  s         rm   _pk_synonymsMapper._pk_synonyms1  s      >>>>(,(@(@A(@88(@A ++++-
-#??@  G# CGGSXX-
 	
 B
s   B2 B7B7B7c                l    [         R                  R                  nU R                  UR                  5      $ )zReturn a namespace of all :class:`.Synonym`
properties maintained by this :class:`_orm.Mapper`.

.. seealso::

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

)r!   r  r  _filter_propertiesrN   )r   r  s     rm   synonymsMapper.synonymsC  s,      >>>>&&'7'G'GHHrl   c                    U R                   $ rh   r   r   s    rm   r  Mapper.entity_namespaceT  s    {{rl   c                @    U R                  [        R                  5      $ )zReturn 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    rR   r   s    rm   column_attrsMapper.column_attrsX  s     &&z'@'@AArl   zsqlalchemy.orm.relationshipsc                h    U R                  [        R                  R                  R                  5      $ )a  A namespace of all :class:`.Relationship` 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!   r  orm_relationshipsrS   r   s    rm   relationshipsMapper.relationshipsf  s*    6 &&NN,,AA
 	
rl   c                h    U R                  [        R                  R                  R                  5      $ )zReturn a namespace of all :class:`.Composite`
properties maintained by this :class:`_orm.Mapper`.

.. seealso::

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

)r  r!   r  r  rM   r   s    rm   
compositesMapper.composites  s*     &&NN//AA
 	
rl   c                   ^ U R                  5         [        R                  " [        R                  " U4S jU R                  R                  5        5       5      5      $ )Nc              3  T   >#    U  H  u  p[        UT5      (       d  M  X4v   M     g 7frh   )r   )rg  r  vtype_s      rm   ri  ,Mapper._filter_properties.<locals>.<genexpr>  s$      #641*Q:N#6s   (
()r  r!   r  r  r   r,  )r   r  s    `rm   r  Mapper._filter_properties  sL     	&& #';;#4#4#6 
 	
rl   c           
     2   [        U R                  S5       VVs/ s H)  u  pU[        R                  " SU-  UR                  S94PM+     nnn[        R
                  " U VVs/ s H	  u  pEXE:H  PM     snn6 [        R                  " U5      4$ s  snnf s  snnf )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~   r5   	bindparamr   and_r!   column_dict)r   idxr~   paramsr  r  s         rm   _get_clauseMapper._get_clause  s     %.d.>.>$B

 %C  gm;3C3CD %C 	 
 HHF3F&1qvF34V$
 	

 4s   0B"B
c                   ^ 0 mU4S jnU R                   R                   H6  nUR                  c  M  [        R                  " UR                  0 SU05        M8     T$ )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                  > U R                   [        R                  :X  a  U R                  T;   a)  TU R                     R	                  U R
                  5        OU R
                  1TU R                  '   U R
                  T;   a)  TU R
                     R	                  U R                  5        g U R                  1TU R
                  '   g g rh   )operatorr;   eqleftrx  right)binaryr  s    rm   visit_binary0Mapper._equivalent_columns.<locals>.visit_binary  s    ),,.;;&(6;;'++FLL9+1<<.F6;;'<<6)6<<(,,V[[9,2KK=F6<<( /rl   r
  )r   r+  r   r>   traverse)r   r  r   r  s      @rm   r  Mapper._equivalent_columns  sZ      (*		9 &&;;F''3!!,,b8\2J < rl   c                    [        U[        [        R                  [        R
                  45      (       a  gXR                  ;  $ rh  )r   r(   r   rP   r:   r\   _dataclass_fields)r   assigned_nameobjs      rm   _is_userland_descriptorMapper._is_userland_descriptor  s@     ,,((
 
  (>(>>>rl   c                    [         R                  " U R                  5       Vs/ s H  oR                  PM     sn$ s  snf rh   )r!   dataclass_fieldsr{   rT  )r   fs     rm   r  Mapper._dataclass_fields  s-     $ 5 5dkk BC B1 BCCCs   ;c                v   Ub  [         R                  " U5      (       a  gU(       aW  U R                  R                  R	                  US5       b.  U R                  X R                  R                  U   5      (       a  gO6U R                  R                  US5      nUb  U R                  X%5      (       a  gU R                  b6  XR                  ;  a'  Ub  X@R                  ;  a  U R                  SU-  5        gU R                  b6  XR                  ;   d  Ub$  X@R                  ;   a  U R                  SU-  5        gg)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  _never_select_columnr{   rY  r  r  r   r  r   r   r   )r   rT  r  r(  r)  attrs         rm   r-  Mapper._should_exclude  s*    ("?"?"G"G
 {{##''t"::{{33MB  %%99-NDD$@$@% %  ##/33361H1H#HII1T:;"".+++"v1H1H'HII-67rl   c                2    U R                   UR                   L $ )zPReturn true if the given mapper shares a
common inherited parent as this mapper.)r   r   others     rm   common_parentMapper.common_parent  s     5#4#444rl   c                    U R                   UR                   L =(       a3    U R                  U5      (       + =(       a    UR                  U 5      (       + $ )zkreturn true if the other mapper is an inheriting sibling to this
one.  common parent but different branch

)r   r<  r  s     rm   
is_siblingMapper.is_sibling  sC      1 11 $HHUO#$IIdO#	
rl   c                    U R                  5       nU R                  c  U(       a  [        U5      R                  U5      $ [        U5      UL $ rh   )primary_mapperr   r%   r<  )r   r  allow_subtypesss       rm   _canloadMapper._canload(  sF     !*n '++A.. '1,,rl   c                d    U nU(       a  X!La  UR                   nU(       a  X!La  M  [        U5      $ )z>Return True if the this mapper inherits from the given mapper.)r   r   )r   r  r  s      rm   r<  
Mapper.isa1  s+     $(AN

A ANAwrl   c              #  R   #    U nU(       a  Uv   UR                   nU(       a  M  g g 7frh   )r   rW  s     rm   r  Mapper.iterate_to_root9  s"     #'G

A as   !''c                    / n[        U /5      nU(       aE  UR                  5       nUR                  U5        UR                  UR                  5        U(       a  ME  [
        R                  " U5      $ )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   descendantsr  r  s       rm   r+  Mapper.self_and_descendants?  s\     tf==?Dt$LL112 e   --rl   c                ,    [        U R                  5      $ )a  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()``.

)r7  r+  r   s    rm   polymorphic_iteratorMapper.polymorphic_iteratorO  s     D--..rl   c                .    U R                   R                  $ )zKReturn the primary mapper corresponding to this mapper's class key
(class).)r   r   r   s    rm   r&  Mapper.primary_mapper\  s     !!(((rl   c                B    U R                   R                  R                  $ rh   )r   r   r   r   s    rm   primary_base_mapperMapper.primary_base_mapperb  s    !!((444rl   c                    U R                   nU(       a  U Vs/ s H  oBR                  U   PM     nnUR                  5       nU H
  nXe;  d  M
    g   gs  snf rJ  )r~   r   keys)r   r  r  r  r   rkr}  s          rm   _result_has_identity_keyMapper._result_has_identity_keyf  sR    /3/?/?3:;7aq)7G;[[]C}   <s   Ac                   ^ U R                   nU(       a  U Vs/ s H  oSR                  U   PM     nn[        US5      (       a  UR                  mOUmU R                  [        U4S jU 5       5      U4$ s  snf )aM  Return an identity-map key for use in storing/retrieving an
item from the identity map.

:param row: A :class:`.Row` or :class:`.RowMapping` produced from a
 result set that selected from the ORM mapped primary key columns.

 .. versionchanged:: 2.0
    :class:`.Row` or :class:`.RowMapping` are accepted
    for the "row" argument

_mappingc              3  .   >#    U  H
  nTU   v   M     g 7frh   rk   )rg  r)  mappings     rm   ri  /Mapper.identity_key_from_row.<locals>.<genexpr>  s     8f'&/s   )r~   r   rL  r@  r   r  )r   rowr  r  r  r   rB  s         @rm   identity_key_from_rowMapper.identity_key_from_rowq  sv    " 04/?/?3:;7aq)7G; 3
##llGG   888
 	
 <s   A5c                2    U R                   [        U5      U4$ )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      rm   identity_key_from_primary_key$Mapper.identity_key_from_primary_key  s"       +
 	
rl   c                n    [         R                  " U5      nU R                  U[        R                  5      $ )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_stater&   PASSIVE_OFF)r   instancer  s      rm   identity_key_from_instance!Mapper.identity_key_from_instance  s-     ))(3,,UK4K4KLLrl   c                   UR                   nUR                  nU R                  [        U R                   Vs/ s H+  nXER
                     R                  R                  XU5      PM-     sn5      UR                  4$ s  snf rh   )	r   rQ  r   r  r{  r0  implr  r  )r   r  passiver  rQ  r1  s         rm   rM  Mapper._identity_key_from_state  s~    
 

--   !% 8 8 8 HH%**..uWE 8   	
 		
s   2A<
c                x    [         R                  " U5      nU R                  U[        R                  5      nUS   $ )a  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   rK  )r   rO  r  identity_keys       rm   primary_key_from_instance Mapper.primary_key_from_instance  s;     ))(344;**
 Arl   c                   ^ U R                    Vs/ s H  oR                  R                  PM     snm[        T5      R	                  S /5      (       a  U4S jnU$ S nU$ s  snf )Nc                V   > [        S [        TU R                  S   5       5       5      $ )Nc              3  @   #    U  H  u  pUb  U" U5      OUv   M     g 7frh   rk   )rg  key_fnvals      rm   ri  =Mapper._persistent_sortkey_fn.<locals>.key.<locals>.<genexpr>  s'      'A $*#5F3K3>'As   r   )r  zipr0  )r  key_fnss    rm   r0  *Mapper._persistent_sortkey_fn.<locals>.key  s,     '*7EIIaL'A  rl   c                     U R                   S   $ Nr   r  )r  s    rm   r0  rb    s    yy|#rl   )r~   r   sort_key_functionrj   
difference)r   r}  r0  ra  s      @rm   _persistent_sortkey_fnMapper._persistent_sortkey_fn  s\    9=9I9IJ9I#88--9IJw<""D6** 
$ 
 Ks   Ac                ^    U R                    Vs/ s H  oR                  U   PM     sn$ s  snf rh   )r~   r   r   r}  s     rm   r{  Mapper._identity_key_props  s+    7;7G7GH7G&&s+7GHHHs   *c                |    [        5       nU R                   H!  nUR                  U R                  U   5        M#     U$ rh   )rj   r   r*  r   )r   
collectionr   s      rm   _all_pk_colsMapper._all_pk_cols  s6    -0U
[[Ed0078 !rl   c                    [        U R                  5      nU R                  b  UR                  U R                  5        U$ rh   )rj   r~   r   rx  )r   r  s     rm   _should_undefer_in_wildcard"Mapper._should_undefer_in_wildcard  s5    (+D,<,<(=*HHT(()rl   c                r    U R                    Vs1 s H  oR                  U   R                  iM     sn$ s  snf rh   )rn  r   r0  rj  s     rm   _primary_key_propkeysMapper._primary_key_propkeys  s1    ;?;L;LM;LC&&s+//;LMMMs   "4c                    U R                   U   nUR                  UR                     R                  R	                  XUS9$ NrT  )r   rQ  r0  rS  r  r   r  r  r)  rT  r1  s         rm   _get_state_attr_by_column Mapper._get_state_attr_by_column  s=     %%f-}}TXX&++//g/NNrl   c                    U R                   U   nUR                  UR                     R                  R	                  XU5        g rh   )r   rQ  r0  rS  set_committed_valuer   r  r  r)  r  r1  s         rm   #_set_committed_state_attr_by_column*Mapper._set_committed_state_attr_by_column  s5    %%f-dhh$$88uMrl   c                    U R                   U   nUR                  UR                     R                  R	                  XUS 5        g rh   )r   rQ  r0  rS  rj   r~  s         rm   _set_state_attr_by_column Mapper._set_state_attr_by_column  s7    %%f-dhh$$((udCrl   c                    [         R                  " U5      n[         R                  " U5      nU R                  X4U[        R
                  S9$ rw  )r   rL  instance_dict#_get_committed_state_attr_by_columnr&   rN  )r   r  r)  r  r  s        rm   _get_committed_attr_by_column$Mapper._get_committed_attr_by_column  sG    ))#.((-77&+*A*A 8 
 	
rl   c                    U R                   U   nUR                  UR                     R                  R	                  XUS9$ rw  )r   rQ  r0  rS  get_committed_valuery  s         rm   r  *Mapper._get_committed_state_attr_by_column  sE     %%f-}}TXX&++??' @ 
 	
rl   c                  ^ ^^ T R                   n[        U5      R                  TR                  R                  R                  5       5      n[        [        U VVs/ s H.  nX5   R                    H  n[        R                  " USS9PM     M0     snn6 5      mT R                  R                  T;   a  gU UU4S jn/ nSn	[        [        T R                  5       5      5       H  n
U
R                  T;   a  Sn	O+[        U
R                  [         R"                  5      (       d    gU	(       d  MJ  U
R$                  (       a  M]  U
R&                  (       d   eU
R(                  (       a   eU
R*                  c   eUR-                  U
R*                  5        TR/                  U
R                  5        M      [0        R2                  " US   0 SU05      nXS'   [6        R8                  " U6 n/ nU H   nUR;                  X5   R                  5        M"     [6        R<                  " U6 R?                  U5      RA                  [B        5      $ s  snnf ! [4         a     gf = f)a<  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                `  > U R                   nU R                  nUb  Uc  g UR                  T;  aw  TR                  TTR                  U[
        R                  S9nU[        R                  ;   a
  [        5       e[        R                  " S X0R                  R                  S9U l         g UR                  T;  aw  TR                  TTR                  U[
        R                  S9nU[        R                  ;   a
  [        5       e[        R                  " S X@R                  R                  S9U l        g g )Nrx  r  )r  r	  r   r  r   r&   PASSIVE_NO_INITIALIZEr  	_none_set_OptGetColumnsNotAvailabler5   r  r   )r
  leftcolrightcolleftvalrightvalr   r  r   s        rm   r  5Mapper._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"}}(,,*;*;  .rl   Fr   r
  )"r   rj   rw  r   r  r;  r   r   r  rr  r   r}   reversedr   r  r   r:   r=   r   r   r   r   r  rx  r>   cloned_traverser  r5   r  r  selectwhereset_label_stylerC   )r   r  attribute_namespropscol_attribute_namesr0  r   r  allcondsstartr   
_traversedcondr  r   s   ``            @rm   _optimized_get_statementMapper._optimized_get_statement  s    !/2??LL%%**,
 #&  32"Z// (($?/ @2#
 ''61	> /1
 tD$8$8$:;<F!!V+ 2 2J4J4JKKuV]]]&!??**//;;; 8 89

6--. = 	%!11R(L!9J %QKxx"&CKK
**+ ' JJU4[_;<	
_J * 		s   5I /I 
IIc              #     #    U R                  U5      (       a;  U nU R                  5        H$  nUv   X2La  X#R                  ;  a    g UnX1L d  M$    g    g g 7frh   )r<  r  rb  )r   r   prevr  s       rm   _iterate_to_target_viawpoly"Mapper._iterate_to_target_viawpoly  sV     88FD))+=T1L1L%L; , s   A	AAc                    0 $ rh   rk   r   s    rm   &_would_selectinload_combinations_cache-Mapper._would_selectinload_combinations_cache  s    	rl   c                    U R                   n X!   $ ! [         a     Of = fU R                  U5      (       d   eUnU R                  U5       H  nUR                  S:X  d  M  XAL n  O   SnXRU'   U$ )a&  return True if this mapper would "selectin" polymorphic load based
on the given super mapper, and not from a setting from a subclass.

given::

    class A: ...


    class B(A):
        __mapper_args__ = {"polymorphic_load": "selectin"}


    class C(B): ...


    class D(B):
        __mapper_args__ = {"polymorphic_load": "selectin"}

``inspect(C)._would_selectin_load_only_from_given_mapper(inspect(B))``
returns True, because C does selectin loading because of B's setting.

OTOH, ``inspect(D)
._would_selectin_load_only_from_given_mapper(inspect(B))``
returns False, because D does selectin loading because of its own
setting; when we are doing a selectin poly load from B, we want to
filter out D because it would already have its own selectin poly load
set up separately.

Added as part of #9373.

r  F)r  r^  r<  r  r   )r   super_mappercacher   r  retvals         rm   +_would_selectin_load_only_from_given_mapper2Mapper._would_selectin_load_only_from_given_mapper  s    @ ;;	&& 		 xx%%%%11&9A!!Z/* :
 F$ls    
c                   U(       d/  UnU R                  U5       H  nUR                  S:X  d  M  Us  $    g [        U5      nU Vs0 s H  oUR                  U_M     nnUR	                  U/5       HQ  nUR                  nU R                  U5       H-  nUR                  S:X  d  XF;   d  M  UR                  XD5      s  s  $    MS     g s  snf )Nr  )r  r   rj   r   rP  r  )r   enabled_via_optpolymorphic_fromr   r  eenabled_via_opt_mappersr   s           rm   _should_selectin_loadMapper._should_selectin_load  s    %F55f=%%3H >   "/2O<K&LOqxx{O#&L)//1A0BC99&AA**j876::1@@ B D  'Ms   Czsqlalchemy.orm.strategy_optionsc           	        [         R                  R                  nU R                  (       d   eU R                  b3  U R
                  U R                     n[        U/U R                  -   5      nO[        U R                  5      nUR                  U5      nUR                  U5      nU 1nU R                  n	U	bJ  XLaF  U	R                  S:X  a6  UR                  U	5        U	R                  n	U	b  XLa  U	R                  S:X  a  M6  U R                  U R                  -    H  n
U
R                  U R                  ;  a  M  U
R                  U;   d  X;   a\  [!        U
["        5      (       d  MK  UR%                  ['        UR(                  U
R                  5      4[+        U
R,                  5      SS9nM  UR%                  ['        UR(                  U
R                  5      4SS0SS9nM     U R.                   Vs/ s H  n[0        R2                  " USS05      PM     nn[5        U5      S:  a  [6        R8                  " U6 nOUS   nUR:                  (       a  UR<                  U L d   e[6        R>                  " U5      RA                  [B        5      nURD                  RG                  U5      nU Vs/ s H  oRD                  RG                  U5      PM     nnURI                  URK                  [6        RL                  " S	SS
95      5      RN                  " U6 nOi[6        R>                  " U 5      RA                  [B        5      nURI                  URK                  [6        RL                  " S	SS
95      5      RN                  " U6 nXU4$ s  snf s  snf )zRAssemble a that can load the columns local to
this subclass as a SELECT with IN.

r  T)_reconcile_to_other
do_nothingF
_orm_adaptr   r   primary_keys)	expanding)(r!   r  orm_strategy_optionsr   r   r   rj   r{  Loadr   rx  r  r  r0  r   r  r   r.   _set_generic_strategyr  r  r   strategy_keyr~   r  _deep_annotatery  r5   tuple_is_aliased_classr   r  r  rC   _adapterr  r  rV  r  order_by)r   r   r  strategy_optionspolymorphic_prop
keep_propsdisable_opt
enable_optclasses_to_includer  r1  pkr~   in_exprqr  s                   rm   _subclass_load_via_inMapper._subclass_load_via_in  s2     >>>>}}}*#55d6I6IJ./$2J2JJKJT556J&++F3%**62
"V#'==M)""j0""1%

A M)""j0
 %%(:(::D xxt111{{00D4F "$(;<<'== V44dhh?A**+(, > 
 *?? V44dhh?A!4((- @ 3 ;H &&
& ##Bt(<=& 	 
 {ajj+.G!!nG""==D(((

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

4 00.A CMM.DIJh#%A k))A
( Ms   .#M9%$M>c                8    U R                  X R                  5      $ rh   )r  r   r   s    rm   _subclass_load_via_in_mapper#Mapper._subclass_load_via_in_mapperF  s     ))$0@0@AArl   c           	   #    #    [        5       n[        5       [        5       peUR                  R                  U 5      (       d   e[	        [	        UR                  R
                  R                  5       5      XRUR                  4/5      nU(       a  US   u  ppU(       d  UR                  5         M(  XL av  UR                  5       nUR                  (       a  XR                  ;  a  M^  U
c   eUc   e[	        UR                  UU
UUU5      5      nU(       a  UR                  XSS45        OWXL aS  UR                  5       u  nnnnUUUU4v   UR                  [	        UR
                  R                  5       5      UUU45        U(       a  M  gg7f)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.

r  N)rj   objectr   r<  r   r   r  r   rZ  r  r  cascade_iteratorr  )r   r  r  halt_onvisited_statesprpmpp
visitablesiterator	item_typeparent_stateparent_dictr1  queuerO  instance_mappercorresponding_statecorresponding_dicts                     rm   r  Mapper.cascade_iteratorK  s    @ 36%8VXS||%%%% ELL''..013uzzJK

 =G^:H '')||uLL'@#///"...))$#& %%u4&>?! $$&#'& #'&	  !!o44;;=>+*	I js   FF
F
c                B    [         R                  " U R                  5      $ rh   )r!   LRUCacher   r   s    rm   _compiled_cacheMapper._compiled_cache  s    }}T6677rl   c                2    [        U R                  5      S:  $ rd  )ry  r   r   s    rm   _multiple_persistence_tables#Mapper._multiple_persistence_tables  s    4;;!##rl   c                  ^
 0 m
U R                   R                   H'  nUR                   H  nT
R                  X!5        M     M)     / nT
R	                  5        HG  u  pAUR
                  nU(       d  M  UR                  UR                   Vs/ s H  ofU4PM     sn5        MI     U
4S jn[        R                  " T
UUS9n[        R                  " 5       n	U H
  nT
U   X'   M     U	$ s  snf )Nc                  > TR                  U R                  R                  5      nTR                  U R                  R                  5      nUb  Ub  X!La  UR                  b  [        [        R                  " UR                  5      5      nUR                  bT  UR                  [        R                  " UR                  5      5      nU R                  U;  =(       a    U R                  U;  $ U R                  U;  $ grh  )	r  r  r   r)  r   rj   r  _find_columnsrP  )fkr  depr  table_to_mappers       rm   skip#Mapper._sorted_tables.<locals>.skip  s     %((9F!%%biioo6C"O%))5811#2G2GHI++7:: ..v/G/GHD 99D0JRYYd5JJ99D00rl   )skip_fnextra_dependencies)r   r+  r   
setdefaultr,  r   r  r  sort_tablesr!   r  )r   r   rh  r  r   super_super_tabler  sorted_retr  s             @rm   _sorted_tablesMapper._sorted_tables  s    :<&&;;F]]**15 # <  ,224ME__Fv"))=C]]K]k5)]K 5	0 &&1
  A$Q'CF 
I Ls   
C%
c                    XR                   ;   a  [        [        U R                   U   5      $ U" 5       =U R                   U'   nU$ rh   )r   r	   r_   )r   r0  	callable_r  s       rm   _memoMapper._memo  sB    '''D11#6771:<D!!#&Lrl   c                   [         R                  " [        5      nS nU R                   H  n[	        UR
                  5      nU R                  5        H  nUR                  (       d  M  UR                  [        UUR                   VVs/ s H  u  pgUR                  PM     snn5      5      (       d  Ma  X   R                  XUR                  45        M     M     U$ s  snnf )z_memoized map of tables to collections of columns to be
synchronized upwards to the base mapper.c                $    U R                  U5      $ rh   )rP  )r   ys     rm   	set_union+Mapper._table_to_equated.<locals>.set_union  s    771:rl   )r!   defaultdictr   r  rj   r   r  r   rw  r   rt  r  )r   r  r  r   r  r  r  rs           rm   _table_to_equatedMapper._table_to_equated  s     T" 		 ((Euww<D))+,,,1B1B!121J1JK1J1JK2 2 M((!-F-F)GH , )  Ls   C)>r   r   r   r   r   r   r   rX  r   r   r   r   r   r   r   r   r   r|  rW  r   r   r   r   r   r   r   r   r   r   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r}   rz   r   r   r   r   r   r   r   r   r~   rK   r   r   r   r   r   r   r   )NNNFNNNFNNNNNFNFNTTNNNTFTr   Fd   ):r{   r|   r}   Optional[FromClause]r    z+Optional[Mapping[str, MapperProperty[Any]]]r~   z/Optional[Iterable[_ORMColumnExprArgument[Any]]]rz   r   r   z'Optional[Union[Mapper[Any], Type[Any]]]r   z)Optional[_ColumnExpressionArgument[bool]]r   z/Optional[Sequence[_ORMColumnExprArgument[Any]]]r   r   r   z%Optional[_ORMColumnExprArgument[Any]]r   r   r   zFOptional[Union[_ORMColumnExprArgument[Any], str, MapperProperty[Any]]]r   z Optional[Dict[Any, Mapper[Any]]]r   r   r   r   r   Optional[_WithPolymorphicArg]r   r   r   z'Optional[Literal['selectin', 'inline']]r   r   r   r   r   r   r   Optional[Sequence[str]]r   r  r   r   r   r   r   r   r   zLiteral[True, False, 'auto']r   r   r   int)return
Mapper[_O])r  rQ   )r   r  r  Noner  r  )r   r!  r0  r!  r  zColumn[Any])F)r0  r!  r  z3Union[KeyedColumnElement[Any], MapperProperty[Any]]r:  r   r  r   r  r   r  rb   )r0  r!  r)  zAUnion[Sequence[KeyedColumnElement[Any]], KeyedColumnElement[Any]]r  ColumnProperty[Any])NN)r0  r!  r  rb   r  r   r  zOptional[ColumnProperty[Any]]r  r   r  r  )r0  r!  r)  zKeyedColumnElement[Any]r  r  )r0  r!  r1  z'Union[Column[Any], MapperProperty[Any]]r  r  )r  r!  )r  r!  r  r   r  r  )r  InstanceState[_O]r  r   )r0  r!  r  r   )r0  r!  r0  r   r  rb   )r)  zColumnElement[_T]r  zMapperProperty[_T])r=  r   r>  r  r  Sequence[Mapper[Any]])r?  zIterable[Mapper[Any]]rE  r   r  r]   )r  r   )r  r  )r  r]   )r  z+Mapping[FromClause, FrozenSet[Column[Any]]])r  z#Mapping[FromClause, FrozenSet[str]])r  zSet[str])NFF)r=  r   r>  z'Union[Literal[False, None], FromClause]rE  r   r  z(Tuple[Sequence[Mapper[Any]], FromClause])rk   )r  zOptional[orm_util.ORMAdapter]rh   )r  z,util.ReadOnlyProperties[MapperProperty[Any]])r  z'util.ReadOnlyProperties[InspectionAttr])r  zDict[str, str])r  z-util.ReadOnlyProperties[SynonymProperty[Any]])r  z,util.ReadOnlyProperties[ColumnProperty[Any]])r  z2util.ReadOnlyProperties[RelationshipProperty[Any]])r  z/util.ReadOnlyProperties[CompositeProperty[Any]])r  z	Type[_MP]r  zutil.ReadOnlyProperties[_MP])r  rY   )r  r!  r  r   r  r   )r  re   r  r   )r  zInstanceState[Any]r'  r   r  r   r  zIterator[Mapper[Any]])r  re   )rD  zUnion[Row[Any], RowMapping]r  r   r  zOptional[ORMAdapter]r  _IdentityKeyType[_O])r~   Tuple[Any, ...]r  r   r  r  )rO  r"   r  r  )r  r  rT  r&   r  r  )rO  r"   r  r  )
r  r  r  rH   r)  ColumnElement[Any]rT  r&   r  r   )r  r!  r  r  r  z.Optional[Callable[[InstanceState[Any]], bool]]r  zGIterator[Tuple[object, Mapper[Any], InstanceState[Any], _InstanceDict]])r0  r   r  zCallable[[], _T]r  r_   )r   r   __qualname____firstlineno____doc____annotations__rX  rx   rW  r!   deprecated_paramsr   r   r   	is_mapperrepresents_outer_joinpropertyr   r   r   non_memoized_property
deprecatedr   memoized_propertyr   r   r   r  r2  r5  r   r[  rc  r   r   r   r   rD   memoized_attributer  r  r  preload_moduler.  r  r  r  r  langhelperstag_method_for_warningsr   	SAWarningr  r  r  r   r   r  r   r  r  r!  r*  r-  r1  r4  r8  rA  rG  rP  rX  r\  r_  rb  re  rE   ri  with_polymorphic_mappersrr  rx  r|  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  r  r  r  r  r-  r   r#  r)  r<  r  r+  r3  r&  r8  r=  rE  rH  rP  r&   PASSIVE_RETURN_NO_VALUErM  rX  rg  r{  rn  rq  rt  rz  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  __static_attributes__rk   rl   rm   ru   ru      sR   	 %$O"s" 	
	 -1BFGK!<@GK $@D  =A.2:>%*DH"&'+6:6: $ %%)7=!&$'I^
B^
B *^
B @	^
B
 E^
B ^
B :^
B E^
B
^
B ^
B >^
B
^
B"
#^
B( ;)^
B* ,+^
B, -^
B. 8/^
B0 #1^
B2 B3^
B4  5^
B6 7^
B8 %9^
B: 4;^
B< 4=^
B> ?^
B@ A^
BB #C^
BD 5E^
BF G^
BH "I^
B	^
B@
' I%!    A00552277!!((BBDD6644%%LL%  "! DC 00  PO0 #"2 $#
 54J	 N )(. $# L  65 ,+ ('
 
 87  214		__U56' 7  ' 
- -}~%( =%(	%(NA61[z5.}
~rhD2L &*"## $ ##
 $
 ##/ $/ 
:; <8 
:; "'hh Fh
 h h  h 
h <hT99
9 
9H 8<;?@@ +@ 	@
 5@ 9@ 
@D 
:;"" (" 
	" <"H 
--	 		AA.***E*	*") 
 
CDI	
(" 49,0	".'.	. * *
""%9"	"H,9=	: ## $" ## $ ##
 $
 ##.
 $.
` ##? $? ##
  $
  '
 '
  9
 '
 '
 ##
 $
 ##
 $
 ##
 $
 ##
 $
 ##
	4
 $
$ ##
	4
 $
$ ##
 $
 ##
	,
 $
 ## $  ((
 )
. 

 
  	1 	1 >C	NN <N 	N
 
2N0 ##
 $
 

 


 ##
 $
8 ###4 $#4J ##C
 $C
J ##	:;
 < $
  ##	:;I < $I   ##B $B ##	78
	;
 9 $
: ##	:;
 < $


	%
 ##
 $
$ ##" $"H? ##D $D,\5	
-'-9=-	- ##. $./) 5 5	 )-(,	
(
 &
 &	

 

H )-
$
 &
 
	
"M&  +BB
 
 
 
	
$  ## $$ ##I $I ## $ ## $ ##N $N  +BBO O O #	O
 O 
OND
 -8,O,O
d
L ## $6p, 
:;_* <_*B ##B $B CG	__ !_ @	_

_B ##8 $8 ##$ $$ ##0 $0d 
 rl   ru   r  c                      \ rS rSrSrg)r  i  rk   N)r   r   r  r  r0  rk   rl   rm   r  r    s    rl   r  c                 (    [        [        5       SS9  g)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.

Tr  N)r  rn   rk   rl   rm   configure_mappersr3    s    H /+T:rl   c                   U  H  nUR                   (       d  M    O   g [           [        (       a
   S S S 5        g Sq U  H  nUR                   (       d  M    O    SqS S S 5        g [        R                  R                  [        5      R                  5         [        X5        Sq S S S 5        [        R                  R                  [        5      R                  5         g ! Sqf = f! , (       d  f       NG= f)NTF)	r  ri   _already_compilingru   rw   
_for_classbefore_configured_do_configure_registriesafter_configured)
registriesr  rq   s      rm   r  r  Z  s       		 
	 "	'!### "  "'+ 
	 OO&&v.@@B %Z9!&+ 
, OOv&779 "'+ 
	s9   C%C%CCC%%<C!C%C""C%%
C3zsqlalchemy.orm.decl_apic                   [         R                  R                  R                  n[	        U 5      nUR
                  " U 5       GHZ  nSnUR                  5        H  nS nUR                  R                   H"  nU" XfR                  5      nU[        L d  M   Sn  O   U[        L a  ML  [        USS5      (       a;  [        R                  " SU< SUR                  < 35      n	UR                  U	l        U	eUR                  (       a  M   UR!                  5         UR#                  5         UR                  R%                  XfR                  5        M     U(       d  SUl        U(       a  GM$  UR0                  R3                  U5      (       d  GMG  [        R                  " S5      e   g ! [&         a1    [(        R*                  " 5       S   n
[-        U
S5      (       d  Xl        e f = f)NFTrx   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!   r  orm_decl_apirK   rj   _recurse_with_dependenciesrp   rw   before_mapper_configuredr{   r)   r  r   rC  rx   r   r  r   mapper_configured	Exceptionsysexc_inforL  r  _dependenciesrf  )r:  r  rK   origrq   has_skipr   run_configurefnr  r   s              rm   r8  r8  |  s    ~~**33Hz?D22:>//1F Moo>> "6== 9 H,#H	 ?
 (v2E::..
 v77	9 '-&>&>#$$$557//1OO55fmmL5 2@ $Cw3,,77==,,/ O ?< ! ,,.+C"3(;<<360	s   AF"";Gc                   [         R                  R                  R                  n[	        U 5      nUR
                  " U 5       GH  nU(       d6  UR                  R                  U5      (       a  [        R                  " S5      eUR                  (       aA   UR                  R                  5       u  pVUR                  U5        UR                  (       a  MA  UR                  R                  5         UR                  R                  5         UR                    H  nUR                  R#                  U5        M      UR                   R                  5         SUl        GM     g ! [         a     Nf = f)Nz^Registry has dependent registries that are not disposed; pass cascade=True to clear these alsoF)r!   r  r<  rK   rj   _recurse_with_dependents_dependentsrf  r   rC  	_managerspopitem_dispose_manager_and_mapperr^  _non_primary_mappersclearrC  discardr  )r:  r  rK   rD  rq   rQ  _r  s           rm   _dispose_registriesrR    s   ~~**33Hz?D00<3??55d;;,,8 
 mm9 ]]224

 //8 mmm 	  &&($$COO##C( %!
 !3 =  s   E
E+*E+c                    SU l         U $ )au  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>  )rG  s    rm   reconstructorrT    s    4 #BIrl   Tinclude_removesinclude_backrefsc                    ^ ^^ SUU U4S jjnU$ )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.

 .. versionchanged:: 2.0.16 This paramter inadvertently defaulted to
    ``False`` for releases 2.0.0 through 2.0.15.  Its correct default
    of ``True`` is restored in 2.0.16.

.. seealso::

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

c                *   > TU l         TTS.U l        U $ )NrU  )r@  rO  )rG  rW  rV  namess    rm   wrapvalidates.<locals>.wrap  s"    $. 0%
! 	rl   rG  rc   r  rc   rk   )rV  rW  rZ  r[  s   ``` rm   	validatesr^    s    P  Krl   c                    U R                   R                  nUR                  (       a   UR                  U R                  5       5        g g rh   )rQ  r   r   r  )r  ctxinstrumenting_mappers      rm   rN  rN  $  s4     ==//**++EIIK8 +rl   c                    U R                   R                  nU(       a4  UR                  5         UR                  (       a  UR                  U 5        ggg)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)rQ  r   r  r   )r  r  kwargsra  s       rm   rJ  rJ  +  sD     !==//--/99 ::5A : rl   c                  (    \ rS rSrSrSrS rS rSrg)r   i;  z4Error reporting helper for mapper._columntoproperty.r   c                    Xl         g rh   re  r	  s     rm   r   _ColumnMapping.__init__@  s    rl   c           
     H   U R                   R                  R                  U5      nU(       aN  [        R                  " SUR
                  R                  < SUR                  < SUR                  < SU< 35      e[        R                  " SU< SU R                   < S35      e)NzColumn 'r   z1' is not available, due to conflicting property 'z':z
No column z is configured on mapper z...)r   r   r  orm_excUnmappedColumnErrorr   rT  r0  )r   r)  r1  s      rm   __missing___ColumnMapping.__missing__D  sx    {{!!%%f--- <<$$fkk6::tE 
 ))t{{$
 	
rl   N)	r   r   r  r  r  	__slots__r   rk  r0  rk   rl   rm   r   r   ;  s    >I
rl   r   )r  rb   )r  zSet[registry]r  r  )r:  zSet[_RegistryType]r  r   r  r  r]  )rZ  r!  rV  r   rW  r   r  zCallable[[_Fn], _Fn])r  
__future__r   collectionsr   	functoolsr   	itertoolsr   rA  	threadingtypingr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   weakrefr  r   r   ri  r   r   r    r!   r  _typingr"   r8   r#   r$   r%   r&   r'   
interfacesr(   r)   r*   r+   r,   r-   r.   path_registryr/   r1   r   r2   r3   r4   r5   r6   r7   r  r9   r:   r;   r<   r=   r  r>   sql.cache_keyr?   sql.elementsr@   
sql.schemarA   rB   sql.selectablerC   rD   rE   util.typingrF   rG   rH   rI   rJ   decl_apirK   
dependencyrL   r  rM   rN   eventsrO   rP   rQ   rR   r  rS   r  rT   rU   enginerV   rW   sql._typingrX   rY   sql.baserZ   r[   r\   r]   r^   r_   ra   rc   _WithPolymorphicArgWeakKeyDictionaryrf   r   rn   rr   r5  symbolrs   RLockri   _self_inspectsclass_logger
IdentifiedInspectableru   r@  r  r3  r  r)  r8  rR  rT  r^  rN  rJ  r   rk   rl   rm   <module>r     sI   #    
                               " (    (   & & 2 ) + '          "      "  / -   ;  4 !)&/&"/31$-4*3$ #723+,+! Te01e/0 CL	gclHU=$s)+C%DEEF	  U=$s)+,-/   B 
'
/
   {{>* ??$  h=r"NN<(BKh=  h=V{	 	D;N:":-1:	:D ./1"1-11	1 01h ./! 0!B> */00"&0BF00f9B 
TEF 
rl   