
    h                      d Z ddlmZ ddlZddlZddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddlm!Z! ddlm"Z" ddlm#Z# dd lm$Z$ dd!l%m&Z& dd"l%m'Z' dd#l%m(Z( dd$l%m)Z) dd%l*m+Z+ dd&l*m,Z, dd'l*m-Z- dd(l*m.Z. dd)l*m/Z/ dd*l*m0Z0 dd+l*m1Z1 dd,l2m3Z3 dd-l2m4Z4 dd-l2m4Z5 dd.l6m7Z7 dd/l8m9Z9 dd0l:m;Z; dd1l<m=Z= d2d3lm>Z> d2d4lm?Z? d2d5lm@Z@ d2d6lAmBZB d2d7lCmDZD d2d8lEmFZF d2d9lGmHZH d2d:lImJZJ d2d;l@mKZK d2d<l@mLZL d2d=l@mZM d2d>l@mNZN d2d?lOmPZP d2d@lOmQZQ d2dAlOmRZR d2dBlOmSZS d2dClOmTZT d2dDlOmUZU d2dElOmVZV d2dFlOmWZW d2dGlOmXZX d2dHlOmYZY er0ddIlZm[Z[ ddJlZm\Z\ ddKl*m]Z] ddLlm^Z^ ddMlm_Z_ dd1l<m=Z= d2dNl`maZa d2dOlbmcZc  edPeQ      Zd edReQ      ZeeedSf   Zfe	edSf   ZgedTee(ed   e)ed   eFed   f   f   ZhdzdUZi G dV dWej      Zk G dX dYeke?j                  e7e            Zm eMj                  e9e;e3e4e!e"ee#e f	Z       G d[ d\em             Zo G d] d^em      Zp	 d{	 	 	 	 	 d|d_Zq G d` da      Zr G db dcereed         Zs G dd deej                  ed   er      Zu G df dgeued         Zvd}dhZwd~diZx G dj dkeol      Zy G dm dne?j                  e=e      eml      ZzddoZ{ G dp dqe?j                  e=e            Z|	 	 	 	 	 	 	 	 ddrZ}dde~dsdde.epdt	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dduZ G dv dw      ZeZeseZ\ddxZ e?j                  epezem      ddy       Zy)z1Public API functions and helpers for declarative.    )annotationsN)Any)Callable)ClassVar)Dict)	FrozenSet)Generic)Iterable)Iterator)Mapping)Optional)overload)Set)Tuple)Type)TYPE_CHECKING)TypeVar)Union   )
attributes)clsregistry)instrumentation)
interfaces)	mapperlib)	composite)deferred)mapped_column)relationship)synonym)InstrumentedAttribute)_inspect_mapped_class)_is_mapped_class)Mapped)ORMDescriptor_add_attribute)_as_declarative)_ClassScanMapperConfig)_declarative_constructor)_DeferredMapperConfig)_del_attribute_mapper)	Composite)Synonym)Mapper)MappedColumn)RelationshipProperty)InstanceState   )exc)
inspection)util)sqltypes)_NoArg)SQLCoreOperations)MetaData)
FromClause)hybridmethod)hybridproperty)typing)warn_deprecated)CallableReference)de_optionalize_union_types)flatten_newtype)
is_generic)
is_literal)
is_newtype)	is_pep695)Literal)LITERAL_TYPES)Self)_O)_RegistryType)_DataclassArguments)ClassManager)MapperProperty)_TypeEngineArgument)_MatchedOnType_T)bound_TTz_TypeEngineArgument[Any].c                J    | j                   dd D ]  }t        |dd       y y)aK  Given a class, return True if any of the classes it inherits from has a
    mapped table, otherwise return False.

    This is used in declarative mixins to build attributes that behave
    differently for the base class vs. a subclass in an inheritance
    hierarchy.

    .. seealso::

        :ref:`decl_mixin_inheritance`

    r   N	__table__TF)__mro__getattr)clsclass_s     @D:\EasyAligner\venv\Lib\site-packages\sqlalchemy/orm/decl_api.pyhas_inherited_tabler\   n   s/     ++ab/6;-9 "     c                      e Zd ZddZddZy)_DynamicAttributesTypec                j    d| j                   v rt        | ||       y t        j                  | ||       y N
__mapper__)__dict__r&   type__setattr__)rY   keyvalues      r[   re   z"_DynamicAttributesType.__setattr__   s,    3<<'3U+S#u-r]   c                f    d| j                   v rt        | |       y t        j                  | |       y ra   )rc   r+   rd   __delattr__rY   rf   s     r[   ri   z"_DynamicAttributesType.__delattr__   s(    3<<'3$S#&r]   N)rf   strrg   r   returnNone)rf   rk   rl   rm   )__name__
__module____qualname__re   ri    r]   r[   r_   r_      s    .'r]   r_   c                      e Zd ZdZy)DeclarativeAttributeInterceptzMetaclass that may be used in conjunction with the
    :class:`_orm.DeclarativeBase` class to support addition of class
    attributes dynamically.

    Nrn   ro   rp   __doc__rq   r]   r[   rs   rs      s    
r]   rs   field_specifiersc                      e Zd ZdZy)DCTransformDeclarativez-metaclass that includes @dataclass_transformsNrt   rq   r]   r[   ry   ry      s     8r]   ry   c                  >    e Zd ZU ded<   ded<   	 	 	 	 	 	 	 	 	 	 ddZy)DeclarativeMetar;   metadataRegistryTyperegistryc                8   | j                   }t        | dd       }|>|j                  dd       }t        |t              st        j                  d      || _        | j                   j                  dd      st        || |       t        j                  | |||       y )N_sa_registryr~   ziDeclarative base class has no 'registry' attribute, or registry is not a sqlalchemy.orm.registry() object__abstract__F)rc   rX   get
isinstancer~   r5   InvalidRequestErrorr   r'   rd   __init__)rY   	classnamebasesdict_kwregs         r[   r   zDeclarativeMeta.__init__   s    
 
 c>40;))J-Cc8,--L 
 $' ||6Ce,c9eU3r]   N)
r   r   r   r   r   r   r   r   rl   rm   )rn   ro   rp   __annotations__r   rq   r]   r[   r{   r{      s;    44$'4034;>4	4r]   r{   c                     d fd}|S )a  Decorator that produces an :func:`_orm.synonym`
    attribute in conjunction with a Python descriptor.

    The function being decorated is passed to :func:`_orm.synonym` as the
    :paramref:`.orm.synonym.descriptor` parameter::

        class MyClass(Base):
            __tablename__ = "my_table"

            id = Column(Integer, primary_key=True)
            _job_status = Column("job_status", String(50))

            @synonym_for("job_status")
            @property
            def job_status(self):
                return "Status: %s" % self._job_status

    The :ref:`hybrid properties <mapper_hybrids>` feature of SQLAlchemy
    is typically preferred instead of synonyms, which is a more legacy
    feature.

    .. seealso::

        :ref:`synonyms` - Overview of synonyms

        :func:`_orm.synonym` - the mapper-level function

        :ref:`mapper_hybrids` - The Hybrid Attribute extension provides an
        updated approach to augmenting attribute behavior more flexibly than
        can be achieved with synonyms.

    c                     t        |       S )N)
map_column
descriptor)_orm_synonym)fnr   names    r[   decoratezsynonym_for.<locals>.decorate   s    DZBGGr]   )r   Callable[..., Any]rl   zSynonym[Any]rq   )r   r   r   s   `` r[   synonym_forr      s    HH Or]   c                  4    e Zd Z	 	 d	 	 	 	 	 ddZddZddZy)	_declared_attr_commonc                    t        |t              r|j                  }|| _        || _        || _        |j                  | _        y N)r   classmethod__func__fget
_cascading_quietru   )selfr   	cascadingquiets       r[   r   z_declared_attr_common.__init__   s7     b+&B	#zzr]   c                ^    t        j                  | j                        j                  d      S )Nrl   )r7   get_annotationsr   r   r   s    r[   _collect_return_annotationz0_declared_attr_common._collect_return_annotation
  s"    ##DII.228<<r]   c                   |}t        j                  |      }|tt        j                  d| j                  j
                        s9t        j                  d| j                  j
                  d|j
                         | j	                  |      S |j                  r| j	                  |      S |j                         }|J |j                  }| |v r||    S | j	                  |      x|| <   }|S )Nz^__.+__$z*Unmanaged access of declarative attribute z from non-mapped class )r   opt_manager_of_classrematchr   rn   r7   warn	is_mappeddeclarative_scandeclared_attr_reg)r   instanceownerrY   managerr   r   objs           r[   __get__z_declared_attr_common.__get__  s     11#6?88K););< 		-1YY-?-?O 99S>! 99S>! #335  +++003;t9"iin,CIJr]   N)FF)r   r   r   boolr   r   )rl   zOptional[Type[Any]])r   Optional[object]r   r   rl   r   )rn   ro   rp   r   r   r   rq   r]   r[   r   r      s5      	"" " 	"*=%r]   r   c                  X    e Zd Zej                  r	 d	 	 	 ddZd	dZd
dZddZddZ	yy)_declared_directivec                     y r   rq   r   r   r   s      r[   r   z_declared_directive.__init__:       r]   c                     y r   rq   r   r   r   s      r[   r   z_declared_directive.__get__@  s    r]   c                     y r   rq   r   r   rg   s      r[   __set__z_declared_directive.__set__B      cr]   c                     y r   rq   r   r   s     r[   
__delete__z_declared_directive.__delete__D      Sr]   c                     y r   rq   r   r   s     r[   __call__z_declared_directive.__call__F  s    r]   NF)r   zCallable[..., _T]r   r   )r   r   r   r   rl   rR   r   r   rg   r   rl   rm   r   r   rl   rm   )r   zCallable[..., _TT]rl   z_declared_directive[_TT])
rn   ro   rp   r?   r   r   r   r   r   r   rq   r]   r[   r   r   5  s?     
 $	!	 	 	MA8	 r]   r   c                      e Zd ZdZej
                  r3	 d	 	 	 ddZddZddZe		 	 	 	 	 	 dd       Z
e	dd       Z
	 	 	 	 	 	 ddZ
edd       Zedd	       Zedd
       Zy)declared_attra  Mark a class-level method as representing the definition of
    a mapped property or Declarative directive.

    :class:`_orm.declared_attr` is typically applied as a decorator to a class
    level method, turning the attribute into a scalar-like property that can be
    invoked from the uninstantiated class. The Declarative mapping process
    looks for these :class:`_orm.declared_attr` callables as it scans classes,
    and assumes any attribute marked with :class:`_orm.declared_attr` will be a
    callable that will produce an object specific to the Declarative mapping or
    table configuration.

    :class:`_orm.declared_attr` is usually applicable to
    :ref:`mixins <orm_mixins_toplevel>`, to define relationships that are to be
    applied to different implementors of the class. It may also be used to
    define dynamically generated column expressions and other Declarative
    attributes.

    Example::

        class ProvidesUserMixin:
            "A mixin that adds a 'user' relationship to classes."

            user_id: Mapped[int] = mapped_column(ForeignKey("user_table.id"))

            @declared_attr
            def user(cls) -> Mapped["User"]:
                return relationship("User")

    When used with Declarative directives such as ``__tablename__``, the
    :meth:`_orm.declared_attr.directive` modifier may be used which indicates
    to :pep:`484` typing tools that the given method is not dealing with
    :class:`_orm.Mapped` attributes::

        class CreateTableName:
            @declared_attr.directive
            def __tablename__(cls) -> str:
                return cls.__name__.lower()

    :class:`_orm.declared_attr` can also be applied directly to mapped
    classes, to allow for attributes that dynamically configure themselves
    on subclasses when using mapped inheritance schemes.   Below
    illustrates :class:`_orm.declared_attr` to create a dynamic scheme
    for generating the :paramref:`_orm.Mapper.polymorphic_identity` parameter
    for subclasses::

        class Employee(Base):
            __tablename__ = "employee"

            id: Mapped[int] = mapped_column(primary_key=True)
            type: Mapped[str] = mapped_column(String(50))

            @declared_attr.directive
            def __mapper_args__(cls) -> Dict[str, Any]:
                if cls.__name__ == "Employee":
                    return {
                        "polymorphic_on": cls.type,
                        "polymorphic_identity": "Employee",
                    }
                else:
                    return {"polymorphic_identity": cls.__name__}


        class Engineer(Employee):
            pass

    :class:`_orm.declared_attr` supports decorating functions that are
    explicitly decorated with ``@classmethod``. This is never necessary from a
    runtime perspective, however may be needed in order to support :pep:`484`
    typing tools that don't otherwise recognize the decorated function as
    having class-level behaviors for the ``cls`` parameter::

        class SomethingMixin:
            x: Mapped[int]
            y: Mapped[int]

            @declared_attr
            @classmethod
            def x_plus_y(cls) -> Mapped[int]:
                return column_property(cls.x + cls.y)

    .. versionadded:: 2.0 - :class:`_orm.declared_attr` can accommodate a
       function decorated with ``@classmethod`` to help with :pep:`484`
       integration where needed.


    .. seealso::

        :ref:`orm_mixins_toplevel` - Declarative Mixin documentation with
        background on use patterns for :class:`_orm.declared_attr`.

    c                     y r   rq   r   s      r[   r   zdeclared_attr.__init__  r   r]   c                     y r   rq   r   s      r[   r   zdeclared_attr.__set__  r   r]   c                     y r   rq   r   s     r[   r   zdeclared_attr.__delete__  r   r]   c                     y r   rq   r   s      r[   r   zdeclared_attr.__get__  s     ),r]   c                     y r   rq   r   s      r[   r   zdeclared_attr.__get__  s    ?Br]   c                     y r   rq   r   s      r[   r   zdeclared_attr.__get__  s    36r]   c                    t        di |S Nrq   )_stateful_declared_attr)rY   r   s     r[   	_statefulzdeclared_attr._stateful  s    &,,,r]   c                    t         S r   )r   rY   s    r[   	directivezdeclared_attr.directive  s
     #"r]   c                &    | j                  d      S )NT)r   )r   r   s    r[   r   zdeclared_attr.cascading  s     }}t},,r]   Nr   )r   _DeclaredAttrDecorated[_T]r   r   r   r   )r   rm   r   r   rl   zInstrumentedAttribute[_T])r   objectr   r   rl   rR   )r   r   r   r   rl   z$Union[InstrumentedAttribute[_T], _T]r   r   rl   _stateful_declared_attr[_T])rl   z_declared_directive[Any])rl   r   )rn   ro   rp   ru   r?   r   r   r   r   r   r   r=   r   r>   r   r   rq   r]   r[   r   r   K  s    Zx 
 $	*	 	 	B8 
	, 	,),	,&	, 
	, 
B 
B	7,	758	71	7 - - # # - -r]   r   c                  :    e Zd ZU ded<   ddZedd       Zd	dZy)
r   zDict[str, Any]r   c                    || _         y r   )r   r   r   s     r[   r   z _stateful_declared_attr.__init__  s	    r]   c                n    | j                   j                         }|j                  |       t        di |S r   )r   copyupdater   )r   r   new_kws      r[   r   z!_stateful_declared_attr._stateful  s+    b&000r]   c                .    t        |fi | j                  S r   )r   r   r   s     r[   r   z _stateful_declared_attr.__call__  s    R+477++r]   Nr   r   r   )r   r   rl   zdeclared_attr[_T])rn   ro   rp   r   r   r=   r   r   rq   r]   r[   r   r     s&     1 1
,r]   r   c                    | S )a.  Mark a class as providing the feature of "declarative mixin".

    E.g.::

        from sqlalchemy.orm import declared_attr
        from sqlalchemy.orm import declarative_mixin


        @declarative_mixin
        class MyMixin:

            @declared_attr
            def __tablename__(cls):
                return cls.__name__.lower()

            __table_args__ = {"mysql_engine": "InnoDB"}
            __mapper_args__ = {"always_refresh": True}

            id = Column(Integer, primary_key=True)


        class MyModel(MyMixin, Base):
            name = Column(String(1000))

    The :func:`_orm.declarative_mixin` decorator currently does not modify
    the given class in any way; it's current purpose is strictly to assist
    the :ref:`Mypy plugin <mypy_toplevel>` in being able to identify
    SQLAlchemy declarative mixin classes when no other context is present.

    .. versionadded:: 1.4.6

    .. seealso::

        :ref:`orm_mixins_toplevel`

        :ref:`mypy_declarative_mixins` - in the
        :ref:`Mypy plugin documentation <mypy_toplevel>`

    rq   r   s    r[   declarative_mixinr     s
    R Jr]   c                N   d| j                   v r| j                   d   }nd }d| j                   v r| j                   d   }nd }| j                   j                  dd       }|<t        |t              st	        j
                  d      |)t	        j
                  d      t        ||      }|| _        || _        d| j                   vr| j                  j                  | _        t        | dt        j                        t        j                  u r| j                  j                  | _
        y y )Nr|   type_annotation_mapr~   zfDeclarative base class has a 'registry' attribute that is not an instance of sqlalchemy.orm.registry()zDeclarative base class has both a 'registry' attribute and a type_annotation_map entry.  Per-base type_annotation_maps are not supported.  Please apply the type_annotation_map to this registry directly.)r|   r   r   )rc   r   r   r~   r5   r   r   r|   rX   r   r   constructor)rY   r|   r   r   s       r[   _setup_declarative_baser     s   S\\!<<
+,!ll+@A"
,,

:t
,C
#x())?  !,))-  3F
 C%||,,sJ0FOOC||// Dr]   c                       e Zd ZdZej
                  ej
                  ej
                  ej
                  ej
                  ej
                  ej
                  ej
                  f	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZ xZS )MappedAsDataclassa  Mixin class to indicate when mapping this class, also convert it to be
    a dataclass.

    .. seealso::

        :ref:`orm_declarative_native_dataclasses` - complete background
        on SQLAlchemy native dataclass mapping

    .. versionadded:: 2.0

    c	           	        ||||||||d}
t        | d      r| j                  }t        j                  |       |
j	                         D ci c]:  \  }}||t
        j                  u r |j                  |t
        j                        n|< c}}x| _        }n	|
x| _        }t        | $  di |	 t        |       s-t        j                  |       }t        j                  || |       y y c c}}w )Ninitrepreqorderunsafe_hash
match_argskw_onlydataclass_callable_sa_apply_dc_transformsrq   )hasattrr   r(   _assert_dc_argumentsitemsr9   NO_ARGr   super__init_subclass__r"   (_update_annotations_for_non_mapped_class_apply_dataclasses_to_any_class)rY   r   r   r   r   r   r   r   r   r   apply_dc_transformscurrentkvcurrent_transformsnew_anno	__class__s                   r[   r   z#MappedAsDataclass.__init_subclass__E  s    &$"4	4
 31211G"77@ 0557@7DAq A4F7;;q&--0AM7@ C'*< $C'*< 	!'B'$&OOH #BB"C	 %@s   ?C))r   Union[_NoArg, bool]r   r	  r   r	  r   r	  r   r	  r   r	  r   r	  r   'Union[_NoArg, Callable[..., Type[Any]]]r   r   rl   rm   )rn   ro   rp   ru   r9   r   r   __classcell__r  s   @r[   r   r   8  s    
 %+MM$*MM"(--%+]]+1==*0--'-}} MM1!1 "1  	1
 #1 )1 (1 %1
1 1 
1 1r]   r   )	metaclassc                       e Zd ZU dZej
                  r@ddZddZded<   ded<   	 ded<   	 d	ed
<   ded<   	 ded<   	 ded<   	 ded<   	 ded<   	 ddZ	d fdZ
 xZS )DeclarativeBasea  Base class used for declarative class definitions.

    The :class:`_orm.DeclarativeBase` allows for the creation of new
    declarative bases in such a way that is compatible with type checkers::


        from sqlalchemy.orm import DeclarativeBase


        class Base(DeclarativeBase):
            pass

    The above ``Base`` class is now usable as the base for new declarative
    mappings.  The superclass makes use of the ``__init_subclass__()``
    method to set up new classes and metaclasses aren't used.

    When first used, the :class:`_orm.DeclarativeBase` class instantiates a new
    :class:`_orm.registry` to be used with the base, assuming one was not
    provided explicitly. The :class:`_orm.DeclarativeBase` class supports
    class-level attributes which act as parameters for the construction of this
    registry; such as to indicate a specific :class:`_schema.MetaData`
    collection as well as a specific value for
    :paramref:`_orm.registry.type_annotation_map`::

        from typing_extensions import Annotated

        from sqlalchemy import BigInteger
        from sqlalchemy import MetaData
        from sqlalchemy import String
        from sqlalchemy.orm import DeclarativeBase

        bigint = Annotated[int, "bigint"]
        my_metadata = MetaData()


        class Base(DeclarativeBase):
            metadata = my_metadata
            type_annotation_map = {
                str: String().with_variant(String(255), "mysql", "mariadb"),
                bigint: BigInteger(),
            }

    Class-level attributes which may be specified include:

    :param metadata: optional :class:`_schema.MetaData` collection.
     If a :class:`_orm.registry` is constructed automatically, this
     :class:`_schema.MetaData` collection will be used to construct it.
     Otherwise, the local :class:`_schema.MetaData` collection will supercede
     that used by an existing :class:`_orm.registry` passed using the
     :paramref:`_orm.DeclarativeBase.registry` parameter.
    :param type_annotation_map: optional type annotation map that will be
     passed to the :class:`_orm.registry` as
     :paramref:`_orm.registry.type_annotation_map`.
    :param registry: supply a pre-existing :class:`_orm.registry` directly.

    .. versionadded:: 2.0  Added :class:`.DeclarativeBase`, so that declarative
       base classes may be constructed in such a way that is also recognized
       by :pep:`484` type checkers.   As a result, :class:`.DeclarativeBase`
       and other subclassing-oriented APIs should be seen as
       superseding previous "class returned by a function" APIs, namely
       :func:`_orm.declarative_base` and :meth:`_orm.registry.generate_base`,
       where the base class returned cannot be recognized by type checkers
       without using plugins.

    **__init__ behavior**

    In a plain Python class, the base-most ``__init__()`` method in the class
    hierarchy is ``object.__init__()``, which accepts no arguments. However,
    when the :class:`_orm.DeclarativeBase` subclass is first declared, the
    class is given an ``__init__()`` method that links to the
    :paramref:`_orm.registry.constructor` constructor function, if no
    ``__init__()`` method is already present; this is the usual declarative
    constructor that will assign keyword arguments as attributes on the
    instance, assuming those attributes are established at the class level
    (i.e. are mapped, or are linked to a descriptor). This constructor is
    **never accessed by a mapped class without being called explicitly via
    super()**, as mapped classes are themselves given an ``__init__()`` method
    directly which calls :paramref:`_orm.registry.constructor`, so in the
    default case works independently of what the base-most ``__init__()``
    method does.

    .. versionchanged:: 2.0.1  :class:`_orm.DeclarativeBase` has a default
       constructor that links to :paramref:`_orm.registry.constructor` by
       default, so that calls to ``super().__init__()`` can access this
       constructor. Previously, due to an implementation mistake, this default
       constructor was missing, and calling ``super().__init__()`` would invoke
       ``object.__init__()``.

    The :class:`_orm.DeclarativeBase` subclass may also declare an explicit
    ``__init__()`` method which will replace the use of the
    :paramref:`_orm.registry.constructor` function at this level::

        class Base(DeclarativeBase):
            def __init__(self, id=None):
                self.id = id

    Mapped classes still will not invoke this constructor implicitly; it
    remains only accessible by calling ``super().__init__()``::

        class MyClass(Base):
            def __init__(self, id=None, name=None):
                self.name = name
                super().__init__(id=id)

    Note that this is a different behavior from what functions like the legacy
    :func:`_orm.declarative_base` would do; the base created by those functions
    would always install :paramref:`_orm.registry.constructor` for
    ``__init__()``.


    c                     y r   rq   r   s    r[   _sa_inspect_typez DeclarativeBase._sa_inspect_type      Cr]   c                     y r   rq   r   s    r[   _sa_inspect_instancez$DeclarativeBase._sa_inspect_instance      sr]   ClassVar[_RegistryType]r   r~   ClassVar[MetaData]r|   zClassVar[str]rn   ClassVar[Mapper[Any]]rb   zClassVar[FromClause]rV   r   __tablename____mapper_args____table_args__c                     y r   rq   r   s     r[   r   zDeclarativeBase.__init__C      sr]   c                    t         | j                  v rt        | t                t        |        n!t	        | j
                  | | j                         t        |    di | y r   )	r  	__bases___check_not_declarativer   r'   r   rc   r   r   rY   r   r  s     r[   r   z!DeclarativeBase.__init_subclass__E  sG    cmm+"38#C(C,,c3<<@!'B'r]   rl   zMapper[Self]rl   zInstanceState[Self]r   r   r   rl   rm   )rn   ro   rp   ru   r?   r   r  r  r   r   r   r  r  s   @r[   r  r  y  s    
n` 7B--))	< %$	  
 *)	 ('	 	 	 		 	+( (r]   r  c                    | j                   }d|v rt        |d         st        |d   d      r t        |j	                  dd       t
              r#t        j                  d|j                  d      y )NrV   r   r  zCannot use zR directly as a declarative base class. Create a Base by creating a subclass of it.)	rc   callabler   r   r   rk   r5   r   rn   )rY   basecls_dicts      r[   r   r   N  st    ||HxXk*+x,i8	HLL$7	=%%$--* +A A
 	
 
>r]   c                       e Zd ZU dZded<   ded<   	 ded<   	 ded<   	 d	ed
<   	 ej                  rddZddZded<   	 ded<   	 ded<   	 ddZ	d fdZ
 xZS )DeclarativeBaseNoMetazSame as :class:`_orm.DeclarativeBase`, but does not use a metaclass
    to intercept new attributes.

    The :class:`_orm.DeclarativeBaseNoMeta` base may be used when use of
    custom metaclasses is desirable.

    .. versionadded:: 2.0


    r  r   r~   r  r|   r  rb   Optional[FromClause]rV   c                     y r   rq   r   s    r[   r  z&DeclarativeBaseNoMeta._sa_inspect_type  r  r]   c                     y r   rq   r   s    r[   r  z*DeclarativeBaseNoMeta._sa_inspect_instance  r  r]   r   r  r  r  c                     y r   rq   r   s     r[   r   zDeclarativeBaseNoMeta.__init__  r  r]   c                    t         | j                  v rt        | t                t        |        n!t	        | j
                  | | j                         t        |    di | y r   )	r*  r  r   r   r'   r   rc   r   r   r!  s     r[   r   z'DeclarativeBaseNoMeta.__init_subclass__  sH     CMM1"3(=>#C(C,,c3<<@!'B'r]   r"  r#  r   r$  )rn   ro   rp   ru   r   r?   r   r  r  r   r   r  r  s   @r[   r*  r*  ]  s    	 *)%%8 !  &% $# 7B	 	 		 	+( (r]   r*  c                    t        | ||       y)a'  Add a new mapped attribute to an ORM mapped class.

    E.g.::

        add_mapped_attribute(User, "addresses", relationship(Address))

    This may be used for ORM mappings that aren't using a declarative
    metaclass that intercepts attribute set operations.

    .. versionadded:: 2.0


    Nr%   )targetrf   attrs      r[   add_mapped_attributer3    s      63%r]   Baser|   mapperrY   r   class_registryr   r   r  c                F    t        | |||      j                  ||||      S )a  Construct a base class for declarative class definitions.

    The new base class will be given a metaclass that produces
    appropriate :class:`~sqlalchemy.schema.Table` objects and makes
    the appropriate :class:`_orm.Mapper` calls based on the
    information provided declaratively in the class and any subclasses
    of the class.

    .. versionchanged:: 2.0 Note that the :func:`_orm.declarative_base`
       function is superseded by the new :class:`_orm.DeclarativeBase` class,
       which generates a new "base" class using subclassing, rather than
       return value of a function.  This allows an approach that is compatible
       with :pep:`484` typing tools.

    The :func:`_orm.declarative_base` function is a shorthand version
    of using the :meth:`_orm.registry.generate_base`
    method.  That is, the following::

        from sqlalchemy.orm import declarative_base

        Base = declarative_base()

    Is equivalent to::

        from sqlalchemy.orm import registry

        mapper_registry = registry()
        Base = mapper_registry.generate_base()

    See the docstring for :class:`_orm.registry`
    and :meth:`_orm.registry.generate_base`
    for more details.

    .. versionchanged:: 1.4  The :func:`_orm.declarative_base`
       function is now a specialization of the more generic
       :class:`_orm.registry` class.  The function also moves to the
       ``sqlalchemy.orm`` package from the ``declarative.ext`` package.


    :param metadata:
      An optional :class:`~sqlalchemy.schema.MetaData` instance.  All
      :class:`~sqlalchemy.schema.Table` objects implicitly declared by
      subclasses of the base will share this MetaData.  A MetaData instance
      will be created if none is provided.  The
      :class:`~sqlalchemy.schema.MetaData` instance will be available via the
      ``metadata`` attribute of the generated declarative base class.

    :param mapper:
      An optional callable, defaults to :class:`_orm.Mapper`. Will
      be used to map subclasses to their Tables.

    :param cls:
      Defaults to :class:`object`. A type to use as the base for the generated
      declarative base class. May be a class or tuple of classes.

    :param name:
      Defaults to ``Base``.  The display name for the generated
      class.  Customizing this is not required, but can improve clarity in
      tracebacks and debugging.

    :param constructor:
      Specify the implementation for the ``__init__`` function on a mapped
      class that has no ``__init__`` of its own.  Defaults to an
      implementation that assigns \**kwargs for declared
      fields and relationships to an instance.  If ``None`` is supplied,
      no __init__ will be provided and construction will fall back to
      cls.__init__ by way of the normal Python semantics.

    :param class_registry: optional dictionary that will serve as the
      registry of class names-> mapped classes when string names
      are used to identify classes inside of :func:`_orm.relationship`
      and others.  Allows two or more declarative base classes
      to share the same registry of class names for simplified
      inter-base relationships.

    :param type_annotation_map: optional dictionary of Python types to
        SQLAlchemy :class:`_types.TypeEngine` classes or instances.  This
        is used exclusively by the :class:`_orm.MappedColumn` construct
        to produce column types based on annotations within the
        :class:`_orm.Mapped` type.


        .. versionadded:: 2.0

        .. seealso::

            :ref:`orm_declarative_mapped_column_type_map`

    :param metaclass:
      Defaults to :class:`.DeclarativeMeta`.  A metaclass or __metaclass__
      compatible callable to use as the meta type of the generated
      declarative base class.

    .. seealso::

        :class:`_orm.registry`

    )r|   r7  r   r   )r6  rY   r   r  )r~   generate_baser5  s           r[   declarative_baser:    s;    \ %/	
 m	  
r]   c                  "   e Zd ZU dZded<   ded<   ded<   ded	<   d
ed<   ded<   ded<   ded<   ded<   ddded	 	 	 	 	 	 	 d0dZ	 	 	 	 d1dZ	 d2	 	 	 	 	 d3dZe	d4d       Z
d5dZd6dZe	 	 	 	 d7d       Ze	 	 	 	 d7d       Zd8dZd9dZd:dZd;d Zd<d=d!Zd<d=d"Zd;d#Zded$ef	 	 	 	 	 	 	 	 	 d>d%Z ej6                  eeeee e!e"e#e$f	&      e%d?d'              Z&e%	 d@d(d(d(d(d(d(d(d(d)	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dAd*       Z&	 dBe'jP                  e'jP                  e'jP                  e'jP                  e'jP                  e'jP                  e'jP                  e'jP                  d)	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dCd+Z&dDd,Z)dEd-Z*dFd.Z+	 dB	 	 	 	 	 	 	 dGd/Z,y)Hr~   a  Generalized registry for mapping classes.

    The :class:`_orm.registry` serves as the basis for maintaining a collection
    of mappings, and provides configurational hooks used to map classes.

    The three general kinds of mappings supported are Declarative Base,
    Declarative Decorator, and Imperative Mapping.   All of these mapping
    styles may be used interchangeably:

    * :meth:`_orm.registry.generate_base` returns a new declarative base
      class, and is the underlying implementation of the
      :func:`_orm.declarative_base` function.

    * :meth:`_orm.registry.mapped` provides a class decorator that will
      apply declarative mapping to a class without the use of a declarative
      base class.

    * :meth:`_orm.registry.map_imperatively` will produce a
      :class:`_orm.Mapper` for a class without scanning the class for
      declarative class attributes. This method suits the use case historically
      provided by the ``sqlalchemy.orm.mapper()`` classical mapping function,
      which is removed as of SQLAlchemy 2.0.

    .. versionadded:: 1.4

    .. seealso::

        :ref:`orm_mapping_classes_toplevel` - overview of class mapping
        styles.

    zclsregistry._ClsRegistryType_class_registryz;weakref.WeakKeyDictionary[ClassManager[Any], Literal[True]]	_managersz5weakref.WeakKeyDictionary[Mapper[Any], Literal[True]]_non_primary_mappersr;   r|   z&CallableReference[Callable[..., None]]r   _MutableTypeAnnotationMapTyper   zSet[_RegistryType]_dependents_dependenciesr   _new_mappersN)r|   r7  r   r   c                  |xs
 t               }|t        j                         }|| _        t        j                         | _        t        j                         | _        || _        || _        i | _	        || j                  |       t               | _        t               | _        d| _        t        j                   5  dt        j"                  | <   ddd       y# 1 sw Y   yxY w)a  Construct a new :class:`_orm.registry`

        :param metadata:
          An optional :class:`_schema.MetaData` instance.  All
          :class:`_schema.Table` objects generated using declarative
          table mapping will make use of this :class:`_schema.MetaData`
          collection.  If this argument is left at its default of ``None``,
          a blank :class:`_schema.MetaData` collection is created.

        :param constructor:
          Specify the implementation for the ``__init__`` function on a mapped
          class that has no ``__init__`` of its own.  Defaults to an
          implementation that assigns \**kwargs for declared
          fields and relationships to an instance.  If ``None`` is supplied,
          no __init__ will be provided and construction will fall back to
          cls.__init__ by way of the normal Python semantics.

        :param class_registry: optional dictionary that will serve as the
          registry of class names-> mapped classes when string names
          are used to identify classes inside of :func:`_orm.relationship`
          and others.  Allows two or more declarative base classes
          to share the same registry of class names for simplified
          inter-base relationships.

        :param type_annotation_map: optional dictionary of Python types to
          SQLAlchemy :class:`_types.TypeEngine` classes or instances.
          The provided dict will update the default type mapping.  This
          is used exclusively by the :class:`_orm.MappedColumn` construct
          to produce column types based on annotations within the
          :class:`_orm.Mapped` type.

          .. versionadded:: 2.0

          .. seealso::

              :ref:`orm_declarative_mapped_column_type_map`


        NFT)r;   weakrefWeakValueDictionaryr<  WeakKeyDictionaryr=  r>  r|   r   r   update_type_annotation_mapsetr@  rA  rB  r   _CONFIGURE_MUTEX_mapper_registries)r   r|   r7  r   r   lcl_metadatas         r[   r   zregistry.__init__  s    ^  -8:!$88:N- 224$+$=$=$?!$&#% *++,?@5 U!''15I((. (''s   ;CC!c           	         | j                   j                  |j                         D ci c]  \  }}t        |      | c}}       yc c}}w )zQupdate the :paramref:`_orm.registry.type_annotation_map` with new
        values.N)r   r   r   rB   )r   r   typsqltypes       r[   rG  z#registry.update_type_annotation_map  sQ     	  '' %8$=$=$?$?LC +3/8$?	
s   A
c                   t        |      r5t        |      r||fgfdt        D        }n?|j                  |ff}n-t	        |t
              r|d j                  D        }n||ff}|D ]h  \  }}| j                  j                  |      }|t        j                  |      }|;t        j                  |      }|j                  ||      }|f|c S  |rd }	d }
t        |      r2|}	t        |	      r|	j                  }	t        |	      rt        |	      }	d}
t!        |      rt#        |      }	d}
|	-| j%                  |	d      }||
J t'        d|
 d| dd	       |S y )
Nc              3  &   K   | ]  }|f 
 y wr   rq   ).0ltpython_type_types     r[   	<genexpr>z)registry._resolve_type.<locals>.<genexpr>  s     E}r+,}s   c              3  $   K   | ]  }||f 
 y wr   rq   )rQ  pts     r[   rT  z)registry._resolve_type.<locals>.<genexpr>  s     B)A2r2h)As   TypeAliasTypeNewTypeFzMatching the provided z 'z' on its resolved value without matching it in the type_annotation_map is deprecated; add this type to the type_annotation_map to allow it to match explicitly.z2.0)rD   rE   rI   
__origin__r   rd   rW   r   r   r8   _type_map_getto_instance_resolve_for_python_typerG   	__value__rB   rF   rC   _resolve_typer@   )r   python_type_do_fallbackssearchrV  	flattenedsql_typesql_type_instresolved_sql_typepython_type_to_checkkindres_after_fallbackrS  s               @r[   r^  zregistry._resolve_type  s    k"+&#.  !"23E}E
 $/#9#9 &(89;T**B)9)A)ABF*"$457F#MB	//33B7H#11"5# ( 4 4X > %2$J$J$%!
 %0,,) $. (, D%'2$ 45+?+I+I(   45'A(($ '+&'6{'C$ #/%)%7%7(%&" &1+++#0b F& &
  .-r]   c                l    t        d | j                  D              j                  | j                        S )z9read only collection of all :class:`_orm.Mapper` objects.c              3  4   K   | ]  }|j                     y wr   )r6  rQ  r   s     r[   rT  z#registry.mappers.<locals>.<genexpr>(  s     F~G~s   )	frozensetr=  unionr>  r   s    r[   mapperszregistry.mappers$  s/     Ft~~FFLL%%
 	
r]   c                z    || u ry |j                   j                  |        | j                  j                  |       y r   )r@  addrA  )r   r~   s     r[   _set_depends_onzregistry._set_depends_on,  s5    t  &x(r]   c                h    d|_         | j                  ry | j                  | h      D ]	  }d|_         y NT)_ready_for_configurerB  _recurse_with_dependents)r   r6  r   s      r[   _flag_new_mapperzregistry._flag_new_mapper2  s5    &*#00$8C#C 9r]   c              #  "  K   |}t               }|r}|j                         }|j                  |       |j                  |j                  j                  |             | |j                  |j                  j                  |             |r|y y wr   )rH  poprp  r   r@  
differencerY   
registriestododoner   s        r[   ru  z!registry._recurse_with_dependents:  sq      u((*CHHSM KK22489I KK22489    B
BBc              #  "  K   |}t               }|r}|j                         }|j                  |       |j                  |j                  j                  |             | |j                  |j                  j                  |             |r|y y wr   )rH  rx  rp  r   rA  ry  rz  s        r[   _recurse_with_dependenciesz#registry._recurse_with_dependenciesM  su      u((*CHHSM KK))44T:;I KK))44T:; r~  c                    t        j                  d t        | j                        D        d t        | j                        D              S )Nc              3     K   | ]H  }|j                   r:|j                  j                  s$|j                  j                  r|j                   J y wr   )r   r6  
configuredrt  rk  s     r[   rT  z1registry._mappers_to_configure.<locals>.<genexpr>c  s?      3G$$11NN77	 3s   AAc              3  P   K   | ]  }|j                   s|j                  r|   y wr   )r  rt  )rQ  npms     r[   rT  z1registry._mappers_to_configure.<locals>.<genexpr>j  s'      :C~~#*B*B :s   $&)	itertoolschainlistr=  r>  r   s    r[   _mappers_to_configurezregistry._mappers_to_configurea  sA    #DNN3 9 9:
 	
r]   c                "    d| j                   |<   y rs  )r>  )r   	np_mappers     r[   _add_non_primary_mapperz registry._add_non_primary_mapperq  s    /3!!),r]   c                Z    t        j                  |j                  || j                         y r   )r   remove_classrn   r<  r   rY   s     r[   _dispose_clszregistry._dispose_clst  s      sD4H4HIr]   c                    d| j                   |<   |j                  r"t        j                  d|j                  z        |j
                  J | |_        y )NTz1Class '%s' already has a primary mapper defined. )r=  r   r5   ArgumentErrorrZ   r~   )r   r   s     r[   _add_managerzregistry._add_managerw  sW    "&w##C..!  '''r]   c                4    t        j                  | h|       y)a]  Configure all as-yet unconfigured mappers in this
        :class:`_orm.registry`.

        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.

        If one or more mappers in this registry contain
        :func:`_orm.relationship` constructs that refer to mapped classes in
        other registries, this registry is said to be *dependent* on those
        registries. In order to configure those dependent registries
        automatically, the :paramref:`_orm.registry.configure.cascade` flag
        should be set to ``True``. Otherwise, if they are not configured, an
        exception will be raised.  The rationale behind this behavior is to
        allow an application to programmatically invoke configuration of
        registries while controlling whether or not the process implicitly
        reaches other registries.

        As an alternative to invoking :meth:`_orm.registry.configure`, the ORM
        function :func:`_orm.configure_mappers` function may be used to ensure
        configuration is complete for all :class:`_orm.registry` objects in
        memory. This is generally simpler to use and also predates the usage of
        :class:`_orm.registry` objects overall. However, this function will
        impact all mappings throughout the running Python process and may be
        more memory/time consuming for an application that has many registries
        in use for different purposes that may not be needed immediately.

        .. seealso::

            :func:`_orm.configure_mappers`


        .. versionadded:: 1.4.0b2

        cascadeN)r   _configure_registriesr   r  s     r[   	configurezregistry.configure  s    N 	''@r]   c                4    t        j                  | h|       y)a  Dispose of all mappers in this :class:`_orm.registry`.

        After invocation, all the classes that were mapped within this registry
        will no longer have class instrumentation associated with them. This
        method is the per-:class:`_orm.registry` analogue to the
        application-wide :func:`_orm.clear_mappers` function.

        If this registry contains mappers that are dependencies of other
        registries, typically via :func:`_orm.relationship` links, then those
        registries must be disposed as well. When such registries exist in
        relation to this one, their :meth:`_orm.registry.dispose` method will
        also be called, if the :paramref:`_orm.registry.dispose.cascade` flag
        is set to ``True``; otherwise, an error is raised if those registries
        were not already disposed.

        .. versionadded:: 1.4.0b2

        .. seealso::

            :func:`_orm.clear_mappers`

        r  N)r   _dispose_registriesr  s     r[   disposezregistry.dispose  s    0 	%%tfg>r]   c                    d|j                   v r|j                  }|j                          |j                  }| j	                  |       t
        j                  j                  |       y )Nr6  )rc   r6  _set_dispose_flagsrZ   r  r   _instrumentation_factory
unregister)r   r   r6  rZ   s       r[   _dispose_manager_and_mapperz$registry._dispose_manager_and_mapper  sP    w'''^^F%%'&!00;;FCr]   r4  c                2   | j                   }t        |t               xr |fxs |}t        | |      }t        |t              r|j
                  |d<   | j                  | j                  |d<   d|d<   |r||d<   t        |d      r	d	d}||d<    ||||      S )
a	  Generate a declarative base class.

        Classes that inherit from the returned class object will be
        automatically mapped using declarative mapping.

        E.g.::

            from sqlalchemy.orm import registry

            mapper_registry = registry()

            Base = mapper_registry.generate_base()


            class MyClass(Base):
                __tablename__ = "my_table"
                id = Column(Integer, primary_key=True)

        The above dynamically generated class is equivalent to the
        non-dynamic example below::

            from sqlalchemy.orm import registry
            from sqlalchemy.orm.decl_api import DeclarativeMeta

            mapper_registry = registry()


            class Base(metaclass=DeclarativeMeta):
                __abstract__ = True
                registry = mapper_registry
                metadata = mapper_registry.metadata

                __init__ = mapper_registry.constructor

        .. versionchanged:: 2.0 Note that the
           :meth:`_orm.registry.generate_base` method is superseded by the new
           :class:`_orm.DeclarativeBase` class, which generates a new "base"
           class using subclassing, rather than return value of a function.
           This allows an approach that is compatible with :pep:`484` typing
           tools.

        The :meth:`_orm.registry.generate_base` method provides the
        implementation for the :func:`_orm.declarative_base` function, which
        creates the :class:`_orm.registry` and base class all at once.

        See the section :ref:`orm_declarative_mapping` for background and
        examples.

        :param mapper:
          An optional callable, defaults to :class:`_orm.Mapper`.
          This function is used to generate new :class:`_orm.Mapper` objects.

        :param cls:
          Defaults to :class:`object`. A type to use as the base for the
          generated declarative base class. May be a class or tuple of classes.

        :param name:
          Defaults to ``Base``.  The display name for the generated
          class.  Customizing this is not required, but can improve clarity in
          tracebacks and debugging.

        :param metaclass:
          Defaults to :class:`.DeclarativeMeta`.  A metaclass or __metaclass__
          compatible callable to use as the meta type of the generated
          declarative base class.

        .. seealso::

            :ref:`orm_declarative_mapping`

            :func:`_orm.declarative_base`

        )r~   r|   ru   r   Tr   __mapper_cls____class_getitem__c                    | S r   rq   rj   s     r[   r  z1registry.generate_base.<locals>.__class_getitem__/  s    
r]   )rY   Type[_T]rf   r   rl   r  )r|   r   tupledictrd   ru   r   r   )	r   r6  rY   r   r  r|   r   
class_dictr  s	            r[   r9  zregistry.generate_base  s    ` ==sE**5v<%)4(%K
c4 $'KKJy!'%)%5%5Jz"%)
>"+1J'(3+, /@J*+uj11r]   rv   c                     y r   rq   )r   _registry__clss     r[   mapped_as_dataclasszregistry.mapped_as_dataclass7  s	     ADr]   .r   c                    y r   rq   )
r   r  r   r   r   r   r   r   r   r   s
             r[   r  zregistry.mapped_as_dataclassG  s     *-r]   c          
     H    	 d	 f	d}
|r |
|      S |
S )a_  Class decorator that will apply the Declarative mapping process
        to a given class, and additionally convert the class to be a
        Python dataclass.

        .. seealso::

            :ref:`orm_declarative_native_dataclasses` - complete background
            on SQLAlchemy native dataclass mapping


        .. versionadded:: 2.0


        c                b   	 t        | d	d       t        | | j                         | S )Nr   r   )setattrr'   rc   )
rY   r   r   r   r   r   r   r   r   r   s
    r[   r   z.registry.mapped_as_dataclass.<locals>.decoratet  sE    )  "#.",&*<	 D#s||4Jr]   rY   Type[_O]rl   r  rq   )r   r  r   r   r   r   r   r   r   r   r   s   ` ```````` r[   r  zregistry.mapped_as_dataclassV  s"    <	 	$ E?"Or]   c                4    t        | ||j                         |S )a  Class decorator that will apply the Declarative mapping process
        to a given class.

        E.g.::

            from sqlalchemy.orm import registry

            mapper_registry = registry()


            @mapper_registry.mapped
            class Foo:
                __tablename__ = "some_table"

                id = Column(Integer, primary_key=True)
                name = Column(String)

        See the section :ref:`orm_declarative_mapping` for complete
        details and examples.

        :param cls: class to be mapped.

        :return: the class that was passed.

        .. seealso::

            :ref:`orm_declarative_mapping`

            :meth:`_orm.registry.generate_base` - generates a base class
            that will apply Declarative mapping to subclasses automatically
            using a Python metaclass.

        .. seealso::

            :meth:`_orm.registry.mapped_as_dataclass`

        )r'   rc   r  s     r[   mappedzregistry.mapped  s    L 	c3<<0
r]   c                     d fd}|S )a  
        Class decorator which will invoke
        :meth:`_orm.registry.generate_base`
        for a given base class.

        E.g.::

            from sqlalchemy.orm import registry

            mapper_registry = registry()


            @mapper_registry.as_declarative_base()
            class Base:
                @declared_attr
                def __tablename__(cls):
                    return cls.__name__.lower()

                id = Column(Integer, primary_key=True)


            class MyMappedClass(Base): ...

        All keyword arguments passed to
        :meth:`_orm.registry.as_declarative_base` are passed
        along to :meth:`_orm.registry.generate_base`.

        c                P    | d<   | j                   d<    j                  di S )NrY   r   rq   )rn   r9  )rY   r   r   s    r[   r   z.registry.as_declarative_base.<locals>.decorate  s/    BuIBvJ%4%%+++r]   rY   r  rl   r  rq   )r   r   r   s   `` r[   as_declarative_basezregistry.as_declarative_base  s    <	,
 r]   c                H    t        | ||j                         |j                  S )a  Map a class declaratively.

        In this form of mapping, the class is scanned for mapping information,
        including for columns to be associated with a table, and/or an
        actual table object.

        Returns the :class:`_orm.Mapper` object.

        E.g.::

            from sqlalchemy.orm import registry

            mapper_registry = registry()


            class Foo:
                __tablename__ = "some_table"

                id = Column(Integer, primary_key=True)
                name = Column(String)


            mapper = mapper_registry.map_declaratively(Foo)

        This function is more conveniently invoked indirectly via either the
        :meth:`_orm.registry.mapped` class decorator or by subclassing a
        declarative metaclass generated from
        :meth:`_orm.registry.generate_base`.

        See the section :ref:`orm_declarative_mapping` for complete
        details and examples.

        :param cls: class to be mapped.

        :return: a :class:`_orm.Mapper` object.

        .. seealso::

            :ref:`orm_declarative_mapping`

            :meth:`_orm.registry.mapped` - more common decorator interface
            to this function.

            :meth:`_orm.registry.map_imperatively`

        )r'   rc   rb   r  s     r[   map_declarativelyzregistry.map_declaratively  s    ^ 	c3<<0~~r]   c                    t        | |||      S )a  Map a class imperatively.

        In this form of mapping, the class is not scanned for any mapping
        information.  Instead, all mapping constructs are passed as
        arguments.

        This method is intended to be fully equivalent to the now-removed
        SQLAlchemy ``mapper()`` function, except that it's in terms of
        a particular registry.

        E.g.::

            from sqlalchemy.orm import registry

            mapper_registry = registry()

            my_table = Table(
                "my_table",
                mapper_registry.metadata,
                Column("id", Integer, primary_key=True),
            )


            class MyClass:
                pass


            mapper_registry.map_imperatively(MyClass, my_table)

        See the section :ref:`orm_imperative_mapping` for complete background
        and usage examples.

        :param class\_: The class to be mapped.  Corresponds to the
         :paramref:`_orm.Mapper.class_` parameter.

        :param local_table: the :class:`_schema.Table` or other
         :class:`_sql.FromClause` object that is the subject of the mapping.
         Corresponds to the
         :paramref:`_orm.Mapper.local_table` parameter.

        :param \**kw: all other keyword arguments are passed to the
         :class:`_orm.Mapper` constructor directly.

        .. seealso::

            :ref:`orm_imperative_mapping`

            :ref:`orm_declarative_mapping`

        r,   )r   rZ   local_tabler   s       r[   map_imperativelyzregistry.map_imperatively  s    p tV["55r]   )r|   Optional[MetaData]r7  &Optional[clsregistry._ClsRegistryType]r    Optional[_TypeAnnotationMapType]r   Callable[..., None])r   _TypeAnnotationMapTyperl   rm   )T)r_  rQ   r`  r   rl   z"Optional[sqltypes.TypeEngine[Any]])rl   zFrozenSet[Mapper[Any]])r~   r}   rl   rm   )r6  Mapper[Any]rl   rm   )r{  zSet[RegistryType]rl   zIterator[RegistryType])rl   zIterator[Mapper[Any]])r  r  rl   rm   )rY   r  rl   rm   )r   zClassManager[Any]rl   rm   r   )r  r   rl   rm   )
r6  $Optional[Callable[..., Mapper[Any]]]rY   	Type[Any]r   rk   r  r  rl   r   )r  r  rl   r  ).)r  zLiteral[None]r   r	  r   r	  r   r	  r   r	  r   r	  r   r	  r   r	  r   r
  rl   zCallable[[Type[_O]], Type[_O]]r   )r  zOptional[Type[_O]]r   r	  r   r	  r   r	  r   r	  r   r	  r   r	  r   r	  r   r
  rl   z/Union[Type[_O], Callable[[Type[_O]], Type[_O]]]r  r   r   rl   zCallable[[Type[_T]], Type[_T]])rY   r  rl   
Mapper[_O])rZ   r  r  r+  r   r   rl   r  )-rn   ro   rp   ru   r   r)   r   rG  r^  propertyrn  rq  rv  r   ru  r  r  r  r  r  r  r  r  r   r{   r9  compat_typingdataclass_transformr1   r2   r.   r/   r   r   r   r   r   r   r  r9   r   r  r  r  r  rq   r]   r[   r~   r~   V  sk   @ 21JJOO7766##%%
 (,AE@D+CB6 %B6 ?	B6
 >B6 )B6H
3
 

 BFO)O:>O	+Ob 
 
)$ :*:	: :$ <*<	< <&
 4J 'AR?4D 8<.g24g2 g2 	g2
 g2 
g2R ']&& 

 C  D  #- %($'"%%(+.*-'*FI-- "	-
 "-  - #- )- (- %- D- 
(- -  %)3 %+MM$*MM"(--%+]]+1==*0--'-}} MM3!3 "	3
 "3  3 #3 )3 (3 %3
3 
93j'R#J0j -18686 *86 	86
 
86r]   r~   c                     | j                  dd      | j                  dd      }} t        ||      j                  di | S )a  
    Class decorator which will adapt a given class into a
    :func:`_orm.declarative_base`.

    This function makes use of the :meth:`_orm.registry.as_declarative_base`
    method, by first creating a :class:`_orm.registry` automatically
    and then invoking the decorator.

    E.g.::

        from sqlalchemy.orm import as_declarative


        @as_declarative()
        class Base:
            @declared_attr
            def __tablename__(cls):
                return cls.__name__.lower()

            id = Column(Integer, primary_key=True)


        class MyMappedClass(Base): ...

    .. seealso::

        :meth:`_orm.registry.as_declarative_base`

    r|   Nr7  )r|   r7  rq   )rx  r~   r  )r   r|   r7  s      r[   as_declarativer  M  sQ    > 	z4 
& H
8.    r]   c                t    t        |       }|*t        j                  |       rt        j                  |        |S r   )r!   r*   has_clsraise_unmapped_for_cls)rY   mps     r[   _inspect_decl_metar  u  s4     !6c :B	z ((-!88=Ir]   )rY   r  rl   r   r   )r   rk   r   r   rl   z,Callable[[Callable[..., Any]], Synonym[Any]]r  )rY   r  rl   rm   )rY   r  r'  r  rl   rm   )r1  r  rf   rk   r2  zMapperProperty[Any]rl   rm   )r|   r  r6  r  rY   r  r   rk   r7  r  r   r  r   r  r  r  rl   r   r  )rY   r  rl   zOptional[Mapper[Any]])ru   
__future__r   r  r   r?   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   rD   r   r   r   r   r   _orm_constructorsr   r   r   r   r   r    r'  r!   r"   r#   r$   	decl_baser&   r'   r(   r)   r*   r+   r-   descriptor_propsr.   r/   r   r6  r0   
propertiesr1   relationshipsr2   stater3   r5   r6   r7   sqlr8   sql.baser9   sql.elementsr:   
sql.schemar;   sql.selectabler<   r=   r>   r  r@   util.typingrA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   _typingrK   rL   rM   rN   rO   sql._typingrP   sql.type_apirQ   rR   rT   r  r?  _DeclaredAttrDecoratedr\   rd   r_   Inspectablers   r  ry   r{   r   r   r   _MappedAttributer   r   r   r   r   r  r   r*  r3  r   r:  r~   r}   r  	_inspectsr  rq   r]   r[   <module>r     s   8 "  	                          ( ' , + & - ' "   % & - / , %  ' % 5  $ /        , ! '  ! * " + 4 ) $ $ $ # ! ' &.-*$1-Te3 !&@!@A  $S*D%D E !vbz=,.?.CC	DD 
&'T '	6#;'	 #""
8: 8843 4> #('
''1'T> >B/ ,E-J//35J E-P,mB/ , )X&0R>"8 >BR(=-.+R(j
h(=-.h(V&&&&9&	&* $(37=A<@'?*x x 1x 
	x
 x ;x :x %x x 	xvm6 m6` M% P _&Cr]   