3

T'ícðEã@s®dZddlmZmZmZmZmZmZmZddl	m
Z
ddlmZm
Z
ddlmZddlmZddlmZmZddlmZdd	lmZdd
lmZddlmZmZddlmZdd
l m!Z!ddl"m#Z#m$Z$ddl%m&Z&ddl'm(Z(ddl)m*Z*m+Z+m,Z,ddl-m.Z.ddl/m0Z0m1Z1ddl2m3Z3e(j4e5ƒZ6Gdd„deee7e7fƒZ8Gdd„de8ƒZ9Gdd„de9ƒZ:Gdd„de.ƒZ;Gdd„de&ƒZ<Gdd „d eƒZ=eee7efd!œd"d#„Z>d$S)%zThe JavaScript domain.é)ÚAnyÚDictÚIteratorÚListÚOptionalÚTupleÚcast)Únodes)ÚElementÚNode)Ú
directives)Úaddnodes)Údesc_signatureÚpending_xref)ÚSphinx)ÚBuilder)ÚObjectDescription)ÚDomainÚObjType)Ú_pseudo_parse_arglist)ÚBuildEnvironment)Ú_Ú__)ÚXRefRole)Úlogging)ÚFieldÚGroupedFieldÚ
TypedField)ÚSphinxDirective)Úmake_idÚmake_refnode)Ú
OptionSpecc@sºeZdZUdZdZdZejejdœZe	e
edœdd„Ze
eee
e
fdœdd	„Zee
e
fe
ed
dœdd
„Ze
ee
e
fe
dœdd„Zd
dœdd„Zd
dœdd„Ze
e
dœdd„Zd
S)ÚJSObjectz-
    Description of a JavaScript object.
    F)ÚnoindexÚnoindexentry)ÚreturncCsgS)N©)Úselfr&r&ú;/tmp/pip-build-gk9425m9/sphinx/sphinx/domains/javascript.pyÚget_display_prefix-szJSObject.get_display_prefix)ÚsigÚsignoder%cCsÚ|jƒ}d|krJ|dd…dkrJ|jddƒ\}}|jƒ}|dd
…jƒ}n|}d}|jjjddƒ}|jjjdƒ}|}z6y|jddƒ\}}	Wntk
r¦|}	d}YnXWd|	}|rÈ|rÈdj||gƒ}n|dkrØ|rØ|}X|}
|rðdj||gƒ}
||d	<||d
<|
|d<|jƒ}|r(|t	j
d|žŽ7}d}|r8|}n
|rB|}|r’t	jddƒ}
x4|jdƒD]&}|
t	j||ƒ7}
|
t	j
ddƒ7}
q`W||
7}|t	jddt	j||ƒƒ7}|jrÒ|sÈ|t	jƒ7}n
t||ƒ|
|fS)zÑBreaks down construct signatures

        Parses out prefix and argument list from construct definition. The
        namespace and class will be determined by the nesting of domain
        directives.
        ú(éNú)z	js:objectz	js:moduleÚ.ÚÚmoduleÚobjectÚfullnameéÿÿÿÿr4)r0r0)ÚstripÚsplitÚenvÚref_contextÚgetÚrsplitÚ
ValueErrorÚjoinr)r
Zdesc_annotationZdesc_addnameZ
desc_sig_nameZdesc_sig_punctuationZ	desc_nameÚ
has_argumentsZdesc_parameterlistr)r'r*r+ÚmemberZarglistÚprefixÚmod_nameÚnameZ
member_prefixÚmember_namer3Zdisplay_prefixZ
actual_prefixZaddNameÚpr&r&r(Úhandle_signature1s\
zJSObject.handle_signatureN)Úname_objr*r+r%c
Csæ|jjjdƒ}|r|dnd|d}t|j|jjd|ƒ}|dj|ƒ|j|ƒ}||jjjkrz||dkrz|dj|ƒ|jjj	|ƒt
t|jjdƒƒ}|j
||j||dd|jkrâ|j||ƒ}	|	râ|jd	jd
|	|ddfƒdS)Nz	js:moduler/r0rÚidsÚjs)Úlocationr$ÚentriesÚsingle)r7r8r9rÚstateÚdocumentÚappendÚmake_old_idrFÚnote_explicit_targetrÚJavaScriptDomainÚ
get_domainÚnote_objectÚobjtypeÚoptionsÚget_index_textZ	indexnode)
r'rEr*r+r@r3Únode_idÚold_node_idÚdomainÚ	indextextr&r&r(Úadd_target_and_indexos

zJSObject.add_target_and_index)Ú
objectnamerEr%cCs||\}}|jdkr2|s"tdƒ|Stdƒ||fS|jdkrHtdƒ|S|jdkr^tdƒ|S|jdkrxtd	ƒ||fSd
S)NÚfunctionz%s() (built-in function)z%s() (%s method)Úclassz%s() (class)Údataz %s (global variable or constant)Ú	attributez%s (%s attribute)r0)rSr)r'r[rErAÚobjr&r&r(rU†s



zJSObject.get_index_textcCshd}|jr4|jjƒ\}}|r&|jdƒnd}|jr4|}|rd||jjd<|jrd|jjjdgƒ}|j|ƒdS)aHandle object nesting before content

        :py:class:`JSObject` represents JavaScript language constructs. For
        constructs that are nestable, this method will build up a stack of the
        nesting hierarchy so that it can be later de-nested correctly, in
        :py:meth:`after_content`.

        For constructs that aren't nestable, the stack is bypassed, and instead
        only the most recent object is tracked. This object prefix name will be
        removed with :py:meth:`after_content`.

        The following keys are used in ``self.env.ref_context``:

            js:objects
                Stores the object prefix history. With each nested element, we
                add the object prefix to this list. When we exit that object's
                nesting level, :py:meth:`after_content` is triggered and the
                prefix is removed from the end of the list.

            js:object
                Current object prefix. This should generally reflect the last
                element in the prefix history
        Nr/z	js:objectz
js:objects)ÚnamesÚpopr5Ú
allow_nestingr7r8Ú
setdefaultrM)r'r?Zobj_nameZobj_name_prefixÚobjectsr&r&r(Úbefore_content”szJSObject.before_contentcCs\|jjjdgƒ}|jr8y|jƒWntk
r6YnXt|ƒdkrL|dnd|jjd<dS)a^Handle object de-nesting after content

        If this class is a nestable object, removing the last nested class prefix
        ends further nesting in the object.

        If this class is not a nestable object, the list of classes should not
        be altered as we didn't affect the nesting levels in
        :py:meth:`before_content`.
        z
js:objectsrr-Nz	js:objectr4)r7r8rdrcrbÚ
IndexErrorÚlen)r'rer&r&r(Ú
after_content¸s
zJSObject.after_content)r3r%cCs|jddƒS)z«Generate old styled node_id for JS objects.

        .. note:: Old Styled node_id was used until Sphinx-3.0.
                  This will be removed in Sphinx-5.0.
        ú$Z_S_)Úreplace)r'r3r&r&r(rNËszJSObject.make_old_id)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r=rcrÚflagÚoption_specr!rrr)ÚstrrrrDrZrUrfrirNr&r&r&r(r"s
>$r"c	@sdeZdZdZdZededƒdd	dded
edƒd	dddededƒdddededƒdddgZ	dS) Ú
JSCallablez<Description of a JavaScript function, method or constructor.TÚ	argumentsÚ	ArgumentsÚargumentÚargÚ	parameterÚparamÚfuncÚ	paramtypeÚtype)ÚlabelraZtyperolenameZ	typenamesÚerrorsZThrowsÚthrows)r}ZrolenameraZcan_collapseZreturnvalueZReturnsFÚreturnsr%)r}Úhas_argraZ
returntypezReturn typeÚrtypeN)rvrwrxry)r{r|)r)r€r%)r‚)
rlrmrnror=rrrrZdoc_field_typesr&r&r&r(rsÔs
rsc@s&eZdZdZdZeedœdd„ZdS)Ú
JSConstructorz,Like a callable but with a different prefix.T)r%cCstjddƒtjƒgS)Nr])r
Zdesc_sig_keywordZdesc_sig_space)r'r&r&r(r)ës
z JSConstructor.get_display_prefixN)rlrmrnrorcrrr)r&r&r&r(rƒæsrƒc@sReZdZUdZdZdZdZdZdej	iZ
e
ee
dœdd„Zeed	œd
d„ZdS)
ÚJSModulea÷
    Directive to mark description of a new JavaScript module.

    This directive specifies the module name that will be used by objects that
    follow this directive.

    Options
    -------

    noindex
        If the ``noindex`` option is specified, no linkable elements will be
        created, and the module won't be added to the global module index. This
        is useful for splitting up the module definition across multiple
        sections or files.

    :param mod_name: Module name
    Fr-rr#)r%c
Cs|jdjƒ}||jjd<d|jk}g}|stt|jjdƒƒ}t|j|j	j
d|ƒ}|j||ƒ|j|d||jj
|jfdtjdd|gdd	}|j|ƒ}||j	j
jkrÂ||d
krÂ|d
j|ƒ|j	j
j|ƒ|j|ƒtdƒ|}tjd||ddfgd
}	|j|	ƒ|S)Nrz	js:moduler#rGr1)rHr0T)rFZismodrFz%s (module)rJ)rI)rtr5r7r8rTrrPrQrrKrLÚnote_modulerRÚdocnameÚlinenor	ÚtargetrNrFrMrOrr
Úindex)
r'r@r#ÚretrXrVrˆrWrYÚinoder&r&r(Úruns(




zJSModule.run)Úmodnamer%cCsd|S)z«Generate old styled node_id for JS modules.

        .. note:: Old Styled node_id was used until Sphinx-3.0.
                  This will be removed in Sphinx-5.0.
        zmodule-r&)r'rr&r&r(rN)szJSModule.make_old_idN)rlrmrnroZhas_contentZrequired_argumentsZoptional_argumentsZfinal_argument_whitespacerrprqr!rrrŒrrrNr&r&r&r(r„ðs
r„c@s,eZdZeeeeeeeefdœdd„ZdS)Ú
JSXRefRole)r7ÚrefnodeÚhas_explicit_titleÚtitlerˆr%cCs¢|jjdƒ|d<|jjdƒ|d<|sv|jdƒ}|jdƒ}|dd…dkrv|dd…}|jdƒ}|d	krv||dd…}|dd…dkrš|dd…}d|d<||fS)
Nz	js:objectz	js:moduler/ú~rr-TÚrefspecificr4)r8r9ÚlstripÚrfind)r'r7rrr‘rˆÚdotr&r&r(Úprocess_link3s


zJSXRefRole.process_linkN)	rlrmrnrr
Úboolrrrr—r&r&r&r(rŽ2srŽc
@seZdZUdZdZdZeedƒdƒeedƒdƒeedƒdƒeed	ƒd	ƒeed
ƒdƒeedƒd
ƒdœZe	e	e
eeedœZ
eddeddeddeƒeƒeƒdœZiidœZeeeeeeefffeeeeeeeffdœdd„ƒZd4eeeeddœdd„Zeeeeeeffdœdd„ƒZeeddœdd„Zeddœd d!„Zeeedd"œd#d$„Zd5eeeeeeeeeeeeffd&œd'd(„Zeee eee!e"e#e"d)œd*d+„Z$eee ee!e"eeee"fd,œd-d.„Z%e&eeeeeeefdœd/d0„Z'e"ed1œd2d3„Z(dS)6rPzJavaScript language domain.rGZ
JavaScriptr\rzÚmethodÚmethr]r^r_Úattrr1Úmod)r\r™r]r^r_r1T)Z
fix_parens)rzršr]r^r›rœ)reÚmodules)r%cCs|jjdiƒS)Nre)r^rd)r'r&r&r(rehszJavaScriptDomain.objectsN)r3rSrVrHr%cCsJ||jkr2|j|d}tjtdƒ|||||d|jj||f|j|<dS)Nrz.duplicate %s description of %s, other %s in %s)rH)reÚloggerÚwarningrr7r†)r'r3rSrVrHr†r&r&r(rRls


zJavaScriptDomain.note_objectcCs|jjdiƒS)Nr)r^rd)r'r&r&r(rtszJavaScriptDomain.modules)rrVr%cCs|jj|f|j|<dS)N)r7r†r)r'rrVr&r&r(r…xszJavaScriptDomain.note_module)r†r%cCsfx0t|jjƒƒD]\}\}}}||kr|j|=qWx.t|jjƒƒD]\}\}}||krB|j|=qBWdS)N)ÚlistreÚitemsr)r'r†r3Úpkg_docnameZ_node_idZ_lrr&r&r(Ú	clear_doc{szJavaScriptDomain.clear_doc)ÚdocnamesÚ	otherdatar%c	Cspx6|djƒD]&\}\}}}||kr|||f|j|<qWx2|djƒD]"\}\}}||krF||f|j|<qFWdS)Nrer)r¡rer)	r'r¤r¥r3ÚfnrVrSr@r¢r&r&r(Úmerge_domaindataƒsz!JavaScriptDomain.merge_domaindatar)r7r@r?rAÚtypÚsearchorderr%c
Cs¸|dd…dkr|dd…}g}|r>|r>|jdj|||gƒƒ|rV|jdj||gƒƒ|rn|jdj||gƒƒ|j|ƒ|dkrˆ|jƒd}x|D]}	|	|jkr’|	}q’W||jj|ƒfS)Néz()r/réþÿÿÿr«)rMr<Úreverserer9)
r'r7r@r?rAr¨r©ZsearchesZnewnameÚsearch_namer&r&r(Úfind_objŒs"


zJavaScriptDomain.find_obj)r7ÚfromdocnameÚbuilderr¨rˆÚnodeÚcontnoder%c
Cs`|jdƒ}|jdƒ}	|jdƒr"dnd}
|j|||	|||
ƒ\}}|sFdSt|||d|d||ƒS)Nz	js:modulez	js:objectr“r-r)r9Úhasattrr®r )
r'r7r¯r°r¨rˆr±r²r@r?r©rAr`r&r&r(Úresolve_xref¤s

zJavaScriptDomain.resolve_xref)r7r¯r°rˆr±r²r%cCsb|jdƒ}|jdƒ}|j||||ddƒ\}	}
|
s4gSd|j|
dƒt|||
d|
d||	ƒfgS)Nz	js:modulez	js:objectr-zjs:rªr)r9r®Zrole_for_objtyper )r'r7r¯r°rˆr±r²r@r?rAr`r&r&r(Úresolve_any_xref¯s

z!JavaScriptDomain.resolve_any_xrefccs8x2t|jjƒƒD] \}\}}}|||||dfVqWdS)Nr-)r rer¡)r'Zrefnamer†rVr¨r&r&r(Úget_objectsºszJavaScriptDomain.get_objects)r±r%cCsD|jdƒ}|jdƒ}|jdƒ}|dkr*dSdjtd|||gƒƒSdS)Nz	js:modulez	js:objectZ	reftargetr/)r9r<Úfilter)r'r±rr?rˆr&r&r(Úget_full_qualified_name¾s


z(JavaScriptDomain.get_full_qualified_name)N)r))rlrmrnrorAr}rrZobject_typesrsrƒr"r„rrŽZrolesZinitial_datarrrrÚpropertyrerrRrr…r£rr§rÚintr®rrr
rr´rµrr¶r¸r&r&r&r(rPFsP

$" 
.		"rP)Úappr%cCs|jtƒdddddœS)NÚbuiltinrªT)ÚversionZenv_versionZparallel_read_safeZparallel_write_safe)Z
add_domainrP)r»r&r&r(ÚsetupÈs

r¾N)?roÚtypingrrrrrrrZdocutilsr	Zdocutils.nodesr
rZdocutils.parsers.rstrZsphinxr
Zsphinx.addnodesrrZsphinx.applicationrZsphinx.buildersrZsphinx.directivesrZsphinx.domainsrrZsphinx.domains.pythonrZsphinx.environmentrZ
sphinx.localerrZsphinx.rolesrZsphinx.utilrZsphinx.util.docfieldsrrrZsphinx.util.docutilsrZsphinx.util.nodesrr Zsphinx.util.typingr!Ú	getLoggerrlržrrr"rsrƒr„rŽrPr¾r&r&r&r(Ú<module>s:$
9
B