zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
U
¸ý°df<ã@sâUdZddlmZddlZddlmZddlmZddlmZddlmZddlmZdd    lm    Z    dd
lm
Z
dd lm Z dd lm Z dd lm Z ddlmZddlmZddlZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZe e¡Zde d<dddœdd „Z!Gd!d"„d"ƒZ"Gd#d$„d$eeƒZ#Gd%d&„d&e#eƒZ$d'd(d)œd*d+„Z%Gd,d-„d-eeƒZ&Gd.d/„d/e&eƒZ'Gd0d1„d1e#eƒZ(Gd2d3„d3eeƒZ)Gd4d5„d5e)eƒZ*dS)6aµBase implementation classes.
 
The public-facing ``Events`` serves as the base class for an event interface;
its public attributes represent different kinds of events.   These attributes
are mirrored onto a ``_Dispatch`` class, which serves as a container for
collections of listener functions.   These collections are represented both
at the class level of a particular ``_Dispatch`` class as well as within
instances of ``_Dispatch``.
 
é)Ú annotationsN)ÚAny)Úcast)ÚDict)ÚGeneric)ÚIterator)ÚList)ÚMutableMapping)ÚOptional)Úoverload)ÚTuple)ÚType)ÚUnioné)Ú_ClsLevelDispatch)Ú_EmptyListener)Ú_InstanceLevelDispatch)Ú_JoinedListener)Ú_ET)Ú    _EventKeyé)Úutil)ÚLiteralz8MutableMapping[str, List[Type[_HasEventsDispatch[Any]]]]Ú _registrarsÚstrÚbool©ÚnameÚreturncCs| d¡ r|dkp| d¡S)NÚ_ÚdispatchZ    _sa_event)Ú
startswith)r©r"úLd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\sqlalchemy/event/base.pyÚ_is_event_name1sÿþr$c@s eZdZdZdddœdd„ZdS)Ú_UnpickleDispatchzSerializable callable that re-generates an instance of
    :class:`_Dispatch` given a particular :class:`.Events` subclass.
 
    ú    Type[_ET]ú_Dispatch[_ET])Ú _instance_clsrcCs>|jD]*}d|jkrtd|jdjƒ |¡Sqtdƒ‚dS)Nr r'z*No class with a 'dispatch' member present.)Ú__mro__Ú__dict__rr Ú
_for_classÚAttributeError)Úselfr(Úclsr"r"r#Ú__call__As
 
 
ÿþ
z_UnpickleDispatch.__call__N)Ú__name__Ú
__module__Ú __qualname__Ú__doc__r/r"r"r"r#r%;sr%c@sLeZdZUdZded<dddœdd„Zd    d
d œd d „Zeddœdd„ƒZdS)Ú_DispatchCommonr"úOptional[Type[_ET]]r(ú_DispatchCommon[_ET]ú_JoinedDispatcher[_ET]©ÚotherrcCs
tƒ‚dS©N©ÚNotImplementedError)r-r9r"r"r#Ú_joinPsz_DispatchCommon._joinrú_InstanceLevelDispatch[_ET]rcCs
tƒ‚dSr:r;©r-rr"r"r#Ú __getattr__Ssz_DispatchCommon.__getattr__úType[_HasEventsDispatch[_ET]]©rcCs
tƒ‚dSr:r;©r-r"r"r#Ú_eventsVsz_DispatchCommon._eventsN)    r0r1r2Ú    __slots__Ú__annotations__r=r@ÚpropertyrDr"r"r"r#r4Ks
r4c@süeZdZUdZdZded<e ¡Zded<ded<d    ed
<d ed <d ed<ded<d<dd dœdd„Z    dddœdd„Z
e ddœdd„ƒZ dd d!d"œd#d$„Z d%d&d'œd(d)„Zd*d&d+œd,d-„Zd.d/d0œd1d2„Zd3dœd4d5„Zd=d&dd!d7œd8d9„Zd!dœd:d;„ZdS)>Ú    _DispatchaMMirror the event listening definitions of an Events class with
    listener collections.
 
    Classes which define a "dispatch" member will return a
    non-instantiated :class:`._Dispatch` subclass when the member
    is accessed at the class level.  When the "dispatch" member is
    accessed at the instance level of its owner, an instance
    of the :class:`._Dispatch` class is returned.
 
    A :class:`._Dispatch` class is generated for each :class:`.Events`
    class defined, by the :meth:`._HasEventsDispatch._create_dispatcher_class`
    method.  The original :class:`.Events` classes remain untouched.
    This decouples the construction of :class:`.Events` subclasses from
    the implementation used by the event internals, and allows
    inspecting tools like Sphinx to work in an unsurprising
    way against the public API.
 
    )Ú_parentr(r*Ú_empty_listenersrZ_active_historyz9MutableMapping[Type[_ET], Dict[str, _EmptyListener[_ET]]]Ú_empty_listener_regzDict[str, _EmptyListener[_ET]]rJz    List[str]Ú _event_namesr5r(zType[_JoinedDispatcher[_ET]]Ú_joined_dispatch_clsrArDNzOptional[_Dispatch[_ET]])ÚparentÚ instance_clscsn||_ˆ|_ˆrd|dk    st‚z|jˆ|_Wqjtk
r`‡fdd„|jDƒ|_|jˆ<YqjXni|_dS)Ncsi|]}|jt|ˆƒ“qSr")rr)Ú.0Úls©rOr"r#Ú
<dictcomp>—sÿz&_Dispatch.__init__.<locals>.<dictcomp>)rIr(ÚAssertionErrorrKrJÚKeyErrorÚ_event_descriptors)r-rNrOr"rRr#Ú__init__ˆs 
þþ
ÿ
z_Dispatch.__init__rr>rcCsBz|j|}Wntk
r*t|ƒ‚YnXt||j|ƒ|SdSr:)rJrUr,Úsetattrr)r-rrQr"r"r#r@žs z_Dispatch.__getattr__z Iterator[_ClsLevelDispatch[_ET]]rBccs|jD]}t||ƒVqdSr:)rLÚgetattr)r-Úkr"r"r#rV©s
z_Dispatch._event_descriptorsú_EventKey[_ET]rÚNone©Ú    event_keyÚkwrcKs|jj|f|ŽSr:)rDÚ_listen©r-r^r_r"r"r#r`°sz_Dispatch._listenr&r')rOrcCs | ||¡Sr:)Ú    __class__)r-rOr"r"r#r+³sz_Dispatch._for_classr)ÚinstancercCs|j}| |¡Sr:)rbr+)r-rcrOr"r"r#Ú _for_instance¶sz_Dispatch._for_instancer6r7r8cCs<d|jjkr0td|jjtfd|jiƒ}||j_| ||¡S)z¡Create a 'join' of this :class:`._Dispatch` and another.
 
        This new dispatcher will dispatch events to both
        :class:`._Dispatch` objects.
 
        rMzJoined%srE)rbr*Útyper0Ú_JoinedDispatcherrLrM)r-r9r.r"r"r#r=ºs 
ýz_Dispatch._joinzUnion[str, Tuple[Any, ...]]cCstƒ|jffSr:)r%r(rCr"r"r#Ú
__reduce__Êsz_Dispatch.__reduce__T)r9Úonly_propagatercCs8|jD],}t|tƒrqt||jƒ |¡j||dqdS)zIPopulate from the listeners in another :class:`_Dispatch`
        object.)rhN)rVÚ
isinstancerrYrÚ
for_modifyÚ_update)r-r9rhrQr"r"r#rkÍs
 
ÿz_Dispatch._updatecCs|jD]}| |¡ ¡qdSr:)rVrjÚclear)r-rQr"r"r#Ú_clearÙs
z_Dispatch._clear)N)T)r0r1r2r3rErFÚweakrefÚWeakKeyDictionaryrKrWr@rGrVr`r+rdr=rgrkrmr"r"r"r#rH[s.
þ
 
ý ÿ rHrAr\)r.rcCs.|jjD] }t| |¡t|st|=qdSr:)r rLrÚremove)r.rZr"r"r#Ú_remove_dispatcherÞs rqc    @s®eZdZUded<ded<ejr0dddœdd    „Zd
d œd d „Zeddddœdd„ƒZ    edddddœdddddd
dœdd„ƒZ
e ddddœdd„ƒZ eddd d
d!œd"d#„ƒZ d$S)%Ú_HasEventsDispatchr5Ú_dispatch_targetr'r rr>rcCsdSr:r"r?r"r"r#r@òsz_HasEventsDispatch.__getattr__r\rBcCs| |j|j|j¡dS)zOIntercept new Event subclasses and create associated _Dispatch
        classes.N)Ú_create_dispatcher_classr0Ú    __bases__r*©r.r"r"r#Ú__init_subclass__õsz$_HasEventsDispatch.__init_subclass__úUnion[_ET, Type[_ET]]úOptional[Union[_ET, Type[_ET]]]©ÚtargetÚ
identifierrcCs
tƒ‚dSr:r;)r.r{r|r"r"r#Ú _accept_withûsz_HasEventsDispatch._accept_withF©Ú    propagateÚinsertÚnamedÚasyncior[r©r^rr€rr‚rcCs
tƒ‚dSr:r;©r.r^rr€rr‚r"r"r#r`s
z_HasEventsDispatch._listenrAúType[_Dispatch[_ET]])ÚklassÚ dispatch_clsrcCs|dƒ|_||_|jSr:)r rD)r†r‡r"r"r#Ú _set_dispatch s
 
z _HasEventsDispatch._set_dispatchzTuple[type, ...]zDict[str, Any])Ú    classnameÚbasesÚdict_rc Cs t|dƒr|jj}nt}dd„|Dƒ}tdtd||fd|iƒƒ}||_| ||¡}|jD](}t||t    |||ƒƒt
|  |¡qZ|j D]B}    t |    tƒrŠ|    tk    rŠ|    jjjD] }
t||
j|
ƒ|j  |
j¡qªqŠt|ddƒr|j} | dk    sît‚t| dƒrd    | jkrt|ƒ| _n
t|ƒ| _dS)
zVCreate a :class:`._Dispatch` class corresponding to an
        :class:`.Events` class.r cSsg|]}t|ƒr|‘qSr")r$)rPrZr"r"r#Ú
<listcomp>*sz?_HasEventsDispatch._create_dispatcher_class.<locals>.<listcomp>r…z
%sDispatchrErsNÚ_slots_dispatch)Úhasattrr rbrHrrerLrˆrXrrÚappendruÚ
issubclassrDrVrrYrsrTrEÚslots_dispatcherÚ
dispatcher) r.r‰rŠr‹Z dispatch_baseZ event_namesr‡Z dispatch_instrZZsuper_rQZdispatch_target_clsr"r"r#rts>
 
 
ýþ     
 
 ÿþ z+_HasEventsDispatch._create_dispatcher_classN)r0r1r2rFÚtypingÚ TYPE_CHECKINGr@rwÚ classmethodr}r`Ú staticmethodrˆrtr"r"r"r#rrås"
ù  rrc    @steZdZdZeddddœdd„ƒZeddddd    œd
d d d d d d œdd„ƒZed
d dœdd„ƒZed dœdd„ƒZdS)ÚEventsz>Define event listening functions for a particular target type.rxrryrzcshdddœ‡fdd„ }dddœ‡fdd„ }tˆd    ƒrd||jjƒs`|t|jjƒs`|tƒrd||jjƒrdˆSdS)
Nú    Type[Any]r)Útypesrcst‡fdd„|DƒƒS)Nc3s|]}tˆj|ƒVqdSr:)rir )rPÚt©r{r"r#Ú    <genexpr>Tsz;Events._accept_with.<locals>.dispatch_is.<locals>.<genexpr>)Úall)r™r›r"r#Ú dispatch_isSsz(Events._accept_with.<locals>.dispatch_is)ršrcsttdˆjƒj|ƒS)Nr7)rirr rN)ršr›r"r#Údispatch_parent_isVs ÿz/Events._accept_with.<locals>.dispatch_parent_isr )rŽr rbrerf)r.r{r|ržrŸr"r›r#r}Os
 
ÿ þü
ûzEvents._accept_withFr~r[rr\rƒcCs|j||||ddS)Nr~)Z base_listenr„r"r"r#r`ks
ÿzEvents._listen)r^rcCs | ¡dSr:)rp)r.r^r"r"r#Ú_removeyszEvents._removerBcCs|j ¡dSr:)r rmrvr"r"r#rm}sz Events._clearN)    r0r1r2r3r•r}r`r rmr"r"r"r#r—Lsù r—c@sreZdZUdZdZded<ded<ded<dddœd    d
„Zd d d œdd„Zddddœdd„Ze    ddœdd„ƒZ
dS)rfz5Represent a connection between two _Dispatch objects.©ÚlocalrNr(r6r¢rNr5r()r¢rNcCs||_||_|jj|_dSr:r¡)r-r¢rNr"r"r#rW‹sz_JoinedDispatcher.__init__rz_JoinedListener[_ET]rcCs.t|j|ƒ}t|j|j|ƒ}t||j|ƒ|Sr:)rYr¢rrNrrX)r-rrQZjlr"r"r#r@’s z_JoinedDispatcher.__getattr__r[rr\r]cKs|jj|f|ŽSr:)rNr`rar"r"r#r`šsz_JoinedDispatcher._listenrArBcCs|jjSr:)rNrDrCr"r"r#rDsz_JoinedDispatcher._eventsN) r0r1r2r3rErFrWr@r`rGrDr"r"r"r#rf‚s
rfc@s\eZdZdZddœdd„Zedddd    œd
d „ƒZed dd d    œdd „ƒZd dd d    œdd „ZdS)r’zŸDescriptor used by target classes to
    deliver the _Dispatch class at the class level
    and produce new _Dispatch instances for target
    instances.
 
    rA)ÚeventscCs|j|_||_dSr:)r r£)r-r£r"r"r#rWªszdispatcher.__init__z Literal[None]r˜r…©Úobjr.rcCsdSr:r"©r-r¥r.r"r"r#Ú__get__®szdispatcher.__get__rr6cCsdSr:r"r¦r"r"r#r§´sc
Cs`|dkr|jS|j |¡}z||jd<Wn2tk
rZ}ztd|fƒ|‚W5d}~XYnX|S)Nr zGtarget %r doesn't have __dict__, should it be defining _slots_dispatch?)r rdr*r,Ú    TypeError)r-r¥r.ÚdispZaer"r"r#r§¸s ÿÿýN)r0r1r2r3rWr r§r"r"r"r#r’¢sr’c@seZdZddddœdd„ZdS)r‘rr˜r¤cCs4|dkr|jSt|dƒr|jS|j |¡}||_|S)Nr)r rŽrrd)r-r¥r.r©r"r"r#r§Ès
 zslots_dispatcher.__get__N)r0r1r2r§r"r"r"r#r‘Çsr‘)+r3Ú
__future__rr“rrrrrrr    r
r r r rrnÚattrrrrrÚregistryrrÚrZ util.typingrÚ defaultdictÚlistrrFr$r%r4rHrqrrr—rfr’r‘r"r"r"r#Ú<module>sH
                    þ
 
g6 %