U kf&F@sUdZddlmZddlZddlmZddlmZddlmZddlmZddlm Z dd lm Z dd lm Z dd lm Z dd lm Z dd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlmZddl"m#Z#dd l$m%Z%erdd!l&m'Z'dd"l"m(Z(dd#l"m)Z)ed$ed%Z*e e+ee,d&ffZ-e.Z/d'e0d(<d)d*d+d,d-d.d/Z1d)d0d+d,d-d1d2Z2d)d+d3d4d5d6d7Z3Gd8d&d&Z4Gd9d:d:e4Z5Gd;d<dd>Z7Gd?d@d@Z8e!9e8dAdBGdCdDdDZ:d)dEd@dFdGdHZ;GdIdJdJZdS)RzRoutines 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)boundClsRegistryTokenzSet[ClsRegistryToken] _registriesstrzType[_T]_ClsRegistryTypeNone) classnameclsdecl_class_registryreturnc Cs||kr6||}t|ts>t|td|g}||<n|||<ztt|d}Wn&tk rvtdd|d<}YnX|jd}|r |d}||}|D]}||}qz| ||Wqt k r}z&t|tst d|d|nW5d}~XYqXqdS)z^Add a class to the _decl_class_registry associated with the given declarative class. Type[Any]_sa_module_registryN.rname "-" matches both a class name and a module name) isinstance_MultipleClassMarkerr _ModuleMarkerKeyError __module__splitpop get_module add_classAttributeErrorrInvalidRequestError) r*r+r,existing root_moduletokenstokenmoduleaerDJ/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/orm/clsregistry.pyr;@s>        r;r.cCs||kr,||}t|tr&||n||=ztt|d}Wntk rTYdSX|jd}|r|d}| |}|D]}| |}q~z| ||Wqbt k rt|tsnYqbXqbdS)Nr/r0r) r3r4 remove_itemrr5r6r7r8r9r: remove_classr<)r*r+r,r>r?r@rArBrDrDrErGvs0       rGzCallable[[Any], bool]bool)keyr,testr-cCsP||kr dS||}t|trB|jD]}||r$dSq$tdn || SdS)atest 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. TFzunknown codepathN)r3r4contentsNotImplementedError)rIr,rJthingZ sub_thingrDrDrE _key_is_emptys   rNc@seZdZdZdZdS)r%zAan object that can be in the registry._class_registry as a value.rDN)__name__r7 __qualname____doc__ __slots__rDrDrDrEr%sc@seZdZUdZdZded<ded<d"dd d d d Zd ddddZddddZddd dddZ dddddZ d ddd d!Z dS)#r4zRrefers to multiple classes of the same name within _decl_class_registry. ) on_removerK __weakref__zSet[weakref.ref[Type[Any]]]rKz/CallableReference[Optional[Callable[[], None]]]rSNzIterable[Type[Any]]zOptional[Callable[[], None]])classesrScs(|_fdd|D_tdS)Ncsh|]}t|jqSrD)weakrefref _remove_item).0itemselfrDrE sz0_MultipleClassMarker.__init__..)rSrKr&add)r\rUrSrDr[rE__init__s  z_MultipleClassMarker.__init__r.r))r+r-cCs|t|dSN)rXrVrWr\r+rDrDrErFsz _MultipleClassMarker.remove_itemz*Generator[Optional[Type[Any]], None, None]r-cCsdd|jDS)Ncss|] }|VqdSr`rDrYrWrDrDrE sz0_MultipleClassMarker.__iter__..rKr[rDrDrE__iter__sz_MultipleClassMarker.__iter__ List[str]r')pathrIr-cCsVt|jdkr*tdd||gn(t|jd}|}|dkrNt||SdS)NrzxMultiple classes found for path "%s" in the registry of this declarative base. Please use a fully module-qualified path.r0r)lenrKrr=joinlist NameError)r\rhrIrWr+rDrDrE attempt_getsz _MultipleClassMarker.attempt_getzweakref.ref[Type[Any]])rWr-cCs.|j||js*t||jr*|dSr`)rKdiscardr&rS)r\rWrDrDrErXs   z!_MultipleClassMarker._remove_item)rZr-cCsXddddt|jDD}|j|kr>td|j|jf|jt||j dS)NcSsh|]}|dk r|jqSr`)r7)rYr+rDrDrEr]sz0_MultipleClassMarker.add_item..cSsg|] }|qSrDrDrcrDrDrE sz1_MultipleClassMarker.add_item..zThis declarative base already contains a class with the same class name and module name as %s.%s, and will be replaced in the string-lookup table.) rkrKr7rwarnrOr^rVrWrX)r\rZmodulesrDrDrEadd_items  z_MultipleClassMarker.add_item)N) rOr7rPrQrR__annotations__r_rFrfrmrXrrrDrDrDrEr4s  r4c@seZdZUdZdZded<ded<ded<d ed <d dd d dZd ddddZd ddddZd ddddZ d ddddZ d ddddZ d ddd d!d"Z d ddd d#d$Z d%S)&r5z>Refers to a module name within _decl_class_registry. )parentnamerKmod_nsrhrTzOptional[_ModuleMarker]rtz5Dict[str, Union[_ModuleMarker, _MultipleClassMarker]]rK_ModNSrvrgrhr')rurtcCsJ||_||_i|_t||_|jr6|jj|jg|_ng|_t|dSr`)rtrurKrwrvrhr&r^)r\rurtrDrDrEr_s z_ModuleMarker.__init__rH)rur-cCs ||jkSr`rer\rurDrDrE __contains__sz_ModuleMarker.__contains__r%cCs |j|Sr`rerxrDrDrE __getitem__sz_ModuleMarker.__getitem__r)cCs:|j|d|js6|jdk r6|j|jt|dSr`)rKr9rtrXrur&rnrxrDrDrErX sz_ModuleMarker._remove_itemUnion[_ModNS, Type[Any]]rIr-cCs |j|Sr`)rv __getattr__r\rIrDrDrE resolve_attr&sz_ModuleMarker.resolve_attrcCs4||jkr t||}||j|<ntt|j|}|Sr`)rKr5r)r\rumarkerrDrDrEr:)s    z_ModuleMarker.get_moduler.)rur+r-c sjkrpttj}z||Wqtk rl}z&t|tsZtdd|nW5d}~XYqXn"t|gfddd}j<dS)Nr1r2cs Sr`)rXrDrur\rDrE@z)_ModuleMarker.add_class..)rS)rKrr4rrr<r3rr=)r\rur+r>rCrDrrEr;1s     z_ModuleMarker.add_classcCs(||jkr$tt|j|}||dSr`)rKrr4rF)r\rur+r>rDrDrErGCs z_ModuleMarker.remove_classN)rOr7rPrQrRrsr_ryrzrXrr:r;rGrDrDrDrEr5s  r5c@s8eZdZUdZded<ddddZddd d d Zd S) rw)Z__parentr5_ModNS__parent)rtcCs ||_dSr`)r)r\rtrDrDrEr_Nsz_ModNS.__init__r'r{r|cCstz|jj|}Wntk r$Yn8X|dk r\t|tr>|jSt|tsLt||jj |St d|jj |fdS)Nz.resolve_argz-Callable[[], Union[Type[Any], Table, _ModNS]])rr-cstt|jSr`)rrr)rrrDrE resolve_name5sz_resolver..resolve_name)F) r sqlalchemyrrrZ immutabledict__dict__union)r+rrrrrrrDrrE _resolver!s   r)?rQ __future__rrtypingrrrrrrr r r r r rrrrrrrVrrrZdescriptor_propsr propertiesrrrrrZ sql.schemarZ util.typingrZ relationshipsr r!r"r#r'rr(setr&rsr;rGrNr%r4r5rwrZ _inspectsrrrrrrDrDrDrEsl                                6! EG