
    2h,                    X   S SK Jr  S SKrS SKrS SKrS SKJr	  SSK
Jr  \R                  (       a  SSKJr   " S S5      r " S S	5      r " S
 S\5      r " S S5      r " S S\5      r " S S5      rSS jrSS jr " S S\\\	R0                  5      r " S S\\	R0                  5      rg)    )annotationsN   )Query)
SQLAlchemyc                  "    \ rS rSrSrSS jrSrg)_QueryProperty   zJA class property that creates a query object for a model.

:meta private:
c                P    UR                  X"R                  R                  5       S9$ )N)session)query_class__fsa__r   )selfobjclss      N/var/www/auris/envauris/lib/python3.13/site-packages/flask_sqlalchemy/model.py__get___QueryProperty.__get__   s(    ,,.  
 	
     N)r   zModel | Noner   ztype[Model]returnr   )__name__
__module____qualname____firstlineno____doc__r   __static_attributes__r   r   r   r   r      s    

r   r   c                  Z    \ rS rSr% SrS\S'    \rS\S'    \" 5       r	S\S'    SS	 jr
S
rg)Model   al  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]queryc                F   [         R                  " U 5      nUc   eUR                  (       a  S[        U 5       S3nOJUR                  (       a  S[        U 5       S3nO)SR                  [        [        UR                  5      5      nS[        U 5      R                   SU S3$ )Nz(transient )z	(pending z, < >)sainspect	transientidpendingjoinmapstridentitytyper   )r   statepks      r   __repr__Model.__repr__8   s    

4    ??r$xj*B]]RXJa(B3sENN34B4:&&'qA..r   r   N)r   r-   )r   r   r   r   r   __annotations__r   r   r   r    r2   r   r   r   r   r   r      s@     $#
 ,1K(0  ./E//r   r   c                  Z   ^  \ rS rSr% SrS\S'   S\S'             S	U 4S jjrSrU =r$ )
BindMetaMixinF   a  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metadatac                   > SU R                   ;   dO  SU R                   ;   d?  [        U SS 5      n[        U SS 5      nU R                  R                  U5      nXvLa  Xpl        [
        TU ]  " XU40 UD6  g )Nr9   	__table____bind_key__)__dict__getattrr   _make_metadatar9   super__init__)	r   namebasesdkwargsbind_keyparent_metadatar9   	__class__s	           r   rA   BindMetaMixin.__init__Q   sk     cll*kS\\.IsND9H%c:t<O{{11(;H.'a262r   r   
rB   r-   rC   ztuple[type, ...]rD   zdict[str, t.Any]rE   t.Anyr   None)	r   r   r   r   r   r4   rA   r   __classcell__rH   s   @r   r6   r6   F   sH     33/34D3PU3	3 3r   r6   c                  P   ^  \ rS rSr% SrS\S'   S\S'   \S	U 4S jj5       rSrU =r	$ )
	BindMixin_   a  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   r8   r9   c                  > SU R                   ;   d`  SU R                   ;   dP  [        U S5      (       a?  [        U SS 5      n[        U SS 5      nU R                  R	                  U5      nXCLa  X@l        [        TU ]  " S0 UD6  g )Nr9   r;   r<   r   )r=   hasattrr>   r   r?   r9   r@   __init_subclass__)r   rE   rF   rG   r9   rH   s        r   rT   BindMixin.__init_subclass__p   sz    cll*kS\\.IwP
 P
 sND9H%c:t<O{{11(;H.'!+F+r   r   )r   zt.Type[BindMixin]rE   t.Dict[str, t.Any]r   rL   )
r   r   r   r   r   r4   classmethodrT   r   rM   rN   s   @r   rP   rP   _   s(     , ,r   rP   c                  n   ^  \ rS rSr% SrS\S'   S\S'   S\S'             SU 4S	 jjrSS
 jrSrU =r	$ )NameMetaMixin   a@  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.
r8   r9   r-   __tablename__sa.Tabler;   c                   > [        U 5      (       a  [        U R                  5      U l        [        TU ]  " XU40 UD6  SU R                  ;  a%  SU R                  ;   a  U R                  S   c  U ?g g g g )Nr[   r;   )should_set_tablenamecamel_to_snake_caser   r[   r@   rA   r=   r;   )r   rB   rC   rD   rE   rH   s        r   rA   NameMetaMixin.__init__   sr      $$ 3CLL ACa262 3<</s||+[)1 2 , 0r   c                *   UR                  S5      nUc  US   nO
U SUS    3nX@R                  R                  ;   a  [        R                  " U0 UD6$ U Hj  n[        U[        R                  5      (       a  UR                  (       d!  [        U[        R                  5      (       d  MT  [        R                  " U0 UD6s  $    U R                  SS  H  nSUR                  ;   d  M    O   [        R                  " U0 UD6$ SU R                  ;   a  U ?g	zThis 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;   r[   getr9   tablesr&   Table
isinstanceColumnprimary_keyPrimaryKeyConstraint__mro__r=   r[   r   argsrE   rc   keyargbases          r   __table_cls__NameMetaMixin.__table_cls__   s     H%>q'CHAd1gY'C ,,%%%88T,V,, C3		**s:R,,D D xx000	  KK"%Ddmm+ & 88T,V,, cll*!r   r   rJ   rp   rK   rE   rK   r   zsa.Table | None)
r   r   r   r   r   r4   rA   rt   r   rM   rN   s   @r   rY   rY      sS     /4DPU	 ' 'r   rY   c                  n   ^  \ rS rSr% SrS\S'   S\S'   S\S'   \SU 4S	 jj5       r\SS
 j5       rSr	U =r
$ )	NameMixin   aa  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
r8   r9   r-   r[   r\   r;   c                   > [        U 5      (       a  [        U R                  5      U l        [        TU ]  " S0 UD6  SU R                  ;  a%  SU R                  ;   a  U R                  S   c  U ?g g g g )Nr[   r;   r   )r^   r_   r   r[   r@   rT   r=   r;   )r   rE   rH   s     r   rT   NameMixin.__init_subclass__   sl    $$ 3CLL AC!+F+ 3<</s||+[)1 2 , 0r   c                *   UR                  S5      nUc  US   nO
U SUS    3nX@R                  R                  ;   a  [        R                  " U0 UD6$ U Hj  n[        U[        R                  5      (       a  UR                  (       d!  [        U[        R                  5      (       d  MT  [        R                  " U0 UD6s  $    U R                  SS  H  nSUR                  ;   d  M    O   [        R                  " U0 UD6$ SU R                  ;   a  U ?grb   rf   ro   s          r   rt   NameMixin.__table_cls__   s     H%>q'CHAd1gY'C ,,%%%88T,V,, C3		**s:R,,D D xx000	  KK"%Ddmm+ & 88T,V,, cll*!r   r   )r   zt.Type[NameMixin]rE   rV   r   rL   rv   )r   r   r   r   r   r4   rW   rT   rt   r   rM   rN   s   @r   rx   rx      sB       ' 'r   rx   c                   U R                   R                  SS5      (       dt  [        U [        R                  [        R
                  45      (       d$  [        S U R                  SS  5       5      (       a!  [        S U R                   5       5      (       a  gU R                   H  nSUR                   ;  a  M  [        UR                   S   [        R                  5      (       a    gXL =(       d    UR                   R                  SS5      =(       dk    [        U[        R                  5      =(       dE    [        U[        R                  R                  5      =(       d    [        U[        R
                  5      (       + (       + s  $    g)	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  V   #    U  H  n[        U[        R                  5      v   M!     g 7fN)rj   sa_ormDeclarativeMeta.0bs     r   	<genexpr>'should_set_tablename.<locals>.<genexpr>  s      W!
1f&<&<==s   ')r   Nc              3  x   #    U  H0  nU[         R                  L =(       d    U[         R                  L v   M2     g 7fr   )r   DeclarativeBaseDeclarativeBaseNoMetar   s     r   r   r     s5      
" &(((MA1M1M,MM"s   8:r[   T)r=   rg   
issubclassr   r   r   anyrn   	__bases__rj   declared_attrr   decl_apiDeclarativeAttributeIntercept)r   rs   s     r   r^   r^     s2    	//3!7!79U9U VWWWs{{STSUWWW 
]]
 
 

 $--/dmmO4f6J6JKK K 	}}  7	 4!7!78 BdFOO$Q$QRB dF$@$@A
 	
 ( r   c                p    [         R                  " SSU 5      n U R                  5       R                  S5      $ )z/Convert a ``CamelCase`` name to ``snake_case``.z(((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))z_\1_)resublowerlstrip)rB   s    r   r_   r_   ;  s,    66=vtLD::<s##r   c                      \ rS rSrSrSrg)DefaultMetaiA  _SQLAlchemy declarative metaclass that provides ``__bind_key__`` and
``__tablename__`` support.
r   Nr   r   r   r   r   r   r   r   r   r   r   A      r   r   c                      \ rS rSrSrSrg)DefaultMetaNoNameiG  r   r   Nr   r   r   r   r   r   G  r   r   r   )r   r/   r   bool)rB   r-   r   r-   )
__future__r   r   typingt
sqlalchemyr&   sqlalchemy.ormormr   r    r   TYPE_CHECKING	extensionr   r   r   r/   r6   rP   rY   rx   r^   r_   r   r   r   r   r   r   <module>r      s    " 	    ??%	
 	
(/ (/V3D 32, ,@BD BJD DN-`$-0F0F v'='= r   