a
    `g,                     @  s   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 ejrNddlmZ G dd dZG dd	 d	ZG d
d deZG dd dZG dd deZG dd dZdddddZdddddZG dd deee	jZG dd dee	jZdS )    )annotationsN   )Query)
SQLAlchemyc                   @  s"   e Zd ZdZddddddZdS )	_QueryPropertyzRA class property that creates a query object for a model.

    :meta private:
    zModel | Noneztype[Model]r   )objclsreturnc                 C  s   |j ||j dS )N)session)query_class__fsa__r
   )selfr   r    r   d/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/flask_sqlalchemy/model.py__get__   s    
z_QueryProperty.__get__N)__name__
__module____qualname____doc__r   r   r   r   r   r      s   r   c                   @  sB   e Zd ZU dZded< eZded< e Zded< dd	d
dZ	dS )Modela  The base class of the :attr:`.SQLAlchemy.Model` declarative model class.

    To define models, subclass :attr:`db.Model <.SQLAlchemy.Model>`, not this. To
    customize ``db.Model``, subclass this and pass it as ``model_class`` to
    :class:`.SQLAlchemy`. To customize ``db.Model`` at the metaclass level, pass an
    already created declarative model class as ``model_class``.
    zt.ClassVar[SQLAlchemy]r   zt.ClassVar[type[Query]]r   zt.ClassVar[Query]querystr)r	   c                 C  sp   t | }|d usJ |jr.dt|  d}n*|jrFdt|  d}ndtt|j}dt	| j
 d| dS )Nz(transient )z	(pending z, < >)sainspect	transientidpendingjoinmapr   identitytyper   )r   statepkr   r   r   __repr__8   s    
zModel.__repr__N)
r   r   r   r   __annotations__r   r   r   r   r'   r   r   r   r   r      s
   
	r   c                      s@   e Zd ZU dZded< ded< dddd	d
d fddZ  ZS )BindMetaMixina  Metaclass mixin that sets a model's ``metadata`` based on its ``__bind_key__``.

    If the model sets ``metadata`` or ``__table__`` directly, ``__bind_key__`` is
    ignored. If the ``metadata`` is the same as the parent model, it will not be set
    directly on the child model.
    r   r   sa.MetaDatametadatar   tuple[type, ...]dict[str, t.Any]t.AnyNonenamebasesdkwargsr	   c                   sb   d| j v sFd| j v sFt| dd }t| dd }| j|}||urF|| _t j|||fi | d S Nr+   	__table__Z__bind_key__)__dict__getattrr   _make_metadatar+   super__init__)r   r1   r2   r3   r4   bind_keyparent_metadatar+   	__class__r   r   r;   Q   s    zBindMetaMixin.__init__)r   r   r   r   r(   r;   __classcell__r   r   r>   r   r)   F   s   
r)   c                      s@   e Zd ZU dZded< ded< edddd	 fd
dZ  ZS )	BindMixina  DeclarativeBase mixin to set a model's ``metadata`` based on ``__bind_key__``.

    If no ``__bind_key__`` is specified, the model will use the default metadata
    provided by ``DeclarativeBase`` or ``DeclarativeBaseNoMeta``.
    If the model doesn't set ``metadata`` or ``__table__`` directly
    and does set ``__bind_key__``, the model will use the metadata
    for the specified bind key.
    If the ``metadata`` is the same as the parent model, it will not be set
    directly on the child model.

    .. versionchanged:: 3.1.0
    r   r   r*   r+   zt.Type[BindMixin]t.Dict[str, t.Any]r/   r   r4   r	   c                   sf   d| j v sPd| j v sPt| drPt| dd }t| dd }| j|}||urP|| _t jf i | d S r5   )r7   hasattrr8   r   r9   r+   r:   __init_subclass__)r   r4   r<   r=   r+   r>   r   r   rE   p   s    zBindMixin.__init_subclass__)r   r   r   r   r(   classmethodrE   r@   r   r   r>   r   rA   _   s
   
rA   c                      sZ   e Zd ZU dZded< ded< ded< ddd	d
dd fddZd
d
ddddZ  ZS )NameMetaMixinaP  Metaclass mixin that sets a model's ``__tablename__`` by converting the
    ``CamelCase`` class name to ``snake_case``. A name is set for non-abstract models
    that do not otherwise define ``__tablename__``. If a model does not define a primary
    key, it will not generate a name or ``__table__``, for single-table inheritance.
    r*   r+   r   __tablename__sa.Tabler6   r,   r-   r.   r/   r0   c                   sV   t | rt| j| _t j|||fi | d| jvrRd| jv rR| jd d u rR| `d S NrH   r6   )should_set_tablenamecamel_to_snake_caser   rH   r:   r;   r7   r6   )r   r1   r2   r3   r4   r>   r   r   r;      s    zNameMetaMixin.__init__sa.Table | Noneargsr4   r	   c                 O  s   | d}|du r|d }n| d|d  }|| jjv rJtj|i |S |D ]6}t|tjrd|jspt|tjrNtj|i |  S qN| j	dd D ]}d|j
v r qqtj|i |S d| j
v r| `dS 	a  This is called by SQLAlchemy during mapper setup. It determines the final
        table object that the model will use.

        If no primary key is found, that indicates single-table inheritance, so no table
        will be created and ``__tablename__`` will be unset.
        schemaNr   .r   r6   rH   getr+   Ztablesr   Table
isinstanceColumnZprimary_keyZPrimaryKeyConstraint__mro__r7   rH   r   rO   r4   rQ   keyargbaser   r   r   __table_cls__   s$    



zNameMetaMixin.__table_cls__)r   r   r   r   r(   r;   r^   r@   r   r   r>   r   rG      s   
rG   c                      s^   e Zd ZU dZded< ded< ded< edd	d
d fddZeddddddZ  ZS )	NameMixinau  DeclarativeBase mixin that sets a model's ``__tablename__`` by converting the
    ``CamelCase`` class name to ``snake_case``. A name is set for non-abstract models
    that do not otherwise define ``__tablename__``. If a model does not define a primary
    key, it will not generate a name or ``__table__``, for single-table inheritance.

    .. versionchanged:: 3.1.0
    r*   r+   r   rH   rI   r6   zt.Type[NameMixin]rB   r/   rC   c                   sP   t | rt| j| _t jf i | d| jvrLd| jv rL| jd d u rL| `d S rJ   )rK   rL   r   rH   r:   rE   r7   r6   )r   r4   r>   r   r   rE      s    zNameMixin.__init_subclass__r.   rM   rN   c                 O  s   | d}|du r|d }n| d|d  }|| jjv rJtj|i |S |D ]6}t|tjrd|jspt|tjrNtj|i |  S qN| j	dd D ]}d|j
v r qqtj|i |S d| j
v r| `dS rP   rT   rZ   r   r   r   r^      s$    



zNameMixin.__table_cls__)	r   r   r   r   r(   rF   rE   r^   r@   r   r   r>   r   r_      s   
r_   r$   bool)r   r	   c                 C  s   | j ddsPt| tjtjfs<tdd | jdd D rPtdd | jD rTdS | jD ]j}d|j vrjqZt	|j d tj
r dS || u p|j ddpt	|tjpt	|tjjpt|tj    S d	S )
a  Determine whether ``__tablename__`` should be generated for a model.

    -   If no class in the MRO sets a name, one should be generated.
    -   If a declared attr is found, it should be used instead.
    -   If a name is found, it should be used if the class is a mixin, otherwise one
        should be generated.
    -   Abstract models should not have one generated.

    Later, ``__table_cls__`` will determine if the model looks like single or
    joined-table inheritance. If no primary key is found, the name will be unset.
    Z__abstract__Fc                 s  s   | ]}t |tjV  qd S N)rW   sa_ormDeclarativeMeta.0br   r   r   	<genexpr>      z'should_set_tablename.<locals>.<genexpr>r   Nc                 s  s"   | ]}|t ju p|t ju V  qd S ra   )rb   DeclarativeBaseDeclarativeBaseNoMetard   r   r   r   rg     s   rH   T)r7   rU   
issubclassrb   ri   rj   anyrY   	__bases__rW   Zdeclared_attrrc   Zdecl_apiZDeclarativeAttributeIntercept)r   r]   r   r   r   rK     s4    


rK   r   )r1   r	   c                 C  s   t dd| } |  dS )z/Convert a ``CamelCase`` name to ``snake_case``.z(((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))z_\1_)resublowerlstrip)r1   r   r   r   rL   ;  s    rL   c                   @  s   e Zd ZdZdS )DefaultMetagSQLAlchemy declarative metaclass that provides ``__bind_key__`` and
    ``__tablename__`` support.
    Nr   r   r   r   r   r   r   r   rs   A  s   rs   c                   @  s   e Zd ZdZdS )DefaultMetaNoNamert   Nru   r   r   r   r   rv   G  s   rv   )
__future__r   ro   typingtZ
sqlalchemyr   Zsqlalchemy.ormZormrb   r   r   TYPE_CHECKING	extensionr   r   r   r$   r)   rA   rG   r_   rK   rL   rc   rs   rv   r   r   r   r   <module>   s"   + EG0