3

T'ícóã@sØdZddlmZddlmZddlmZmZmZm	Z	m
Z
mZmZm
Z
ddlmZmZddlmZddlmZddlmZerˆdd	lmZejeƒZGd
d„deƒZdd
ddddddddddddddœZGdd„dƒZdS)zLSphinx core events.

Gracefully adapted from the TextPress system by Armin.
é)Údefaultdict)Ú
attrgetter)Ú
TYPE_CHECKINGÚAnyÚCallableÚDictÚListÚ
NamedTupleÚTupleÚType)ÚExtensionErrorÚSphinxError)Ú__)Úlogging)Úsafe_getattr)ÚSphinxc@seZdZUeeedS)Ú
EventListenerN)Ú__name__Ú
__module__Ú__qualname__ÚintÚidrÚhandlerÚpriority©rrú//tmp/pip-build-gk9425m9/sphinx/sphinx/events.pyrs
rÚÚconfigzenv, added, changed, removedÚenvzenv, docnamez
env, docnameszdocname, source textz the doctree before being pickledz&env, read docnames, other env instancezenv, node, contnodezdomain, nodezdoctree, docnameÚ	exception)zbuilder-initedz
config-initedzenv-get-outdatedzenv-get-updatedz
env-purge-doczenv-before-read-docszenv-check-consistencyzsource-readzdoctree-readzenv-merge-infozmissing-referencezwarn-missing-referencezdoctree-resolvedzenv-updatedzbuild-finishedc@s eZdZdZdddœdd„Zeddœdd	„Zeeeed
œdd„Z	edd
œdd„Z
fdœeeee
edfedœdd„Zfdœeeee
edfedœdd„ZdS)ÚEventManagerzEvent manager for Sphinx.rN)ÚappÚreturncCs$||_tjƒ|_ttƒ|_d|_dS)Nr)r!Úcore_eventsÚcopyÚeventsrÚlistÚ	listenersÚnext_listener_id)Úselfr!rrrÚ__init__3s

zEventManager.__init__)Únamer"cCs(||jkrttdƒ|ƒ‚d|j|<dS)zRegister a custom Sphinx event.zEvent %r already presentrN)r%rr)r)r+rrrÚadd9s
zEventManager.add)r+Úcallbackrr"cCsJ||jkrttdƒ|ƒ‚|j}|jd7_|j|jt|||ƒƒ|S)z$Connect a handler to specific event.zUnknown event name: %sé)r%rrr(r'Úappendr)r)r+r-rÚlistener_idrrrÚconnect?s
zEventManager.connect)r0r"cCsBx<|jjƒD].}x(|dd…D]}|j|kr|j|ƒqWqWdS)zDisconnect a handler.N)r'ÚvaluesrÚremove)r)r0r'ÚlistenerrrrÚ
disconnectIs
zEventManager.disconnect)Úallowed_exceptions.)r+Úargsr6r"c	Gsôytjd|t|ƒdd…ƒWntk
r2YnXg}t|j|tdƒd}x |D]˜}y|j|j|j	f|žŽƒWqT|k
rŠ‚YqTt
k
rž‚YqTtk
rê}z2t|jddƒ}tt
dƒ|j|f||d|‚WYdd}~XqTXqTW|S)	zEmit a Sphinx event.z[app] emitting event: %r%sNédr)Úkeyrz*Handler %r for event %r threw an exception)Úmodname)ÚloggerÚdebugÚreprÚ	ExceptionÚsortedr'rr/rr!r
rrr)	r)r+r6r7Úresultsr'r4Úexcr:rrrÚemitPs$
,zEventManager.emitcGs0x*|j|f|žd|iŽD]}|dk	r|SqWdS)zŠEmit a Sphinx event and returns first result.

        This returns the result of the first handler that doesn't return ``None``.
        r6N)rB)r)r+r6r7ÚresultrrrÚemit_firstresultjszEventManager.emit_firstresult)rrrÚ__doc__r*Ústrr,rrr1r5rr
rr>rrBrDrrrrr 0s
&r N)rEÚcollectionsrÚoperatorrÚtypingrrrrrr	r
rZ
sphinx.errorsrr
Z
sphinx.localerZsphinx.utilrZsphinx.util.inspectrZsphinx.applicationrÚ	getLoggerrr;rr#r rrrrÚ<module>s6(