
    [h6F                       U d Z ddlmZ ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 dd	lm
Z
 dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddlm!Z! ddlmZ ddl"m#Z# dd l$m%Z% erdd!l&m'Z' dd"l"m(Z( dd#l"m)Z)  ed$e%          Z*ee+ee,d&f         f         Z- e.            Z/d'e0d(<   dPd1Z1dQd3Z2dRd8Z3 G d9 d&          Z4 G d: d;e4          Z5 G d< d=e4          Z6 G d> d?          Z7 G d@ dA          Z8  e!j9        e8          dB             G dC dD          Z:dSdGZ; G dH dI          Z<da=dJe0dK<   dTdOZ>dS )UzRoutines to handle the string class registry used by declarative.

This system allows specification of classes and expressions used in
:func:`_orm.relationship` using strings.

    )annotationsN)Any)Callable)cast)Dict)	Generator)Iterable)List)Mapping)MutableMapping)NoReturn)Optional)Set)Tuple)Type)TYPE_CHECKING)TypeVar)Union   )
attributes)
interfaces)SynonymProperty)ColumnProperty)class_mapper   )exc)
inspection)util)_get_table_key)CallableReference)RelationshipProperty)MetaData)Table_T)boundClsRegistryTokenzSet[ClsRegistryToken]_registries	classnamestrclsType[_T]decl_class_registry_ClsRegistryTypereturnNonec                   | |v rB||          }t          |t                    s$t          |t          d|          g          x}|| <   n||| <   	 t          t          |d                   }n%# t          $ r t          dd          x|d<   }Y nw xY w|j                            d          }|r|                    d          }|                    |          }|D ]}|                    |          }	 |	                    | |           nA# t          $ r4}t          |t                    st          j        d|  d          | d}~ww xY w|dS dS )z^Add a class to the _decl_class_registry associated with the
    given declarative class.

    	Type[Any]_sa_module_registryN.r   name "-" matches both a class name and a module name)
isinstance_MultipleClassMarkerr   _ModuleMarkerKeyError
__module__splitpop
get_module	add_classAttributeErrorr   InvalidRequestError)	r(   r*   r,   existingroot_moduletokenstokenmoduleaes	            i/var/www/api.easyaligner.net/htdocs/venv_linux/lib/python3.11/site-packages/sqlalchemy/orm/clsregistry.pyr>   r>   @   s    '''&y1($899 	8Ld;1129 9 H*95 *-I&
./DE
 
  
 
 
/66	
12[[[

 ^!!#&&F  

1''.. 	. 	.E&&u--FF		Y,,,, 	 	 	fm44 -3Y 3 3 3  
 	      s*   A) )B
B/D 
E/D??Er1   c                   | |v r6||          }t          |t                    r|                    |           n|| = 	 t          t          |d                   }n# t
          $ r Y d S w xY w|j                            d          }|r|                    d          }|	                    |          }|D ]}|	                    |          }	 |
                    | |           n'# t          $ r t          |t                    sn Y nw xY w|d S d S )Nr2   r3   r   )r6   r7   remove_itemr   r8   r9   r:   r;   r<   r=   remove_classr?   )r(   r*   r,   rA   rB   rC   rD   rE   s           rG   rJ   rJ   v   sm    '''&y1h 455 	/  %%%%#I../DE
 
     ^!!#&&F
 

1''.. 	. 	.E&&u--FF		3//// 	 	 	fm44  	      s#   A 
A&%A&
C! !!DDkeytestCallable[[Any], bool]boolc                    | |vrdS ||          }t          |t                    r'|j        D ]} ||          r dS t          d           ||           S )a  test if a key is empty of a certain object.

    used for unit tests against the registry to see if garbage collection
    is working.

    "test" is a callable that will be passed an object should return True
    if the given object is the one we were looking for.

    We can't pass the actual object itself b.c. this is for testing garbage
    collection; the caller will have to have removed references to the
    object itself.

    TFzunknown codepath)r6   r7   contentsNotImplementedError)rK   r,   rL   thing	sub_things        rG   _key_is_emptyrT      s    $ %%%t$E%-..  	: 	:ItI uu &&89994;;    c                      e Zd ZdZdZdS )r&   zAan object that can be in the registry._class_registry as a value. N)__name__r:   __qualname____doc__	__slots__rW   rU   rG   r&   r&      s        KKIIIrU   c                  `    e Zd ZU dZdZded<   ded<   	 dddZddZd dZd!dZ	d"dZ
d#dZdS )$r7   zRrefers to multiple classes of the same name
    within _decl_class_registry.

    )	on_removerP   __weakref__zSet[weakref.ref[Type[Any]]]rP   z/CallableReference[Optional[Callable[[], None]]]r]   NclassesIterable[Type[Any]]Optional[Callable[[], None]]c                p     | _          fd|D              _        t                                          d S )Nc                D    h | ]}t          j        |j                  S rW   )weakrefref_remove_item).0itemselfs     rG   	<setcomp>z0_MultipleClassMarker.__init__.<locals>.<setcomp>   s5     
 
 
59GKd/00
 
 
rU   )r]   rP   r'   add)ri   r_   r]   s   `  rG   __init__z_MultipleClassMarker.__init__   sP    
 #
 
 
 
=D
 
 
 	rU   r*   r1   r.   r/   c                T    |                      t          j        |                     d S N)rf   rd   re   ri   r*   s     rG   rI   z _MultipleClassMarker.remove_item   s&    '+c**+++++rU   *Generator[Optional[Type[Any]], None, None]c                $    d | j         D             S )Nc              3  *   K   | ]} |            V  d S rn   rW   rg   re   s     rG   	<genexpr>z0_MultipleClassMarker.__iter__.<locals>.<genexpr>   s(      //#//////rU   rP   )ri   s    rG   __iter__z_MultipleClassMarker.__iter__   s    //////rU   path	List[str]rK   r)   c                    t          | j                  dk    r.t          j        dd                    ||gz             z            t          | j                  d         } |            }|t          |          |S )Nr   zxMultiple classes found for path "%s" in the registry of this declarative base. Please use a fully module-qualified path.r3   r   )lenrP   r   r@   joinlist	NameError)ri   rw   rK   re   r*   s        rG   attempt_getz _MultipleClassMarker.attempt_get   s    t}!!)B 88DC5L))+   t}%%a(C#%%C{nn$JrU   re   weakref.ref[Type[Any]]c                    | j                             |           | j         s7t                              |            | j        r|                                  d S d S d S rn   )rP   discardr'   r]   )ri   re   s     rG   rf   z!_MultipleClassMarker._remove_item   sj    c"""} 	!%%%~ !     	! 	!! !rU   rh   c                   d d t          | j                  D             D             }|j        |v r%t          j        d|j        d|j        d           | j                            t          j        || j	                             d S )Nc                     h | ]}||j         S rn   )r:   )rg   r*   s     rG   rj   z0_MultipleClassMarker.add_item.<locals>.<setcomp>   s'     
 
 
 NrU   c                "    g | ]} |            S rW   rW   rs   s     rG   
<listcomp>z1_MultipleClassMarker.add_item.<locals>.<listcomp>   s    ===#===rU   z[This declarative base already contains a class with the same class name and module name as r3   z2, and will be replaced in the string-lookup table.)
r|   rP   r:   r   warnrX   rk   rd   re   rf   )ri   rh   moduless      rG   add_itemz_MultipleClassMarker.add_item   s    
 
==dm)<)<===
 
 

 ?g%%II ???DMMM3   	'+dD,=>>?????rU   rn   )r_   r`   r]   ra   )r*   r1   r.   r/   )r.   rp   )rw   rx   rK   r)   r.   r1   )re   r   r.   r/   )rh   r1   r.   r/   )rX   r:   rY   rZ   r[   __annotations__rl   rI   rv   r~   rf   r   rW   rU   rG   r7   r7      s          
 7I))))>>>>
 37	 	 	 	 	, , , ,0 0 0 0   ! ! ! !@ @ @ @ @ @rU   r7   c                      e Zd ZU dZdZded<   ded<   ded<   d	ed
<   ddZddZd dZd!dZ	d"dZ
d#dZd$dZd$dZdS )%r8   z>Refers to a module name within
    _decl_class_registry.

    )parentnamerP   mod_nsrw   r^   Optional[_ModuleMarker]r   z5Dict[str, Union[_ModuleMarker, _MultipleClassMarker]]rP   _ModNSr   rx   rw   r   r)   c                    || _         || _        i | _        t          |           | _        | j         r| j         j        | j        gz   | _        ng | _        t                              |            d S rn   )r   r   rP   r   r   rw   r'   rk   )ri   r   r   s      rG   rl   z_ModuleMarker.__init__  sd    	Tll; 	(DI;6DIIDIrU   r.   rN   c                    || j         v S rn   ru   ri   r   s     rG   __contains__z_ModuleMarker.__contains__  s    t}$$rU   r&   c                    | j         |         S rn   ru   r   s     rG   __getitem__z_ModuleMarker.__getitem__  s    }T""rU   r/   c                    | j                             |d            | j         sB| j        | j                            | j                   t
                              |            d S d S rn   )rP   r<   r   rf   r   r'   r   r   s     rG   rf   z_ModuleMarker._remove_item   sh    $%%%} 	&{&((333%%%%%	& 	&rU   rK   Union[_ModNS, Type[Any]]c                6    | j                             |          S rn   )r   __getattr__ri   rK   s     rG   resolve_attrz_ModuleMarker.resolve_attr'  s    {&&s+++rU   c                    || j         vrt          ||           }|| j         |<   n t          t          | j         |                   }|S rn   )rP   r8   r   )ri   r   markers      rG   r=   z_ModuleMarker.get_module*  sH    t}$$"4..F"(DM$-t)<==FrU   r*   r1   c                N     j         v ryt          t           j                            }	 |                    |           d S # t          $ r4}t          |t                    st          j        d d          | d }~ww xY wt          |g fd          x} j         <   d S )Nr4   r5   c                 .                                    S rn   )rf   )r   ri   s   rG   <lambda>z)_ModuleMarker.add_class.<locals>.<lambda>A  s    ):):4)@)@ rU   )r]   )rP   r   r7   r   r?   r6   r   r@   )ri   r   r*   rA   rF   s   ``   rG   r>   z_ModuleMarker.add_class2  s    4=  0$-2EFFH	!!#&&&&&!   !(,@AA 17 7 7 7  
  .B!@!@!@!@!@. . . Ht}T***s   A 
B/A==Bc                    || j         v r7t          t          | j         |                   }|                    |           d S d S rn   )rP   r   r7   rI   )ri   r   r*   rA   s       rG   rJ   z_ModuleMarker.remove_classD  sH    4=  0$-2EFFH  %%%%% ! rU   N)r   r)   r   r   )r   r)   r.   rN   )r   r)   r.   r&   )r   r)   r.   r/   rK   r)   r.   r   )r   r)   r.   r8   )r   r)   r*   r1   r.   r/   )rX   r:   rY   rZ   r[   r   rl   r   r   rf   r   r=   r>   rJ   rW   rU   rG   r8   r8     s          
 NI####CCCCNNNOOO	 	 	 	% % % %# # # #& & & &, , , ,      $& & & & & &rU   r8   c                  .    e Zd ZU dZded<   ddZdd
ZdS )r   )__parentr8   _ModNS__parentr   c                    || _         d S rn   )r   )ri   r   s     rG   rl   z_ModNS.__init__O  s    rU   rK   r)   r.   r   c                2   	 | j         j        |         }|St          |t                    r|j        S t          |t
                    sJ |                    | j         j        |          S n# t          $ r Y nw xY wt          d| j         j
        d|          )NzModule z1 has no mapped classes registered under the name )r   rP   r6   r8   r   r7   r~   rw   r9   r}   r   )ri   rK   values      rG   r   z_ModNS.__getattr__R  s    
	FM*3/E  e]33 F <'%e-ABBBBB ,,T]-?EEE !  	 	 	D	 i.2m.@.@.@##G
 
 	
s   A* *
A76A7N)r   r8   r   rX   r:   rY   r[   r   rl   r   rW   rU   rG   r   r   J  sO         I   
 
 
 
 
 
rU   r   c                  .    e Zd ZU dZded<   ddZdd	Zd
S )_GetColumnsr*   r1   r*   c                    || _         d S rn   r   ro   s     rG   rl   z_GetColumns.__init__i  s    rU   rK   r)   r.   r   c                   t          | j        d          }|r||j        vrt          d| j        d|          |j        |         }|j        t
          j        j        u rlt          |t          j
                  sJ |j        }t          |t                    r|j        }n,t          |t                    st          j        d|z            t#          | j        |          S )NF)	configurezClass z% does not have a mapped column named zaProperty %r is not an instance of ColumnProperty (i.e. does not correspond directly to a Column).)r   r*   all_orm_descriptorsr?   extension_typer   NotExtensionNOT_EXTENSIONr6   r   QueryableAttributepropertyr   r   r   r   r@   getattr)ri   rK   mpdescprops        rG   r   z_GetColumns.__getattr__l  s    $(e444 	"000$nxxx&  
 )#.D"j&=&KKK!$
(EFFFFF}dO44 )CC#D.99 12478  
 tx%%%rU   N)r*   r1   rK   r)   r.   r   r   rW   rU   rG   r   r   d  sL         INNN   & & & & & &rU   r   c                4    t          j        | j                  S rn   )r   inspectr*   )targets    rG   r   r     s    :%fj11 rU   c                  8    e Zd ZU dZded<   ded<   ddZdd	Zd
S )	_GetTablerK   metadatar)   rK   r"   r   c                "    || _         || _        d S rn   r   )ri   rK   r   s      rG   rl   z_GetTable.__init__  s     rU   r.   r#   c                L    | j         j        t          || j                           S rn   )r   tablesr   rK   r   s     rG   r   z_GetTable.__getattr__  s    }#N3$A$ABBrU   N)rK   r)   r   r"   )rK   r)   r.   r#   r   rW   rU   rG   r   r     s^         !IHHH! ! ! !C C C C C CrU   r   r   r   c                v    t          |t                    r|                    g |           }t          |          S rn   )r6   r7   r~   r   )rK   r   s     rG   _determine_containerr     s8    %-.. +!!"c**urU   c                  |    e Zd ZU dZded<   ded<   ded<   ded	<   d
ed<   ded<   	 dddZddZd dZd!dZd"dZ	dS )#_class_resolver)r*   r   argfallback_dict
_resolversfavor_tablesr1   r*   RelationshipProperty[Any]r   Mapping[str, Any]r   r)   r   rN   r   z Tuple[Callable[[str], Any], ...]r   Fc                    || _         || _        || _        || _        t	          j        | j                  | _        d| _        || _	        d S )NrW   )
r*   r   r   r   r   PopulateDict_access_clsr   r   r   )ri   r*   r   r   r   r   s         rG   rl   z_class_resolver.__init__  sJ     	 &t'788
(rU   rK   r.   r   c                   | j         }t          j        |          }|j        }|J |j        }|j        }| j        r>||j        v r|j        |         S ||j        v rt          |t          |d|                    S ||v rt          |||                   S | j        s>||j        v r|j        |         S ||j        v rt          |t          |d|                    S d|v rM|t          t          |d                   v r0t          t          |d                   }|                    |          S | j        r| j        D ]} ||          }	|	|	c S | j        |         S )Nr   r2   )r*   r   manager_of_classregistry_class_registryr   r   r   _schemasr   r   r   r   r8   r   r   r   )
ri   rK   r*   manager	decl_baser,   r   r   resolvr   s
             rG   r   z_class_resolver._access_cls  s   h-c22$	$$$'7% 	Jho%%s++))) gc:x&H&HIII%%%'-@-EFFF  	Jho%%s++))) gc:x&H&HIII $777C4./DED
 D
 =
 =
 23HI H ((---_ 	!/ ! !s$ LLL % }S!!rU   r   err	Exceptionr   c                   t          j        d|          }|ry|                    d                              d          }t	          j        d| j        j         d| j        d| j        j	         d|                    d           d	| d
          |t	          j        d| j        j        d| j        d|d| j
        d	          |)Nz(.+)\[(.+)\]r   'zWhen initializing mapper z, expression "relationship(z)" seems to be using a generic class as the argument to relationship(); please state the generic argument using an annotation, e.g. "z	: Mapped[r   z['z']] = relationship()"z, expression z failed to locate a name (zG). If this is a class name, consider adding this relationship() to the z6 class after both dependent classes have been defined.)rematchgroupstripr   r@   r   r   r   rK   r*   )ri   r   r   generic_matchclsargs        rG   _raise_for_namez_class_resolver._raise_for_name  s	   $77 	"((++11#66F)4DI,< 4 4,0H4 4
 IM4 4
 -:,?,?,B,B4 4 4 4 4   ))
 9###TXXXtttTXXX	?  rU   Union[Table, Type[Any], _ModNS]c                   | j         }| j        }d }	 |                    d          D ]}|	||         }t          ||          }	 t	          |t
                    r|j        S t          r$t	          |t          t          t          f          sJ |S # t          $ r!}|                     ||           Y d }~d S d }~wt          $ r,}|                     |j        d         |           Y d }~d S d }~ww xY w)Nr3   r   )r   r   r;   r   r6   r   r*   r   typer#   r   r9   r   r}   args)ri   r   drvalrD   r   ns          rG   _resolve_namez_class_resolver._resolve_name  s,   xJ	C 0 0<U8DD"4//DD	0 $,, x  C%dT5&,ABBBBB  	, 	, 	,  s+++++++++ 	/ 	/ 	/  A.........	/s#   3B 
C.B55C.!C))C.c                    	 t          | j        t                      | j                  }t	          |t
                    r|j        S |S # t          $ r,}|                     |j	        d         |           Y d }~d S d }~ww xY w)Nr   )
evalr   globalsr   r6   r   r*   r}   r   r   )ri   xr   s      rG   __call__z_class_resolver.__call__  s    	/TXwyy$*55A![)) u 	/ 	/ 	/  A.........	/s   AA A 
A=!A88A=NF)
r*   r1   r   r   r   r   r   r)   r   rN   r   )r   r)   r   r   r.   r   )r.   r   )r.   r   )
rX   r:   rY   r[   r   rl   r   r   r   r   rW   rU   rG   r   r     s         I NNN####HHH0000 #) ) ) ) ) %" %" %" %"N   .   ,	/ 	/ 	/ 	/ 	/ 	/rU   r   r   _fallback_dictr   r   mTuple[Callable[[str], Callable[[], Union[Type[Any], Table, _ModNS]]], Callable[[str, bool], _class_resolver]]c                     t           ?dd l}ddlm} ddlm} t          j        |j                                      ||d          a dd fd}d fd}||fS )Nr   r   )foreign)remote)r   r   Fr   r)   r   rN   r.   r   c                6    t          t          | |          S )N)r   )r   r   )r   r   r*   r   s     rG   resolve_argz_resolver.<locals>.resolve_arg1  s%    ~s
 
 
 	
rU   -Callable[[], Union[Type[Any], Table, _ModNS]]c                <    t          t          |           j        S rn   )r   r   r   )r   r*   r   s    rG   resolve_namez_resolver.<locals>.resolve_name6  s     sD.#>>LLrU   r   )r   r)   r   rN   r.   r   )r   r)   r.   r   )	r   
sqlalchemy r   r   r   immutabledict__dict__union)r*   r   r   r   r   r   r   s   ``     rG   	_resolverr  "  s     +J,?@@FF622
 

 
 
 
 
 
 
 

M M M M M M M
 $$rU   )r(   r)   r*   r+   r,   r-   r.   r/   )r(   r)   r*   r1   r,   r-   r.   r/   )rK   r)   r,   r-   rL   rM   r.   rN   )rK   r)   r   r   r.   r   )r*   r1   r   r   r.   r   )?rZ   
__future__r   r   typingr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   rd   r   r   r   descriptor_propsr   
propertiesr   r   r   r   r   
sql.schemar   util.typingr    relationshipsr!   r"   r#   r$   r)   r   r-   setr'   r   r>   rJ   rT   r&   r7   r8   r   r   	_inspectsr   r   r   r   r  rW   rU   rG   <module>r     s     # " " " " " 				                                                 ! ! ! ! ! !                                                                    - - - - - - & & & & & &                         ' ' ' ' ' ' + + + + + + #333333%%%%%%""""""WT!#uT3E-E'F"FG  &)SUU * * * *3 3 3 3l   B   @       B@ B@ B@ B@ B@+ B@ B@ B@JE& E& E& E& E&$ E& E& E&P
 
 
 
 
 
 
 
4& & & & & & & &@ " 
 [ ! !11  
C C C C C C C C   / / / / / / / /D %) ( ( ( (% % % % % %rU   