
    +h|                         d dl Z d dlZd dlmZ d dlmZmZ d dlmZ ddl	m
Z
 d Z e j                  d      Zd	 Z G d
 de      Z G d de      Z G d deee      Z G d de      Zy)    N)inspect)DeclarativeMetadeclared_attr)_get_table_key   to_strc                 h   | j                   j                  dd      st        d | j                  dd D              sy| j                  D ]g  }d|j                   vrt	        |j                   d   t
              r y|| u xs/ |j                   j                  dd      xs t	        |t                c S  y)a@  Determine whether ``__tablename__`` should be automatically 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, :meth:`._BoundDeclarativeMeta.__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   <   K   | ]  }t        |t                y wN)
isinstancer   ).0bs     I/var/www/html/venv/lib/python3.12/site-packages/flask_sqlalchemy/model.py	<genexpr>z'should_set_tablename.<locals>.<genexpr>   s     Ka:a1Ks   r   N__tablename__T)__dict__getany__mro__r   r   r   )clsbases     r   should_set_tablenamer      s     	/K3;;qr?KK 
$--/dmmO4mD CK 5}}  75dO44
 	

     z([A-Z]+)(?=[a-z0-9])c                 R    d }t         j                  ||       j                  d      S )Nc                     | j                         }t        |      dkD  rd|d d d|d   j                         S d|j                         z   S )Nr   _)grouplenlower)matchwords     r   _joinz"camel_to_snake_case.<locals>._join3   sG    {{}t9q= $Sb	484;;==TZZ\!!r   r   )camelcase_resublstrip)namer%   s     r   camel_to_snake_caser*   2   s'    " E4(//44r   c                   $     e Zd Z fdZd Z xZS )NameMetaMixinc                     t        |       rt        | j                        | _        t        t
        |   |||       d| j                  vr"d| j                  v r| j                  d   | `y y y y )Nr   	__table__)	r   r*   __name__r   superr,   __init__r   r.   )r   r)   basesd	__class__s       r   r1   zNameMetaMixin.__init__?   sl    $ 3CLL ACmS*4:
 3<</s||+[)1 2 , 0r   c                    t        |d   |j                  d            }|| j                  j                  v rt	        j
                  |i |S |D ]Y  }t        |t        j                        r|j                  st        |t        j                        sDt	        j
                  |i |c S  | j                  dd D ]  }d|j                  v s n t	        j
                  |i |S d| j                  v r| `yy)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.
        r   schemar   r   r.   r   N)r   r   metadatatablessaTabler   Columnprimary_keyPrimaryKeyConstraintr   r   r   )r   argskwargskeyargr   s         r   __table_cls__zNameMetaMixin.__table_cls__N   s     T!Wfjj&:;#,,%%%88T,V,,  	1CC+c2#:#:;xx000	1 KK"% 	-Ddmm+	- 88T,V,, cll*! +r   )r/   
__module____qualname__r1   rB   __classcell__r4   s   @r   r,   r,   >   s    !"r   r,   c                        e Zd Z fdZ xZS )BindMetaMixinc                     |j                  dd       xs t        | dd       }t        t        |   |||       |(t        | dd       || j
                  j                  d<   y y y )N__bind_key__r.   bind_key)popgetattrr0   rH   r1   r.   info)r   r)   r2   r3   rK   r4   s        r   r1   zBindMetaMixin.__init__s   sm    EE.$' 2sND1 	
 	mS*4:GCd$C$O-5CMMz* %Pr   )r/   rC   rD   r1   rE   rF   s   @r   rH   rH   r   s    	6 	6r   rH   c                       e Zd Zy)DefaultMetaN)r/   rC   rD    r   r   rP   rP      s    r   rP   c                       e Zd ZdZdZdZd Zy)ModelzBase class for SQLAlchemy declarative base model.

    To define models, subclass :attr:`db.Model <SQLAlchemy.Model>`, not this
    class. To customize ``db.Model``, subclass this and pass it as
    ``model_class`` to :class:`SQLAlchemy`.
    Nc                     t        |       j                  }|dj                  t        |             }ndj	                  d |D              }dj                  t        |       j                  |      S )Nz(transient {0})z, c              3   2   K   | ]  }t        |        y wr   r   )r   values     r   r   z!Model.__repr__.<locals>.<genexpr>   s     ?U6%=?s   z	<{0} {1}>)r   identityformatidjointyper/   )selfrW   pks      r   __repr__zModel.__repr__   s\    4=))"))"T(3B?h??B!!$t*"5"5r::r   )r/   rC   rD   __doc__query_classqueryr^   rQ   r   r   rS   rS      s     K
 E;r   rS   )re
sqlalchemyr9   r   sqlalchemy.ext.declarativer   r   sqlalchemy.schemar   _compatr	   r   compiler&   r*   r[   r,   rH   rP   objectrS   rQ   r   r   <module>ri      sj    	   E , !H rzz12	51"D 1"h
6D 
6	- 	;F ;r   