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

    :meta private:
    objNoneclstype[Model]returnr   c                    d S N selfr	   r   s      R/var/www/html/t/fyr/venv311/lib/python3.11/site-packages/flask_sqlalchemy/model.py__get__z_QueryProperty.__get__           Modelc                    d S r   r   r   s      r   r   z_QueryProperty.__get__   r   r   Model | Nonec                ^    |                     ||j                                                  S )N)session)query_class__fsa__r   r   s      r   r   z_QueryProperty.__get__   s0    ,,..  
 
 	
r   N)r	   r
   r   r   r   r   )r	   r   r   r   r   r   )r	   r   r   r   r   r   )__name__
__module____qualname____doc__toverloadr   r   r   r   r   r      sv         
 Z   Z Z   Z
 
 
 
 
 
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 )r   a  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__@   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%   r7   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   r
   c                    d| j         v sPd| j         v sGt          | dd           }t          | dd           }| j                            |          }||ur|| _         t                      j        |||fi | d S )Nr<   	__table____bind_key__)__dict__getattrr   _make_metadatar<   super__init__)	r   r=   r>   r@   rB   bind_keyparent_metadatar<   	__class__s	           r   rK   zBindMetaMixin.__init__Y   s     cl**kS\.I.IsND99H%c:t<<O{11(;;H..'ua22622222r   
r=   r&   r>   r?   r@   rA   rB   rC   r   r
   )r   r   r    r!   r8   rK   __classcell__rN   s   @r   r:   r:   N   sc           3 3 3 3 3 3 3 3 3 3r   r:   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.
    r;   r<   r&   __tablename__zsa.TablerE   r=   r>   r?   r@   rA   rB   rC   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 )NrT   rE   )should_set_tablenamecamel_to_snake_caser   rT   rJ   rK   rG   rE   )r   r=   r>   r@   rB   rN   s        r   rK   zNameMetaMixin.__init__r   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   rE   rT   )getr<   tablesr,   Table
isinstanceColumnprimary_keyPrimaryKeyConstraint__mro__rG   rT   )r   rX   rB   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   rO   )rX   rC   rB   rC   r   rY   )r   r   r    r!   r8   rK   ri   rP   rQ   s   @r   rS   rS   g   s                 ' ' ' ' ' ' ' 'r   rS   r   r4   r   boolc                |   | j                             dd          s&t          d | j        dd         D                       sdS | j        D ]p}d|j         vrt	          |j         d         t
          j                  r dS || u p5|j                             dd          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 r   )ra   sa_ormDeclarativeMeta).0bs     r   	<genexpr>z'should_set_tablename.<locals>.<genexpr>   s@       : :23
1f,--: : : : : :r   r   NrT   T)rG   r^   anyre   ra   rn   declared_attrro   )r   rh   s     r   rV   rV      s     |.. c : :7:{122: : : 7 7  u 
 
$-//dmO4f6JKK 	55 CK <}  77<dF$:;;;
 	
 	
 	
 4r   r=   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)r=   s    r   rW   rW      s2    6=vtLLD::<<s###r   c                      e Zd ZdZdS )DefaultMetazgSQLAlchemy declarative metaclass that provides ``__bind_key__`` and
    ``__tablename__`` support.
    N)r   r   r    r!   r   r   r   r|   r|      s           r   r|   )r   r4   r   rj   )r=   r&   r   r&   )
__future__r   rw   typingr"   
sqlalchemyr,   sqlalchemy.ormormrn   r%   r   TYPE_CHECKING	extensionr   r   r   r4   r:   rS   rV   rW   ro   r|   r   r   r   <module>r      s   " " " " " " 				                    ? &%%%%%%
 
 
 
 
 
 
 
((/ (/ (/ (/ (/ (/ (/ (/V3 3 3 3 3D 3 3 32B B B B BD B B BJ   B$ $ $ $    -0F     r   