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

    :meta private:
    objModel | Noneclstype[Model]returnr   c                ^    |                     ||j                                                  S )N)session)query_class__fsa__r   )selfr	   r   s      e/var/www/api.easyaligner.net/htdocs/venv_linux/lib/python3.11/site-packages/flask_sqlalchemy/model.py__get__z_QueryProperty.__get__   s0    ,,..  
 
 	
    N)r	   r
   r   r   r   r   )__name__
__module____qualname____doc__r    r   r   r   r      s2         

 
 
 
 
 
r   r   c                  X    e Zd ZU dZded<   	 eZded<   	  e            Zde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]queryr   strc                .   t          j        |           }|J |j        rdt          |            d}nH|j        rd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pks      r   __repr__zModel.__repr__8   s    
4     ? 	5*r$xx***BB] 	5(RXX(((BB3sEN3344B.4::&......r   N)r   r   )
r   r   r   r   __annotations__r   r   r   r   r/   r   r   r   r   r      s           $###
 ,1K0000  .~//E///// / / / / /r   r   c                  :     e Zd ZU dZded<   ded<   d fdZ x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metadatanamer   basestuple[type, ...]ddict[str, t.Any]kwargst.Anyr   Nonec                    d| j         v sPd| j         v sGt          | dd           }t          | dd           }| j                            |          }||ur|| _         t                      j        |||fi | d S )Nr4   	__table____bind_key__)__dict__getattrr   _make_metadatar4   super__init__)	r   r5   r6   r8   r:   bind_keyparent_metadatar4   	__class__s	           r   rD   zBindMetaMixin.__init__Q   s     cl**kS\.I.IsND99H%c:t<<O{11(;;H..'ua22622222r   
r5   r   r6   r7   r8   r9   r:   r;   r   r<   )r   r   r   r   r0   rD   __classcell__rG   s   @r   r2   r2   F   sc           3 3 3 3 3 3 3 3 3 3r   r2   c                  J     e Zd ZU dZded<   ded<   ed fd            Z x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   r3   r4   r   t.Type[BindMixin]r:   t.Dict[str, t.Any]r   r<   c                   d| j         v s`d| j         v sWt          | d          rGt          | dd           }t          | dd           }| j                            |          }||ur|| _         t                      j        di | d S )Nr4   r>   r?   r   )r@   hasattrrA   r   rB   r4   rC   __init_subclass__)r   r:   rE   rF   r4   rG   s        r   rQ   zBindMixin.__init_subclass__p   s    cl**kS\.I.IwP
 P
.I sND99H%c:t<<O{11(;;H..'!!++F+++++r   )r   rM   r:   rN   r   r<   )r   r   r   r   r0   classmethodrQ   rI   rJ   s   @r   rL   rL   _   sm           , , , , , [, , , , ,r   rL   c                  L     e Zd ZU dZded<   ded<   ded<   d fdZddZ x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.
    r3   r4   r   __tablename__sa.Tabler>   r5   r6   r7   r8   r9   r:   r;   r   r<   c                    t          |           rt          | j                  | _         t	                      j        |||fi | d| j        vrd| j        v r| j        d         | `d S d S d S d S )NrU   r>   )should_set_tablenamecamel_to_snake_caser   rU   rC   rD   r@   r>   )r   r5   r6   r8   r:   rG   s        r   rD   zNameMetaMixin.__init__   s      $$ 	B 3CL A ACua226222 3<//s|++[)1	 0/++11r   argssa.Table | Nonec                   |                     d          }|	|d         }n| d|d          }|| j        j        v rt          j        |i |S |D ]P}t          |t          j                  r|j        st          |t          j                  rt          j        |i |c S Q| j	        dd         D ]}d|j
        v r nt          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   r>   rU   getr4   tablesr$   Table
isinstanceColumnprimary_keyPrimaryKeyConstraint__mro__r@   rU   r   rZ   r:   r^   keyargbases          r   __table_cls__zNameMetaMixin.__table_cls__   s2    H%%>q'CC''d1g''C #,%%%8T,V,,,  	1 	1C3	** 1s 1:R,D D 1 x0000001 K"% 	- 	-Ddm++ , 8T,V,,, cl**!tr   rH   rZ   r;   r:   r;   r   r[   )r   r   r   r   r0   rD   rn   rI   rJ   s   @r   rT   rT      s                 ' ' ' ' ' ' ' 'r   rT   c                  l     e Zd ZU dZded<   ded<   ded<   ed fd            Zedd            Z x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
    r3   r4   r   rU   rV   r>   r   t.Type[NameMixin]r:   rN   r   r<   c                    t          |           rt          | j                  | _         t	                      j        di | d| j        vrd| j        v r| j        d         | `d S d S d S d S )NrU   r>   r   )rX   rY   r   rU   rC   rQ   r@   r>   )r   r:   rG   s     r   rQ   zNameMixin.__init_subclass__   s    $$ 	B 3CL A AC!!++F+++ 3<//s|++[)1	 0/++11r   rZ   r;   r[   c                   |                     d          }|	|d         }n| d|d          }|| j        j        v rt          j        |i |S |D ]P}t          |t          j                  r|j        st          |t          j                  rt          j        |i |c S Q| j	        dd         D ]}d|j
        v r nt          j        |i |S d| j
        v r| `dS r]   ra   rj   s          r   rn   zNameMixin.__table_cls__   s2    H%%>q'CC''d1g''C #,%%%8T,V,,,  	1 	1C3	** 1s 1:R,D D 1 x0000001 K"% 	- 	-Ddm++ , 8T,V,,, cl**!tr   )r   rr   r:   rN   r   r<   ro   )	r   r   r   r   r0   rR   rQ   rn   rI   rJ   s   @r   rq   rq      s                [ ' ' ' [' ' ' ' 'r   rq   r   r,   r   boolc                v   | j                             dd          sjt          | t          j        t          j        f          s&t          d | j        dd         D                       rt          d | j        D                       rdS | j        D ]}d|j         vrt          |j         d         t          j
                  r dS || u pn|j                             dd          pSt          |t          j                  p8t          |t          j        j                  pt          |t          j                    c 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.
    __abstract__Fc              3  J   K   | ]}t          |t          j                  V  d S N)re   sa_ormDeclarativeMeta.0bs     r   	<genexpr>z'should_set_tablename.<locals>.<genexpr>  s/      WW!
1f&<==WWWWWWr   r   Nc              3  N   K   | ] }|t           j        u p|t           j        u V  !d S ry   )rz   DeclarativeBaseDeclarativeBaseNoMetar|   s     r   r   z'should_set_tablename.<locals>.<genexpr>  sK       
 
 &((MA1M,M
 
 
 
 
 
r   rU   T)r@   rb   
issubclassrz   r   r   anyri   	__bases__re   declared_attrr{   decl_apiDeclarativeAttributeIntercept)r   rm   s     r   rX   rX     sr    	// 3!79U VWW WWs{STSUSUWWWWW	  
 
]
 
 
 
 
 u 
 
$-//dmO4f6JKK 	55 CK 	}  77	 4!788 BdFO$QRRB dF$@AA
 	
 	
 	
 4r   r5   r   c                |    t          j        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)r5   s    r   rY   rY   ;  s2    6=vtLLD::<<s###r   c                      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   r   A             r   r   c                      e Zd ZdZdS )DefaultMetaNoNamer   Nr   r   r   r   r   r   G  r   r   r   )r   r,   r   ru   )r5   r   r   r   )
__future__r   r   typingt
sqlalchemyr$   sqlalchemy.ormormrz   r   r   TYPE_CHECKING	extensionr   r   r   r,   r2   rL   rT   rq   rX   rY   r{   r   r   r   r   r   <module>r      s   " " " " " " 				                    ? &%%%%%%	
 	
 	
 	
 	
 	
 	
 	
(/ (/ (/ (/ (/ (/ (/ (/V3 3 3 3 3D 3 3 32, , , , , , , ,@B B B B BD B B BJD D D D D D D DN- - - -`$ $ $ $    -0F       v'=     r   