3

T'íc[ã"@s0dZddlZddlZddlmZmZmZmZmZm	Z	m
Z
mZmZm
Z
mZddlmZddlmZmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZeràddl m!Z!dd
l"m#Z#ddl$m%Z%ddl&m'Z'ej(e)ƒZ*ej+dej,ƒZ-e-Z.Gdd„dƒZ/ee0dœdd„Z1dee2e0dœdd„Z3eddœdd„Z4ej5ej6ej7ej8fZ9ee:dœdd„Z;ee:dœdd„Z<ej6ej7ej=ej>fZ?ej@fZAejBfZCeeeee0fd œd!d"„ZDee	e0dœd#d$„ZEee	e2dœd%d&„ZFd‚eeeed'œd(d)„ZGee	edœd*d+„ZHeeeeed,fd œd-d.„ZIeeee0d/œd0d1„ZJee0dœd2d3„ZKe0ee:e0e0fd4œd5d6„ZLd7d8d9d:d;d<gZMe0e0eee0e0e0e0e	e0fd=œd>d?„ZNd@e
e0e0ejOeee0ejOdAœdBdC„ZPe0e0dDœdEdF„ZQej+dGƒZRej+dHƒZSdIdJdKdLdMdNdOdOdPdJdQdRdMdSdTdNdNdUdVdWdVdMdSdNdXdPdYdVdZdXd[d\dUd]œ!ZTd^d_d`dadbdcœZUdƒdeejOe0e0e0dfœdgdh„ZVejWe0e	ediœdjdk„ZXd„d@e0e0e0e
eeefe0ejYdlœdmdn„ZZeeddoœdpdq„Z[ee2eddrœdsdt„Z\eedduœdvdw„Z]ej^ej_ej`ej@ej>ejaejbfZcee:dœdxdy„Zdedzdd{œd|d}„Zeeed~œdd€„Zfefej_gdS)…z3Docutils node-related utility functions for Sphinx.éN)Ú
TYPE_CHECKINGÚAnyÚCallableÚIterableÚListÚOptionalÚSetÚTupleÚTypeÚUnionÚcast)Únodes)ÚElementÚNode)Ú	Directive)ÚInliner)Ú
StringList)Úaddnodes)Ú__)Úlogging)ÚBuilder)Ú
IndexEntry)ÚBuildEnvironment)ÚTagsz^(.+?)\s*(?<!\x00)<([^<]*?)>$c@sFeZdZdZeeeddœdd„Zeedœdd„Z	eedœd	d
„Z
dS)ÚNodeMatchera"A helper class for Node.findall().

    It checks that the given node is an instance of the specified node-classes and
    has the specified node-attributes.

    For example, following example searches ``reference`` node having ``refdomain``
    and ``reftype`` attributes::

        matcher = NodeMatcher(nodes.reference, refdomain='std', reftype='citation')
        doctree.findall(matcher)
        # => [<reference ...>, <reference ...>, ...]

    A special value ``typing.Any`` matches any kind of node-attributes.  For example,
    following example searches ``reference`` node having ``refdomain`` attributes::

        from typing import Any
        matcher = NodeMatcher(nodes.reference, refdomain=Any)
        doctree.findall(matcher)
        # => [<reference ...>, <reference ...>, ...]
    N)Únode_classesÚattrsÚreturncOs||_||_dS)N)Úclassesr)Úselfrr©r ú3/tmp/pip-build-gk9425m9/sphinx/sphinx/util/nodes.pyÚ__init__6szNodeMatcher.__init__)ÚnodercCsŽyt|jrt||jƒrdS|jrrt|tjƒs0dSx@|jjƒD]2\}}||krPdS|tkr\q<q<|j|ƒ|kr<dSq<WdStk
rˆdSXdS)NFT)	rÚ
isinstancerr
rÚitemsrÚgetÚ	Exception)rr#ÚkeyÚvaluer r r!Úmatch:s zNodeMatcher.matchcCs
|j|ƒS)N)r*)rr#r r r!Ú__call__PszNodeMatcher.__call__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
rrr"Úboolr*r+r r r r!r sr)r#rcCsdj|j|jjƒS)z—
    Return full module dotted path like: 'docutils.nodes.paragraph'

    :param nodes.Node node: target node
    :return: full module dotted path
    z{}.{})Úformatr-Ú	__class__r,)r#r r r!Úget_full_module_nameTsr3éP)r#ÚlengthrcCsRy|jƒjƒ}Wntk
r,t|ƒ}YnX|rNt|ƒ|krN|d|…d}|S)a†
    return DOM XML representation of the specified node like:
    '<paragraph translatable="False"><inline classes="versionmodified">New in version...'

    :param nodes.Node node: target node
    :param int length:
       length of return value to be striped. if false-value is specified, repr_domxml
       returns full of DOM XML representation.
    :return: DOM XML representation
    Nz...)ZasdomZtoxmlr'ÚstrÚlen)r#r5Útextr r r!Úrepr_domxml^sr9cCs8t|tjƒrP|jrPtjdt|ƒt|ƒƒ|j}|j	|_	|j
d|_
|jƒ|_nt|tjƒrn|j	rn|jj	|_	t|tjƒr°|j	dkr°tjdt|ƒt|ƒƒ|jj	|jj
|_	|_
t|tj
ƒrò|j	dkròtjdt|ƒt|ƒƒ|jj	|jj
|_	|_
t|tjƒrXtjdt|ƒt|ƒƒx@tt|jjtjƒƒƒD]&}tjdtj|jƒƒd|jƒ|_q.Wt|tjƒrž|j	dkržtjdt|ƒt|ƒƒ|jj	|jj
|_	|_
t|tjƒrÂ|j	dkrÂt|ƒ|_	|jsÔ|jƒ|_|j	rè|jrèdSt|tjtj
tjtjfƒr4tjdt|ƒt|ƒƒt|ƒp&d|_	d	|_
dSdS)
Nz7[i18n] PATCH: %r to have source, line and rawsource: %séz)[i18n] PATCH: %r to have source, line: %sz#[i18n] PATCH: %r to have source: %sz&[i18n] PATCH: %r to have rawsource: %sz	\s*:\s*%sÚz,[i18n] PATCH: %r to have source and line: %sr)r$r
Ú
classifierÚ	rawsourceÚloggerÚdebugr3r9ÚparentÚsourceÚlineÚastextÚimageÚtitleÚtermÚreversedÚlistÚfindallÚreÚsubÚescapeZtopicÚ
literal_blockÚget_node_sourceZrubricÚ
field_name)r#Zdefinition_list_itemr<r r r!Úapply_source_workaroundrsV


rPcCs4t|tjƒr,t|jjddgƒdtjƒr,dSdSdS)Nr
rTF)r$r
ÚpendingÚdetailsr&rÚmeta)r#r r r!Úis_pending_meta¹srTcCs8t|tjƒrdSt|tjƒr4|jdƒs0|jdƒr4dSt|tjƒrLd|krLdSt|tjƒr|jszt	j
dt|ƒt|ƒƒdSt|t
ƒr¦d|kr¦t	j
dt|ƒt|ƒƒdS|jddƒsÌt	j
dt|ƒt|ƒƒdSt|tjƒoä|jdd	krt	j
d
t|ƒt|ƒƒdSdSt|ƒst|tjƒr"dSt|tjƒr4dSdS)NTÚtranslatableÚaltFz)[i18n] SKIP %r because no node.source: %szO[i18n] SKIP %r because node is in IGNORED_NODES and no node['translatable']: %sz3[i18n] SKIP %r because not node['translatable']: %srZorphanz&[i18n] SKIP %r because orphan node: %s)r$rrUr
rDr&ZInlineZTextElementrAr>r?r3r9Ú
IGNORED_NODESrOÚchildrenrTrSÚ
docutils_meta)r#r r r!Úis_translatableÁs: rZ)Údoctreerccsx|jtƒD]ü}t|tjƒr>x|jƒD]}||fVq*Wqt|tƒr\|j}|sZ|jƒ}n¢t|t	j
ƒrž|jdƒr€||dfV|jdƒr˜d|d}nd}n`t|tƒr°|j
}nNt|t	jƒrÖt|ƒrÖ|jddj
}n(t|tjƒrì|d}n|jjd	d
ƒjƒ}|r||fVqWdS)z3Extract translatable messages from a document tree.rVrUz
.. image:: %sÚurir;r
rÚcontentÚ
ú N)rIrZr$rrUZextract_original_messagesÚLITERAL_TYPE_NODESr=rCr
rDr&ÚMETA_TYPE_NODESZ
rawcontentrQrTrRrYÚreplaceÚstrip)r[r#Úmsgr r r!Úextract_messagesüs0





recCs"xt|ƒD]}|jr
|jSq
WdS)N)Útraverse_parentrA)r#Úpnoder r r!rNs
rNcCs"xt|ƒD]}|jr
|jSq
WdS)N)rfrB)r#rgr r r!Ú
get_node_line&s
rh)r#Úclsrccs,x&|r&|dkst||ƒr|V|j}qWdS)N)r$r@)r#rir r r!rf-srfcCs*|jj|ƒ}|dkr"|j|dSdSdS)Nrr:)r@Úindex)r#Úposr r r!Ú
get_prev_node4srlrccsJttjdd}x6|j|ƒD](}d|kr0|d}n|d}||fVqWdS)z6Traverse translatable index node from a document tree.F)ÚinlineZraw_entriesÚentriesN)rrrjrI)r[Zmatcherr#rnr r r!Útraverse_translatable_index<s
ro)Ústater]r#rcCsJ|jj}|jj}g|j_d|j_z|j|d|ddS||j_||j_XdS)zûVersion of state.nested_parse() that allows titles and does not require
    titles to have the same decoration as the calling document.

    This is useful when the parsed content comes from a completely different
    context, such as docstrings.
    rr:)Zmatch_titlesN)ÚmemoZtitle_stylesZ
section_levelZnested_parse)rpr]r#Zsurrounding_title_stylesZsurrounding_section_levelr r r!Únested_parse_with_titlesGsrrcCsT|jƒ}x|jtjƒD]}d|d<qWx$t|jtjƒƒD]}|jj|ƒq8W|jƒS)z&Like node.astext(), but ignore images.r;rV)	ÚdeepcopyrIr
rDrHÚrawr@ÚremoverC)r#Úimgrtr r r!Úclean_astextZsrw)r8rcCs.tj|ƒ}|r$d|jdƒ|jdƒfSd||fS)z3Split role content into title and target, if given.Tr:éF)Úexplicit_title_rer*Úgroup)r8r*r r r!Úsplit_explicit_titleds
r{ÚsingleÚpairÚdoubleZtripleZseeZseealso)ÚentryÚtargetidrcCsPddlm}g}|jƒ}|}d}|jdƒr>d}|dd…jƒ}x
|D]P}|j|dƒrF|t|ƒdd…jƒ}||d|}|jd	|||dfƒPqFWx°tD]L}|j|dƒr |t|ƒdd…jƒ}|d
krÖd	}|j||||dfƒPq WxZ|jdƒD]L}|jƒ}d}|jdƒr,d}|dd…jƒ}|s4qü|jd|||dfƒqüW|S)
Nr)Úpairindextypesr;ú!Úmainr:ú:z; r}r~ú,r|)	Zsphinx.domains.pythonrrcÚ
startswithÚlstripr7ÚappendÚ
indextypesÚsplit)rr€rZindexentriesZoentryrƒÚtyper)r r r!Úprocess_index_entryqs>

rŒr)ÚbuilderÚ
docnamesetÚdocnameÚtreeÚ	colorfuncÚ	traversedrc
Csttj|jƒƒ}xt|jtjƒƒD]ð}g}tt	|dƒ}xÊ|D]Â}	|	|kr@yH|j
|	ƒtj||	ƒdddt
|||	|jj|	ƒ||ƒ}
|j|	ƒWn(tk
r¼tjtdƒ|	|dYq@Xtj|	d}|
j|_x$|jtjƒD]}d|krà|	|d<qàW|j
|ƒq@W|jj||ƒq$W|S)	zwInline all toctrees in the *tree*.

    Record all docnames in *docnameset*, and output docnames with *colorfunc*.
    Úincludefilesr_T)Znonlz+toctree contains ref to nonexisting file %r)Úlocation)rr)rr
ÚdocumentrsrHrIrZtoctreeÚmapr6rˆr>ÚinfoÚinline_all_toctreesÚenvZget_doctreeÚaddr'ÚwarningrZ
start_of_filerXÚsectionr@rb)
rrŽrrr‘r’ZtoctreenodeZnewnodesr“ZincludefileZsubtreeZsofZsectionnoder r r!r˜˜s0



r˜)ÚstringrcCsX|jtƒ}|jtƒ}tjd|ƒjddƒjdƒ}tjddj	|j
ƒƒƒ}tjd|ƒ}t|ƒS)aëConvert `string` into an identifier and return it.

    This function is a modified version of ``docutils.nodes.make_id()`` of
    docutils-0.16.

    Changes:

    * Allow to use capital alphabet characters
    * Allow to use dots (".") and underscores ("_") for an identifier
      without a leading character.

    # Author: David Goodger <goodger@python.org>
    # Maintainer: docutils-develop@lists.sourceforge.net
    # Copyright: This module has been placed in the public domain.
    ZNFKDÚasciiÚignoreú-r_r;)
Ú	translateÚ_non_id_translate_digraphsÚ_non_id_translateÚunicodedataÚ	normalizeÚencodeÚdecodeÚ
_non_id_charsrKÚjoinrŠÚ_non_id_at_endsr6)rÚidr r r!Ú_make_idºs

r¬z[^a-zA-Z0-9._]+z^[-0-9._]+|-+$ÚoÚdÚhÚiÚlÚtÚbÚcÚfÚkÚnÚpÚyÚzÚgÚjÚsÚeÚqÚr)!éøii'i1iBigi€iƒiˆiŒi’i™išiži¥i«i­i´i¶iåi%i4i5i6i7i<i?i@iGiIiKiMiOÚszZaeZoeÚdbZqp)éßéæiSi8i9r;r)r™r•ÚprefixrFrcCs†d}|r|d}n|jjpdd}|rD|rDt||ƒ}||kr\d}n|r\t|ƒ}|dkr\d}x$|dksp||jkr€||j|ƒ}q^W|S)z>Generate an appropriate node_id for given *prefix* and *term*.Nz-%sr«z%sr;)ÚsettingsZ	id_prefixr¬ÚidsZnew_serialno)r™r•rÆrFZnode_idZidformatr r r!Úmake_ids
rÉ)r#Ú	conditionrcCs4x.|D]"}t|tjƒr|jdƒ|kr|SqWdSdS)zBPick matched pending_xref_condition node up from the pending_xref.rÊN)r$rZpending_xref_conditionr&)r#rÊZsubnoder r r!Úfind_pending_xref_conditions

rË)rÚfromdocnameÚ	todocnamer€ÚchildrErcCsltjdddd}||kr&|r&||d<n.|rD|j||ƒd||d<n|j||ƒ|d<|r`||d<||7}|S)z$Shortcut to create a reference node.r;T)ZinternalZrefidú#ZrefuriZreftitle)r
Ú	referenceZget_relative_uri)rrÌrÍr€rÎrEr#r r r!Úmake_refnode(s
rÑ)Ú	directiver#rcCs|jj|jƒ\|_|_dS)N)Z
state_machineÚget_source_and_lineÚlinenorArB)rÒr#r r r!Úset_source_info:srÕ)ÚinlinerrÔr#rcCs|jj|ƒ\|_|_dS)N)ZreporterrÓrArB)rÖrÔr#r r r!Úset_role_source_info?sr×)ÚsrcÚdstrcCst|ƒ|_t|ƒ|_dS)N)rNrArhrB)rØrÙr r r!Úcopy_source_infoCs
rÚcCsNx4t|jƒD]&}t|tƒrdS|jddƒdkrdSqWt|ddƒdkrJdSdS)z0Check whether the node is smart-quotable or not.FZsupport_smartquotesNT)rfr@r$ÚNON_SMARTQUOTABLE_PARENT_NODESr&Úgetattr)r#rgr r r!Úis_smartquotableSs
rÝr)r•ÚtagsrcCs xš|jtjƒD]Š}y|j|dƒ}WnJtk
rn}z.tjtdƒ||d|j|j	pZt
jƒƒWYdd}~XqX|rŠ|j|j	p„t
jƒƒq|jt
jƒƒqWdS)z0Filter ``only`` nodes which do not match *tags*.Úexprz8exception while evaluating only directive expression: %s)r”N)rIrÚonlyZeval_conditionr'r>r›rZreplace_selfrXr
Úcomment)r•rÞr#ÚretÚerrr r r!Úprocess_only_nodesas&rä)rrcCs2|j|jf|jŽ}t|tjƒr.|j|_|j|_|S)z¡monkey-patch Element.copy to copy the rawsource and line
    for docutils-0.16 or older versions.

    refs: https://sourceforge.net/p/docutils/patches/165/
    )r2r=Ú
attributesr$r
rrArB)rZnewnoder r r!Ú	_new_copyus
ræ)r4)N)r;N)N)hr/rJr¤Útypingrrrrrrrr	r
rrZdocutilsr
Zdocutils.nodesrrZdocutils.parsers.rstrZdocutils.parsers.rst.statesrZdocutils.statemachinerZsphinxrZ
sphinx.localerZsphinx.utilrZsphinx.buildersrZ
sphinx.domainrZsphinx.environmentrZsphinx.util.tagsrÚ	getLoggerr,r>ÚcompileÚDOTALLryZcaption_ref_rerr6r3Úintr9rPZ	InvisiblerMZ
doctest_blockZversionmodifiedrWr0rTrZZ
math_blockrtr`rDZIMAGE_TYPE_NODESrSrarerNrhrfrlrorrrwr{r‰rŒr•r˜r¬r¨rªr£r¢rÉZpending_xrefrËrÐrÑrÕr×rÚZFixedTextElementÚliteralÚmathZproblematicZnot_smartquotablerÛrÝräræÚcopyr r r r!Ú<module>sÚ4
4
?.# 
	$&
 

*