U kf# @sZdZddlmZddlZddlmZddlmZddlmZddlmZddlmZdd lm Z d d l m Z d d l m Z d dl mZd dlmZejrd dlmZd dlmZeeeeeedeffZd0dddddddZdddddddZdddd d!d"Zdd#ddd$d%d&Zddddd$d'd(Zd)ddd*d+d,Zdd)ddd-d.d/ZdS)1zhRoutines to handle adaption of legacy call signatures, generation of deprecation notes and docstrings. ) annotationsN)Any)Callable)List)Optional)Tuple)Type)_ET)_ListenerFnType)util) FullArgSpec)_ClsLevelDispatch)_HasEventsDispatch.strz List[str]zOptional[Callable[..., Any]]z2Callable[[Callable[..., Any]], Callable[..., Any]])sinceargnames converterreturncsdddfdd }|S)a_legacy sig decorator :param since: string version for deprecation warning :param argnames: list of strings, which is *all* arguments that the legacy version accepted, including arguments that are still there :param converter: lambda that will accept tuple of this full arg signature and return tuple of new arg signature. zCallable[..., Any])fnrcs&t|dsg|_|jf|S)N_legacy_signatures)hasattrrappend)rrrrG/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/event/legacy.pyleg3s z_legacy_signature..legr)rrrrrrr_legacy_signature#srz_ClsLevelDispatch[_ET]r r)dispatch_collectionrargspecrcsjD]\ddkr.dddndtt|jkrt|jkrdjdjrjdnd f}d jj|fdk rrt d d d d fd d }n d d d d fdd }|SqS)Nz**kwTrFz def %s(%s%s), , **kwzThe argument signature for the "%s.%s" event listener has changed as of version %s, and conversion for the old argument signature will be removed in a future release. The new signature is "%s"r)argskwrcs&tjddk st|S)Nversion)r warn_deprecatedAssertionError)r%r&)convrr warning_txtrrwrap_leg`s z%_wrap_fn_for_legacy..wrap_legcsJtjdttj|fddD}r>||S|SdS)Nr'csg|] }|qSrr).0nameZargdictrr jsz9_wrap_fn_for_legacy..wrap_leg..)r r)dictzip arg_names)r%r&Zargs_from_dict)rrrhas_kwrr,r0rr-gs  ) legacy_signatureslenr%boolvarkwr/joinr4clsnamer*)rrr Z formatted_defr-r)rr+rrr5rr,r_wrap_fn_for_legacy<s6     r<)textindentrcsdfdd|dDS)N c3s|]}|VqdSNr)r.liner>rr vsz_indent..)r:split)r=r>rrBr_indentusrEr)r sample_targetrrcCstddd|jddDd}|jr@tdd|jD}nd}d}||rVd |nd |j|jrfd nd d |j||d ;}|S)Nr?css|]}dd|iVqdS)z%(arg)s = kw['%(arg)s']argNr)r.rGrrrrCsz+_standard_listen_example..rr z css|]\}}}|VqdSr@r)r.rr%r+rrrrCszfrom sqlalchemy import event @event.listens_for(%(sample_target)s, '%(event_name)s') def receive_%(event_name)s(%(named_event_arguments)s%(has_kw_arguments)s): "listen for the '%(event_name)s' event" # ... (event handling logic) ... z (arguments as of %s)r$r#r") current_since event_namehas_kw_argumentsnamed_event_argumentsexample_kw_argrF)rEr:r4r6max__name__r5)rrFrrLrHr=rrr_standard_listen_exampleys,       rOc CsDd}|jD]4\}}}|d||j|jr(dndd||d7}q |S)Nr$a& # DEPRECATED calling style (pre-%(since)s, will be removed in a future release) @event.listens_for(%(sample_target)s, '%(event_name)s') def receive_%(event_name)s(%(named_event_arguments)s%(has_kw_arguments)s): "listen for the '%(event_name)s' event" # ... (event handling logic) ... z **kwr")rrIrJrKrF)r6rNr5r:)rrFrr=rr%r+rrr_legacy_listen_exampless rPzType[_HasEventsDispatch[_ET]])parent_dispatch_clsrrc sJjd\}}}d|jjdfddjDjr@dnddS) Nra= .. versionchanged:: %(since)s The :meth:`.%(clsname)s.%(event_name)s` event now accepts the arguments %(named_event_arguments)s%(has_kw_arguments)s. Support for listener functions which accept the previous argument signature(s) listed above as "deprecated" will be removed in a future release.r"c3s"|]}djj|dVqdS)z6:paramref:`.%(clsname)s.%(event_name)s.%(param_name)s`)r;rI param_nameN)rNr/)r.rRrrQrrrCsz-_version_signature_changes..r#r$)rr;rIrKrJ)r6rNr/r:r4r5)rQrrr%r+rrSr_version_signature_changess rT)rrQrrcCs`d}t|dd}|tt|||d}|jrP|tt|||d7}|t||7}t|j|dS)Nz@.. container:: event_signatures Example argument forms:: Z_target_class_docobjz r ) getattrrErOr6rPrTr Zinject_docstring_text__doc__)rrQrheaderrFr=rrr_augment_fn_docss"   rY)N)rW __future__rtypingrrrrrrregistryr r r$r Z util.compatr TYPE_CHECKINGattrrbaserrZ_LegacySignatureTyperr<rErOrPrTrYrrrrs0             9)