
    wdf|                         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dS )    N)inspect)DeclarativeMetadeclared_attr)_get_table_key   to_strc                 h   | j                             dd          s&t          d | j        dd         D                       sdS | j        D ]f}d|j         vrt	          |j         d         t
                    r dS || u p0|j                             dd          pt	          |t                      c S dS )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                    V  d S N)
isinstancer   ).0bs     [/var/www/book.euthymeo.com/html/venv/lib/python3.11/site-packages/flask_sqlalchemy/model.py	<genexpr>z'should_set_tablename.<locals>.<genexpr>   s,      KKa:a11KKKKKK    r   N__tablename__T)__dict__getany__mro__r   r   r   )clsbases     r   should_set_tablenamer      s     	//KK3;qrr?KKKKK u 
 
$-//dmO4mDD 	55 CK 5}  775dO444
 	
 	
 	
 4r   z([A-Z]+)(?=[a-z0-9])c                 d    d }t                               ||                               d          S )Nc                     |                                  }t          |          dk    r(d|d d         d|d                                         S d|                                z   S )Nr   _)grouplenlower)matchwords     r   _joinz"camel_to_snake_case.<locals>._join3   s\    {{}}t99q=== $SbS			4884;;===TZZ\\!!r   r   )camelcase_resublstrip)namer%   s     r   camel_to_snake_caser*   2   s7    " " " E4((//4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         | `d S d S d S d S )Nr   	__table__)	r   r*   __name__r   superr,   __init__r   r.   )r   r)   basesd	__class__s       r   r1   zNameMetaMixin.__init__?   s    $$ 	B 3CL A ACmS!!**4:::
 3<//s|++[)1	 0/++11r   c                    t          |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 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.
        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&:&:;;#,%%%8T,V,,,  	1 	1CC++1031c2#:;;1 x000000	1 K"% 	- 	-Ddm++ , 8T,V,,, cl**!!! +*r   )r/   
__module____qualname__r1   rB   __classcell__r4   s   @r   r,   r,   >   sG            !" !" !" !" !" !" !"r   r,   c                        e Zd Z fdZ xZS )BindMetaMixinc                     |                     dd           pt          | dd           }t          t          |                               |||           |"t          | dd           || j        j        d<   d S d S d S )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   s    EE.$'' 2sND11 	
 	mS!!**4:::GCd$C$C$O-5CMz***  $O$Or   )r/   rC   rD   r1   rE   rF   s   @r   rH   rH   r   s8        	6 	6 	6 	6 	6 	6 	6 	6 	6r   rH   c                       e Zd ZdS )DefaultMetaN)r/   rC   rD    r   r   rP   rP      s        Dr   rP   c                        e Zd ZdZdZdZd ZdS )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                    t          |                     }nd                    d |D                       }d                    t          |           j        |          S )Nz(transient {0})z, c              3   4   K   | ]}t          |          V  d S r   r   )r   values     r   r   z!Model.__repr__.<locals>.<genexpr>   s(      ??U6%==??????r   z	<{0} {1}>)r   identityformatidjointyper/   )selfrW   pks      r   __repr__zModel.__repr__   sp    4==)"))"T((33BB??h?????B!!$t**"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      sR   				           E E E E E E E E , , , , , ,      ! ! !H rz122	5 	5 	51" 1" 1" 1" 1"D 1" 1" 1"h
6 
6 
6 
6 
6D 
6 
6 
6	 	 	 	 	- 	 	 	; ; ; ; ;F ; ; ; ; ;r   