
    -h                     .   S r SSKJr  SSK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 r! " S S\"5      r#S*S jr$ " S S\RJ                  \&5      r' " S S \'5      r(S! r)SSS\*S"\S\#4S# jr+ " S$ S%\*5      r,\," 5       \l-        \R\                  " S&S'9S( 5       r/\R`                  " \#5      S) 5       r1g)+z1Public API functions and helpers for declarative.    )absolute_importN   )
attributes)clsregistry)exc)instrumentation)
interfacesmapper)_inspect_mapped_class_add_attribute)_as_declarative)_declarative_constructor)_DeferredMapperConfig_del_attribute_mapper)SynonymProperty   )
inspection)util)MetaData)hybridmethod)hybridpropertyc                 P    U R                   SS  H  n[        USS5      c  M    g   g)a/  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     lC:\Users\ROHAN GUPTA\OneDrive\Desktop\mathbuddy-assessment\venv\Lib\site-packages\sqlalchemy/orm/decl_api.pyhas_inherited_tabler$   $   s/     ++ab/6;-9 "     c                   &    \ rS rSrS rS rS rSrg)DeclarativeMeta7   c                 H   U R                   n[        U SS 5      nUcC  UR                  SS 5      n[        U[        5      (       d  [
        R                  " S5      eXPl        U R                   R                  SS5      (       d  [        XPU5        [        R                  XX#5        g )N_sa_registryregistryziDeclarative base class has no 'registry' attribute, or registry is not a sqlalchemy.orm.registry() object__abstract__F)__dict__r    get
isinstancer+   r   InvalidRequestErrorr*   r   type__init__)r!   	classnamebasesdict_kwregs         r#   r2   DeclarativeMeta.__init__8   s     
 c>40;))J-Cc8,,--L 
 $' ||66Ce,ce3r%   c                     [        XU5        g Nr   )r!   keyvalues      r#   __setattr__DeclarativeMeta.__setattr__O   s    s'r%   c                     [        X5        g r:   r   r!   r;   s     r#   __delattr__DeclarativeMeta.__delattr__R   s
    s r%    N)__name__
__module____qualname____firstlineno__r2   r=   rA   __static_attributes__rC   r%   r#   r'   r'   7   s    4.(!r%   r'   c                    ^ ^ UU 4S jnU$ )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TU S9$ )N)
map_column
descriptor)_orm_synonym)fnrK   names    r#   decoratesynonym_for.<locals>.decoratex   s    DZBGGr%   rC   )rO   rK   rP   s   `` r#   synonym_forrR   V   s    DH Or%   c                   V   ^  \ rS rSrSrSU 4S jjrS r\S 5       r\	S 5       r
SrU =r$ )	declared_attr~   ai  Mark a class-level method as representing the definition of
a mapped property or special declarative member name.

: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 mixins, to define
relationships that are to be applied to different implementors of the
class. It is also used to define :class:`_schema.Column` objects that
include the :class:`_schema.ForeignKey` construct, as these cannot be
easily reused across different mappings.  The example below illustrates
both::

    class ProvidesUser(object):
        "A mixin that adds a 'user' relationship to classes."

        @declared_attr
        def user_id(self):
            return Column(ForeignKey("user_account.id"))

        @declared_attr
        def user(self):
            return relationship("User")

:class:`_orm.declared_attr` can also be applied to mapped classes, such as
to provide a "polymorphic" scheme for inheritance::

    class Employee(Base):
        id = Column(Integer, primary_key=True)
        type = Column(String(50), nullable=False)

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

        @declared_attr
        def __mapper_args__(cls):
            if cls.__name__ == 'Employee':
                return {
                        "polymorphic_on":cls.type,
                        "polymorphic_identity":"Employee"
                }
            else:
                return {"polymorphic_identity":cls.__name__}

To use :class:`_orm.declared_attr` inside of a Python dataclass
as discussed at :ref:`orm_declarative_dataclasses_declarative_table`,
it may be placed directly inside the field metadata using a lambda::

    @dataclass
    class AddressMixin:
        __sa_dataclass_metadata_key__ = "sa"

        user_id: int = field(
            init=False, metadata={"sa": declared_attr(lambda: Column(ForeignKey("user.id")))}
        )
        user: User = field(
            init=False, metadata={"sa": declared_attr(lambda: relationship(User))}
        )

:class:`_orm.declared_attr` also may be omitted from this form using a
lambda directly, as in::

    user: User = field(
        init=False, metadata={"sa": lambda: relationship(User)}
    )

.. seealso::

    :ref:`orm_mixins_toplevel` - illustrates how to use Declarative Mixins
    which is the primary use case for :class:`_orm.declared_attr`

    :ref:`orm_declarative_dataclasses_mixin` - illustrates special forms
    for use with Python dataclasses

c                 Z   > [         [        U ]  U5        UR                  U l        X l        g r:   )superrT   r2   __doc__
_cascading)selffget	cascading	__class__s      r#   r2   declared_attr.__init__   s"    mT+D1||#r%   c                    [         R                  " U5      nUc}  [        R                  " SU R                  R
                  5      (       d<  [        R                  " SU R                  R
                  < SUR
                  < 35        U R	                  U5      $ UR                  (       a  U R	                  U5      $ UR                  5       nUc   eUR                  nX;   a  XP   $ U R	                  U5      =XP'   nU$ )Nz^__.+__$z*Unmanaged access of declarative attribute z from non-mapped class )r   manager_of_classrematchr[   rD   r   warn	is_mappeddeclarative_scandeclared_attr_reg)descrZ   r!   managerre   r7   objs          r#   __get__declared_attr.__get__   s     --c2?88K););<< 		-1YY-?-?O 99S>! 99S>! #335+++00;9"iin,CIJr%   c                     [        S0 UD6$ NrC   )_stateful_declared_attr)r!   r6   s     r#   	_statefuldeclared_attr._stateful   s    &,,,r%   c                      U R                  SS9$ )a7  Mark a :class:`.declared_attr` as cascading.

This is a special-use modifier which indicates that a column
or MapperProperty-based declared attribute should be configured
distinctly per mapped subclass, within a mapped-inheritance scenario.

.. warning::

    The :attr:`.declared_attr.cascading` modifier has several
    limitations:

    * The flag **only** applies to the use of :class:`.declared_attr`
      on declarative mixin classes and ``__abstract__`` classes; it
      currently has no effect when used on a mapped class directly.

    * The flag **only** applies to normally-named attributes, e.g.
      not any special underscore attributes such as ``__tablename__``.
      On these attributes it has **no** effect.

    * The flag currently **does not allow further overrides** down
      the class hierarchy; if a subclass tries to override the
      attribute, a warning is emitted and the overridden attribute
      is skipped.  This is a limitation that it is hoped will be
      resolved at some point.

Below, both MyClass as well as MySubClass will have a distinct
``id`` Column object established::

    class HasIdMixin(object):
        @declared_attr.cascading
        def id(cls):
            if has_inherited_table(cls):
                return Column(
                    ForeignKey('myclass.id'), primary_key=True
                )
            else:
                return Column(Integer, primary_key=True)

    class MyClass(HasIdMixin, Base):
        __tablename__ = 'myclass'
        # ...

    class MySubClass(MyClass):
        ""
        # ...

The behavior of the above configuration is that ``MySubClass``
will refer to both its own ``id`` column as well as that of
``MyClass`` underneath the attribute named ``some_id``.

.. seealso::

    :ref:`declarative_inheritance`

    :ref:`mixin_inheritance_columns`


T)r\   )ro   r!   s    r#   r\   declared_attr.cascading   s    x }}t},,r%   )rX   rY   F)rD   rE   rF   rG   rX   r2   rj   r   ro   r   r\   rH   __classcell__)r]   s   @r#   rT   rT   ~   s<    Pd$
> - - ;- ;-r%   rT   c                   &    \ rS rSrS rS rS rSrg)rn   i8  c                     Xl         g r:   r6   )rZ   r6   s     r#   r2    _stateful_declared_attr.__init__9  s    r%   c                 n    U R                   R                  5       nUR                  U5        [        S0 UD6$ rm   )r6   copyupdatern   )rZ   r6   new_kws      r#   ro   !_stateful_declared_attr._stateful<  s+    b&000r%   c                 .    [        U40 U R                  D6$ r:   )rT   r6   )rZ   rN   s     r#   __call__ _stateful_declared_attr.__call__A  s    R+477++r%   rx   N)rD   rE   rF   rG   r2   ro   r   rH   rC   r%   r#   rn   rn   8  s    1
,r%   rn   c                     U $ )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>`

rC   rr   s    r#   declarative_mixinr   E  s
    N Jr%   Basec                 l    U b  [         R                  " S5        [        U UUUS9R                  UUUUS9$ )aZ  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 :func:`~sqlalchemy.orm.mapper` calls based on the
information provided declaratively in the class and any subclasses
of the class.

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 bind: An optional
  :class:`~sqlalchemy.engine.Connectable`, will be assigned
  the ``bind`` attribute on the :class:`~sqlalchemy.schema.MetaData`
  instance.

  .. deprecated:: 1.4  The "bind" argument to declarative_base is
     deprecated and will be removed in SQLAlchemy 2.0.

: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 :func:`~sqlalchemy.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 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`

z^The ``bind`` argument to declarative_base is deprecated and will be removed in SQLAlchemy 2.0.)_bindmetadataclass_registryconstructor)r   r!   rO   	metaclass)r   warn_deprecated_20r+   generate_base)bindr   r   r!   rO   r   r   r   s           r#   declarative_baser   o  sW    D @	

 %	
 m	  
r%   c                       \ rS rSrSrSS\S4S jr\S 5       rS r	S r
\S 5       r\S	 5       rS
 rS rS rS rSS jrSS jrS rS\S\4S jrS rS rS rSS jrSrg)r+   i  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
  :func:`_orm.mapper` classical mapping function.

.. versionadded:: 1.4

.. seealso::

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

Nc                    U=(       d
    [        5       nU(       a  XEl        Uc  [        R                  " 5       nX l        [        R
                  " 5       U l        [        R
                  " 5       U l        XPl        X0l	        [        5       U l        [        5       U l        SU l        [        R                     S[        R                   U '   SSS5        g! , (       d  f       g= f)aM  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.

NFT)r   r   weakrefWeakValueDictionary_class_registryWeakKeyDictionary	_managers_non_primary_mappersr   r   set_dependents_dependencies_new_mappers	mapperlib_CONFIGURE_MUTEX_mapper_registries)rZ   r   r   r   r   lcl_metadatas         r#   r2   registry.__init__  s    @  -8: %!$88:N- 224$+$=$=$?!$&5 U!''15I((. (''s   4C
Cc                 l    [        S U R                   5       5      R                  U R                  5      $ )z9read only collection of all :class:`_orm.Mapper` objects.c              3   8   #    U  H  oR                   v   M     g 7fr:   r
   .0rh   s     r#   	<genexpr>#registry.mappers.<locals>.<genexpr>?  s     F~G~s   )	frozensetr   unionr   rZ   s    r#   mappersregistry.mappers;  s/     Ft~~FFLL%%
 	
r%   c                 z    XL a  g UR                   R                  U 5        U R                  R                  U5        g r:   )r   addr   )rZ   r+   s     r#   _set_depends_onregistry._set_depends_onC  s3      &x(r%   c                 v    SUl         U R                  (       a  g U R                  U 15       H
  nSUl        M     g NT)_ready_for_configurer   _recurse_with_dependents)rZ   r   r7   s      r#   _flag_new_mapperregistry._flag_new_mapperI  s5    &*#00$8C#C 9r%   c              #   8  #    Un[        5       nU(       a  UR                  5       nUR                  U5        UR                  UR                  R                  U5      5        Uv   UR                  UR                  R                  U5      5        U(       a  M  g g 7fr:   )r   popr   r|   r   
differencer!   
registriestododoner7   s        r#   r   !registry._recurse_with_dependentsQ  sp     u((*CHHSM KK22489I KK22489 d   BBBc              #   8  #    Un[        5       nU(       a  UR                  5       nUR                  U5        UR                  UR                  R                  U5      5        Uv   UR                  UR                  R                  U5      5        U(       a  M  g g 7fr:   )r   r   r   r|   r   r   r   s        r#   _recurse_with_dependencies#registry._recurse_with_dependenciesb  st     u((*CHHSM KK))44T:;I KK))44T:; dr   c                     [         R                  " S [        U R                  5       5       S [        U R                  5       5       5      $ )Nc              3      #    U  H^  nUR                   (       d  M  UR                  R                  (       a  M3  UR                  R                  (       d  MP  UR                  v   M`     g 7fr:   )rd   r   
configuredr   r   s     r#   r   1registry._mappers_to_configure.<locals>.<genexpr>v  sN      3G$$   11  NN77	 3s   A(A(A(A(c              3   r   #    U  H-  nUR                   (       a  M  UR                  (       d  M)  Uv   M/     g 7fr:   )r   r   )r   npms     r#   r   r   }  s.      :C~~ *-*B*B :s   77	7)	itertoolschainlistr   r   r   s    r#   _mappers_to_configureregistry._mappers_to_configuret  sA    #DNN3 9 9:
 	
r%   c                 "    SU R                   U'   g r   )r   )rZ   	np_mappers     r#   _add_non_primary_mapper registry._add_non_primary_mapper  s    /3!!),r%   c                 Z    [         R                  " UR                  XR                  5        g r:   )r   remove_classrD   r   rZ   r!   s     r#   _dispose_clsregistry._dispose_cls  s      s4H4HIr%   c                     SU R                   U'   UR                  b4  UR                  (       a#  [        R                  " SUR
                  -  5      eXl        g )NTz1Class '%s' already has a primary mapper defined. )r   r+   rd   r   ArgumentErrorr"   )rZ   rh   s     r#   _add_managerregistry._add_manager  sN    "&w'G,=,=##C..!   r%   c                 0    [         R                  " U 1US9  g)au  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rZ   r   s     r#   	configureregistry.configure  s    N 	''@r%   c                 0    [         R                  " U 1US9  g)a6  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#   disposeregistry.dispose  s    0 	%%tfg>r%   c                     SUR                   ;   a  UR                  nUR                  5         UR                  nU R	                  U5        [
        R                  R                  U5        g )Nr   )r-   r   _set_dispose_flagsr"   r   r   _instrumentation_factory
unregister)rZ   rh   r   r"   s       r#   _dispose_manager_and_mapper$registry._dispose_manager_and_mapper  sP    w'''^^F%%'&!00;;FCr%   r   c                 f   U R                   n[        U[        5      (       + =(       a    U4=(       d    Un[        XS9n[        U[        5      (       a  UR
                  US'   U R                  (       a  U R                  US'   SUS'   U(       a  XS'   [        US5      (       a  S nXS'   U" X6U5      $ )	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

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 :func:`~sqlalchemy.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   rX   r2   Tr,   __mapper_cls____class_getitem__c                     U $ r:   rC   r@   s     r#   r   1registry.generate_base.<locals>.__class_getitem__8  s    
r%   )r   r/   tupledictr1   rX   r   hasattr)	rZ   r   r!   rO   r   r   r4   
class_dictr   s	            r#   r   registry.generate_base  s    N ==sE**5v<4;
c4  $'KKJy!%)%5%5Jz"%)
>"+1'(3+,, /@*+j11r%   c                 2    [        XUR                  5        U$ )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.

r   r-   r   s     r#   mappedregistry.mapped@  s    B 	3<<0
r%   c                    ^ ^ UU 4S jnU$ )a7  
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(object):
        @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   > U TS'   U R                   TS'   TR                  " S0 TD6$ )Nr!   rO   rC   )rD   r   )r!   r6   rZ   s    r#   rP   .registry.as_declarative_base.<locals>.decorate  s-    BuIBvJ%%+++r%   rC   )rZ   r6   rP   s   `` r#   as_declarative_baseregistry.as_declarative_based  s    8	,
 r%   c                 .    [        XUR                  5      $ )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   r   s     r#   map_declarativelyregistry.map_declaratively  s    Z t#,,77r%   c                     [        XX#5      $ )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 classic
SQLAlchemy :func:`_orm.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
 :func:`_orm.mapper` function directly.

.. seealso::

    :ref:`orm_imperative_mapping`

    :ref:`orm_declarative_mapping`

r   )rZ   r"   local_tabler6   s       r#   map_imperativelyregistry.map_imperatively  s    b t[55r%   )r   r   r   r   r   r   r   r   rt   r:   )rD   rE   rF   rG   rX   r   r2   propertyr   r   r   classmethodr   r   r   r   r   r   r   r   r   objectr'   r   r   r   r   r  rH   rC   r%   r#   r+   r+     s    D ,36j 
 
)$ : :  < <"
 4J 'AR?4D !^2@"H!F-8^16r%   r+   )z2.0z\The ``bind`` argument to as_declarative is deprecated and will be removed in SQLAlchemy 2.0.)r   c                      U R                  SS5      U R                  SS5      U R                  SS5      p2n[        XUS9R                  " S0 U D6$ )ab  
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(object):
        @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   Nr   r   )r   r   r   rC   )r   r+   r   )r6   r   r   r   s       r#   as_declarativer    sc    H 	vt
z4 
& #D n     r%   c                     [        U 5      nUc]  [        R                  " U 5      (       aB  [        R                  " U 5        [        R
                  " U S[        R                  " U 5      -  S9eU$ )NzOClass %s has a deferred mapping on it.  It is not yet usable as a mapped class.)msg)r   r   has_clsraise_unmapped_for_clsorm_excUnmappedClassError_safe_cls_name)r!   mps     r#   _inspect_decl_metar    sf    	s	#B	z ((--!88=,,,.5.D.DS.IJ 
 Ir%   rt   )2rX   
__future__r   r   ra   r    r   r   r   r  r   r	   r   r   baser   	decl_baser   r   r   r   r   r   descriptor_propsr   rM   r   r   
sql.schemar   r   r   r$   r1   r'   rR   _MappedAttributer  rT   rn   r   r  r   r+   _legacy_registrydeprecated_paramsr  	_inspectsr  rC   r%   r#   <module>r     s   8 &  	       ! ' % & / , %  =    !  !&!d !>%Pw-J// w-t
,m 
,'V 
	(slB6v B6J &Z	  
$ $ N o&
 '
r%   