o $a?Y@sdZddlZddlZddlmZmZmZmZmZm Z m Z m Z m Z m Z mZddlmZddlmZmZddlmZddlmZddlmZdd lmZdd lmZdd lmZerpdd l m!Z!dd l"m#Z#ddl$m%Z%ddl&m'Z'e(e)Z*e+dej,Z-e-Z.GdddZ/dede0fddZ1ddede2de0fddZ3deddfddZ4ej5ej6ej7ej8fZ9dede:fddZ;dede:fdd ZfZ?ej@fZAejBfZCd!edee ee0ffd"d#ZDdede e0fd$d%ZEdede e2fd&d'ZFdded(edeefd)d*ZGdede efd+d,ZHd!edee eed-ffd.d/ZId0ed1edede0fd2d3ZJdede0fd4d5ZKd6e0de e:e0e0ffd7d8ZLgd9ZMd:e0d;e0dee e0e0e0e0e e0ffdd?d@e e0dAe0dBejOdCedDee0dejOfdEdFZPdGe0de0fdHdIZQe+dJZRe+dKZSidLdMdNdOdPdQdRdSdTdUdVdWdXdYdZdYd[d\d]dOd^d_d`dadbdUdcdddedfdgdWdhdWididjdkdldmdndodldpdUdqdddrdWdsdtdud\dvdwdxdldydzd{dtd|d}d~dddjZTddddddZU ddddejOde0de0de0f ddZVdejWde0de efddZX dd>d?de0de0d;e0de eeefde0dejYfddZZdededdfddZ[dede2deddfddZ\dededdfddZ]ej^ej_ej`ej@ej>ejaejbfZcdede:fddZddeddddfddZededefddZfefej_gdS)z sphinx.util.nodes ~~~~~~~~~~~~~~~~~ Docutils node-related utility functions for Sphinx. :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. N) TYPE_CHECKINGAnyCallableIterableListOptionalSetTupleTypeUnioncast)nodes)ElementNode) Directive)Inliner) StringList)addnodes)__)logging)Builder) IndexEntry)BuildEnvironment)Tagsz^(.+?)\s*(?$c@sNeZdZdZdeededdfddZdedefd d Z dedefd d Z dS) NodeMatchera%A helper class for Node.traverse(). 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.traverse(matcher) # => [, , ...] 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.traverse(matcher) # => [, , ...] node_classesattrsreturnNcOs||_||_dSN)classesr)selfrrr!3/usr/lib/python3/dist-packages/sphinx/util/nodes.py__init__>s zNodeMatcher.__init__nodecCsz=|jr t||js WdS|jr;t|tjsWdS|jD]\}}||vr*WdS|tur/q|||kr:WdSqWdStyGYdSw)NFT) r isinstancerr ritemsrget Exception)r r$keyvaluer!r!r"matchBs$  zNodeMatcher.matchcCs ||Sr)r+)r r$r!r!r"__call__Xs zNodeMatcher.__call__) __name__ __module__ __qualname____doc__r rrr#boolr+r,r!r!r!r"r(s rr$rcCsd|j|jjS)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_name\sr5PlengthcCsPz|}Wn tyt|}Ynw|r&t||kr&|d|d}|S)a return DOM XML representation of the specified node like: '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...)asdomtoxmlr(strlen)r$r7textr!r!r" repr_domxmlfs   r=cCst|tjr'|js'tdt|t||j}|j |_ |j d|_ | |_nt|tjr5|j s5|jj |_ t|tj rV|j durVtdt|t||jj |jj |_ |_ t|tj rw|j durwtdt|t||jj |jj |_ |_ t|tjrtdt|t|tt|jtjD]}tdt| d|j|_qt|tjr|j durt||_ |js| |_|j r|jrdSt|tjtj tj tjfrtdt|t|t|pd|_ d |_ dSdS) Nz7[i18n] PATCH: %r to have source, line and rawsource: %sz)[i18n] PATCH: %r to have source, line: %sz#[i18n] PATCH: %r to have source: %sz&[i18n] PATCH: %r to have rawsource: %sz \s*:\s*%sz,[i18n] PATCH: %r to have source and line: %sr)r%r classifier rawsourceloggerdebugr5r=parentsourcelineastextimagetitletermreversedlisttraverseresubescape literal_blockget_node_sourcerubric field_name)r$definition_list_itemr@r!r!r"apply_source_workaroundzs^            rVcCs0t|tjrt|jddgdtjrdSdS)Nr rTF)r%r pendingdetailsr'rmetar4r!r!r"is_pending_metas rZcCs"t|tjrdSt|tjr|ds|drdSt|tjr&d|vr&dSt|tjr|js)rDindex)r$posr!r!r" get_prev_node0s rxrccsD|ttjddD]}d|vr|d}n|d}||fVq dS)z6Traverse translatable index node from a document tree.F)inline raw_entriesentriesN)rMrrrv)rcr$r{r!r!r"traverse_translatable_index8s  r|statecontentcCsX|jj}|jj}g|j_d|j_z|j|d|ddW||j_||j_S||j_||j_w)zVersion 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>) match_titles)memo title_styles section_level nested_parse)r}r~r$surrounding_title_stylessurrounding_section_levelr!r!r"nested_parse_with_titlesBs  rcCsL|}|tjD]}d|d<q t|tjD]}|j|q|S)z&Like node.astext(), but ignore images.r?r\) deepcopyrMr rHrLrawrDremoverG)r$imgrr!r!r" clean_astextUs  rr<cCs.t|}|rd|d|dfSd||fS)z3Split role content into title and target, if given.Tr>F)explicit_title_rer+group)r<r+r!r!r"split_explicit_title_s  r)singlepairdoubletripleseeseealsoentrytargetidcCsFddlm}g}|}|}d}|drd}|dd}|D]*}||drK|t|dd}||d|}|d |||df|Sq!tD](}||drv|t|dd}|d krid }|||||df|SqN|d D]$}|}d}|drd}|dd}|sq||d |||dfq||S) Nr)pairindextypesr?!mainr>:z; rr,r) sphinx.domains.pythonrrl startswithlstripr;append indextypessplit)rrr indexentriesoentryrtyper*r!r!r"process_index_entrylsF    rbuilderr docnamesetdocnametree colorfunc traversedc Cs ttj|}t|tjD]s}g}tt |d}|D]^} | |vr{z$| | t j || dddt ||| |j| ||} || WntyZt jtd| |dYqwtj| d} | j| _| tjD] } d| vru| | d<qk| | q|j||q|S) zwInline all toctrees in the *tree*. Record all docnames in *docnameset*, and output docnames with *colorfunc*. includefilesrfT)nonlz+toctree contains ref to nonexisting file %rlocation)rr)r r documentrrLrMrtoctreemapr:rrBinfoinline_all_toctreesenv get_doctreeaddr(warningr start_of_filerasectionrDrk) rrrrrr toctreenodenewnodesr includefilesubtreesof sectionnoder!r!r"rs:       rstringcCsX|t}|t}td|ddd}tdd | }t d|}t |S)aConvert `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 # Maintainer: docutils-develop@lists.sourceforge.net # Copyright: This module has been placed in the public domain. NFKDasciiignore-rfr?) translate_non_id_translate_digraphs_non_id_translate unicodedata normalizeencodedecode _non_id_charsrOjoinr_non_id_at_endsr:)ridr!r!r"_make_ids   rz[^a-zA-Z0-9._]+z^[-0-9._]+|-+$oidi'hi1iiBligtibiiciifikiinipiiiyizigi%i4i5i6i7ji<i?si@iGeiIiKqiMriOszaeoedbqp)iSi8i9r?rrrprefixrJcCsd}|r |d}n|jjpdd}|r"|r"t||}||kr!d}n |r.t|}|dkr.d}|dus7||jvrG|||}|dus7||jvs7|S)z>Generate an appropriate node_id for given *prefix* and *term*.Nz-%srz%sr?)settings id_prefixrids new_serialno)rrrrJnode_ididformatr!r!r"make_ids"  r conditioncCs0|D]}t|tjr|d|kr|SqdS)zBPick matched pending_xref_condition node up from the pending_xref.rN)r%rpending_xref_conditionr')r$rsubnoder!r!r"find_pending_xref_conditions  r fromdocname todocnamechildrIcCsltjdddd}||kr|r||d<n|r"|||d||d<n||||d<|r0||d<||7}|S)z$Shortcut to create a reference node.r?T)internalrefid#refurireftitle)r referenceget_relative_uri)rrrrrrIr$r!r!r" make_refnode#s    r directivecCs|j|j\|_|_dSr) state_machineget_source_and_linelinenorErF)rr$r!r!r"set_source_info5s r inlinerr cCs|j|\|_|_dSr)reporterrrErF)r r r$r!r!r"set_role_source_info:sr srcdstcCst||_t||_dSr)rRrErtrF)rrr!r!r"copy_source_info>s rcCsNt|jD]}t|trdS|dddurdSqt|dddur%dSdS)z0Check whether the node is smart-quotable or not.Fsupport_smartquotesNT)rprDr%NON_SMARTQUOTABLE_PARENT_NODESr'getattrrqr!r!r"is_smartquotableNs rtagsrc Cs|tjD]F}z ||d}Wn&ty7}ztjtd||d||j p+t WYd}~qd}~ww|rE||j pBt q|t qdS)z0Filter ``only`` nodes which do not match *tags*.exprz8exception while evaluating only directive expression: %srN) rMronlyeval_conditionr(rBrr replace_selfrar comment)rrr$reterrr!r!r"process_only_nodes\s  rr cCs6|j|jfi|j}t|tjr|j|_|j|_|S)zmonkey-patch Element.copy to copy the rawsource and line for docutils-0.16 or older versions. refs: https://sourceforge.net/p/docutils/patches/165/ )r3rA attributesr%r rrErF)r newnoder!r!r" _new_copyps  r )r6r)r?N)hr0rNrtypingrrrrrrrr r r r docutilsr docutils.nodesrrdocutils.parsers.rstrdocutils.parsers.rst.statesrdocutils.statemachinersphinxr sphinx.localer sphinx.utilrsphinx.buildersr sphinx.domainrsphinx.environmentrsphinx.util.tagsr getLoggerr-rBcompileDOTALLrcaption_ref_rerr:r5intr=rV InvisiblerQ doctest_blockversionmodifiedr`r1rZrb math_blockrrhrHIMAGE_TYPE_NODESrYrirnrRrtrprxr|rrrrrrrrrrrrr pending_xrefrrrr r rFixedTextElementliteralmath problematicnot_smartquotablerrrr copyr!r!r!r"sX 4            4 : ,"    ' "        !$