U kf!$@s$ddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z dd lm Z dd lm Z dd lm Z dd lm Z dd lmZddlZddlmZddlmZe rddlmZddlmZededZededZGdddZGdddeZddddd d!ZdS)") annotations)Any)cast)Dict)Iterable)Iterator)List)NoReturn)Optional)Set)Tuple) TYPE_CHECKING)TypeVarN)util)exc)_IdentityKeyType) InstanceState_T)bound_Oc@sleZdZUded<ded<ded<ddd d Zddd d Zd dddZdddddZdddddZdddddZ dddddZ dDdd d d!d"d#Z dd$dd%d&Z d'dd(d)Z d*dd+d,Zd-d$dd.d/Zdddd0d1Zdddd2d3Zdddd4d5d6Zdddd7d8Zdddd9d:Zddd;d<Zddd=d>Zdddd?d@ZdAddBdCZdS)E IdentityMapzweakref.ref[IdentityMap]_wrz Dict[_IdentityKeyType[Any], Any]_dictzSet[InstanceState[Any]] _modifiedNonereturncCsi|_t|_t||_dSN)rsetrweakrefrefrselfr%G/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/orm/identity.py__init__+szIdentityMap.__init__cCs t|_dSr)_killed_add_unpresentr#r%r%r&_kill0szIdentityMap._killList[InstanceState[Any]]cCs tdSrNotImplementedErrorr#r%r%r& all_states3szIdentityMap.all_statesInstanceState[Any]boolstatercCs tdSrr,r$r2r%r%r&contains_state6szIdentityMap.contains_state_IdentityKeyType[Any]keyrcCs tdSrr,r$r7r%r%r& __contains__9szIdentityMap.__contains__cCs tdSrr,r3r%r%r& safe_discard<szIdentityMap.safe_discard_IdentityKeyType[_O]rcCs tdSrr,r8r%r%r& __getitem__?szIdentityMap.__getitem__N Optional[_O]r7defaultrcCs tdSrr,)r$r7r?r%r%r&getBszIdentityMap.getOptional[InstanceState[_O]]cCs tdSrr,r8r%r%r&fast_get_stateGszIdentityMap.fast_get_statezIterable[_IdentityKeyType[Any]]cCs |jSr)rkeysr#r%r%r&rCLszIdentityMap.keyszIterable[object]cCs tdSrr,r#r%r%r&valuesOszIdentityMap.valuesInstanceState[_O]cCs tdSrr,r3r%r%r&replaceRszIdentityMap.replacecCs tdSrr,r3r%r%r&addUszIdentityMap.addcCs tdSrr,r3r%r%r& _fast_discardXszIdentityMap._fast_discardr2r7rcCs||dS)zUoptional inlined form of add() which can assume item isn't present in the mapN)rGr$r2r7r%r%r&r)[szIdentityMap._add_unpresentcCs|j|_|jr|j|dSr)r_instance_dictmodifiedrrGr3r%r%r&_manage_incoming_statebsz"IdentityMap._manage_incoming_statecCs|`|jr|j|dSr)rKrLrdiscardr3r%r%r&_manage_removed_statehsz!IdentityMap._manage_removed_statecCs|jSr)rr#r%r%r& _dirty_statesmszIdentityMap._dirty_statescCs t|jS)z[return True if any InstanceStates present have been marked as 'modified'. )r0rr#r%r%r&check_modifiedpszIdentityMap.check_modifiedcCs||kSrr%r8r%r%r&has_keywszIdentityMap.has_keyintcCs t|jSr)lenrr#r%r%r&__len__zszIdentityMap.__len__)N)__name__ __module__ __qualname____annotations__r'r*r.r4r9r:r<r@rBrCrDrFrGrHr)rMrOrPrQrRrUr%r%r%r&r%s2 rc@seZdZUded<dddddZdd dd d Zd d d ddZd dd ddZd d d ddZd dddddZ dddddZ d4dddddd Z d!d"d#d$Z d%d"d&d'Z d(d"d)d*Zd+d"d,d-Zd dd d.d/Zd dd d0d1Zd dd d2d3ZdS)5WeakInstanceDictz/Dict[_IdentityKeyType[Any], InstanceState[Any]]rr;rr6cCs,td|j|}|}|dkr(t||SNrE)rrobjKeyErrorr$r7r2or%r%r&r<s zWeakInstanceDict.__getitem__r5r0cCsLz(||jkr |j|}|}nWdSWntk r>YdSX|dk SdSNF)rr\r]r^r%r%r&r9s    zWeakInstanceDict.__contains__r/r1cCsR|j|jkrJtr|jdk stz|j|j|kWStk rFYdSXndSdSr`)r7rr AssertionErrorr]r3r%r%r&r4s  zWeakInstanceDict.contains_statezOptional[InstanceState[Any]]cCs|jdk st|j|jkrbz|j|j}}Wntk rFd}YqfX||k r\||qfdSnd}||j|j<|||Sr)r7rarr]rOrM)r$r2existingZexisting_non_noner%r%r&rFs     zWeakInstanceDict.replacecCs|j}|dk st||jkrxz|j|}Wntk r>Yn:X||k rt|}|dk rxtdt||jfndS||j|<| |dS)NzZCan't attach instance %s; another instance with key %s is already present in this session.FT) r7rarr]r\sa_excInvalidRequestErrororm_util state_strrM)r$r2r7Zexisting_stater_r%r%r&rGs&    zWeakInstanceDict.addrrIcCs||j|<|j|_dSr)rrrKrJr%r%r&r)s zWeakInstanceDict._add_unpresentrAcCs |j|Sr)rr@r8r%r%r&rBszWeakInstanceDict.fast_get_stateNr=r>cCsX||jkr|Sztd|j|}Wntk r:|YSX|}|dkrP|S|SdSr[)rrr]r\)r$r7r?r2r_r%r%r&r@s  zWeakInstanceDict.getz6List[Tuple[_IdentityKeyType[Any], InstanceState[Any]]]rcCsJ|}g}|D]4}|}|j}|dk s.t|dk r|||fq|Sr)r.r\r7raappend)r$rDresultr2valuer7r%r%r&itemss zWeakInstanceDict.itemsz List[object]cCs4|}g}|D]}|}|dk r||q|Sr)r.r\rg)r$rDrhr2rir%r%r&rDs zWeakInstanceDict.valueszIterator[_IdentityKeyType[Any]]cCs t|Sr)iterrCr#r%r%r&__iter__szWeakInstanceDict.__iter__r+cCst|jSr)listrrDr#r%r%r&r.szWeakInstanceDict.all_statescCsP|j}|dk stz|j|}Wntk r4YnX||krL|j|ddSr)r7rarr]popr$r2r7str%r%r&rHs zWeakInstanceDict._fast_discardcCs||dSr)r:r3r%r%r&rNszWeakInstanceDict.discardcCsd|j}||jkr`|dk stz|j|}Wntk r>Yn"X||kr`|j|d||dSr)r7rrar]rnrOror%r%r&r:s  zWeakInstanceDict.safe_discard)N)rVrWrXrYr<r9r4rFrGr)rBr@rjrDrlr.rHrNr:r%r%r%r&rZ~s"     rZr/r5r rIcCstjdt|dddS)NzObject %s cannot be converted to 'persistent' state, as this identity map is no longer valid. Has the owning Session been closed?Zlkrp)code)rcrdrerf)r2r7r%r%r&r(&s r() __future__rtypingrrrrrrr r r r r rr!rrerrcZ_typingrr2rrobjectrrrZr(r%r%r%r&s0                   Y)