
    FeX_                    R   d Z ddlmZ ddlZddlZddlZddlmZmZm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ er2dd	lmZ dd
lmZmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddl!m"Z"  ejF                  e$      Z% ejL                  dejN                        Z(e(Z) G d d      Z*dmdZ+dndodZ,dpdZ-ej\                  ej^                  ej`                  ejb                  fZ2dqdZ3ej^                  ej`                  ejh                  ejj                  fZ6ejn                  fZ8drdZ9dsdZ:dtdZ;dudvdZ<dwdZ=	 	 	 	 dxdZ>	 dy	 	 	 dzdZ?dsdZ@d{d ZAg d!ZB	 	 d|d"ZC	 	 	 	 	 	 	 	 d}d#ZDd~d$ZE ejL                  d%      ZF ejL                  d&      ZGi d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d4d6d7d8d*d9d:d;d<d=d0d>d?d@dAdBd2dCd2i dDdEdFdGdHdIdJdGdKd0dLd?dMd2dNdOdPd7dQdRdSdGdTdUdVdOdWdXdYdZd[dEZHd\d]d^d_d`daZI	 d	 	 	 	 	 ddbZJ	 	 ddcZK	 du	 	 	 	 	 dddZLddeZMddfZNddgZOej                  ej                  ej                  ejn                  ejj                  ej                  ej                  fZUdqdhZVddiZWddjZXddkZYeYej*                  _Z        ddlZ[e[ej*                  _\        y)z3Docutils node-related utility functions for Sphinx.    )annotationsN)TYPE_CHECKINGAnyCallable)nodes)addnodes)__)logging)Iterable)ElementNode)	Directive)Inliner)
StringList)Builder)BuildEnvironment)Tagsz^(.+?)\s*(?<!\x00)<([^<]*?)>$c                  (    e Zd ZdZddZddZddZy)NodeMatcheraT  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 __future__ import annotations
from typing import TYPE_CHECKING, Any
        matcher = NodeMatcher(nodes.reference, refdomain=Any)
        doctree.findall(matcher)
        # => [<reference ...>, <reference ...>, ...]
    c                     || _         || _        y N)classesattrs)selfnode_classesr   s      3/usr/lib/python3/dist-packages/sphinx/util/nodes.py__init__zNodeMatcher.__init__;   s    #
    c                F   	 | j                   rt        || j                         sy| j                  rbt        |t        j                        sy| j                  j                         D ]*  \  }}||vr y|t        u r|j                  |      |k7  s* y y# t        $ r Y yw xY w)NFT)	r   
isinstancer   r   r   itemsr   get	Exception)r   nodekeyvalues       r   matchzNodeMatcher.match?   s    	||JtT\\$Bzz!$6 "&**"2"2"4 %JC$$# #%/$%  		s.   "B &B %B 2B B B 	B B c                $    | j                  |      S r   )r'   )r   r$   s     r   __call__zNodeMatcher.__call__U   s    zz$r   N)r   z
type[Node]r   r   returnNoner$   r   r*   bool)__name__
__module____qualname____doc__r   r'   r)    r   r   r   r   $   s    ,, r   r   c                L    | j                    d| j                  j                   S )z
    Return full module dotted path like: 'docutils.nodes.paragraph'

    :param nodes.Node node: target node
    :return: full module dotted path
    .)r/   	__class__r.   r$   s    r   get_full_module_namer7   Y   s%     ooa 7 7899r   c                    	 | j                         j                         }|rt	        |      |kD  r|d| dz   }|S # t        $ r t        |       }Y 0w xY w)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...)asdomtoxmlr#   strlen)r$   lengthtexts      r   repr_domxmlr?   c   sZ    zz|!!# #d)f$GV}u$K	  4ys   : AAc                   t        | t        j                        r|| j                  spt        j                  dt        |       t        |              | j                  }|j                  | _	        |j                  dz
  | _
        | j                         | _        nAt        | t        j                        r'| j                  s| j                  j                  | _	        t        | t        j                        rl| j                  `t        j                  dt        |       t        |              | j                  j                  | j                  j                  c| _	        | _
        t        | t        j                        rl| j                  `t        j                  dt        |       t        |              | j                  j                  | j                  j                  c| _	        | _
        t        | t        j                        rt        j                  dt        |       t        |              t        t!        | j                  j#                  t        j                                    D ]L  }t%        j&                  dt%        j(                  |j                               z  d| j                        | _        N t        | t        j*                        rl| j                  `t        j                  dt        |       t        |              | j                  j                  | j                  j                  c| _	        | _
        t        | t        j,                        r>| j                  2t/        j0                  t2              5  t5        |       | _	        d d d        | j                  s| j                         | _        | j                  r| j                  ry t        | t        j6                  t        j                  t        j                  t        j8                  f      rBt        j                  dt        |       t        |              	 t5        |       | _	        d	| _
        y y # 1 sw Y   xY w# t2        $ r d| _	        Y d	| _
        y w xY w)
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debugr7   r?   parentsourcelineastextimagetitletermreversedlistfindallresubescapetopicliteral_block
contextlibsuppress
ValueErrorget_node_sourcerubric
field_name)r$   definition_list_itemrC   s      r   apply_source_workaroundr]   w   s8    $(()$..N)$/T1B	D#{{*11(--1		D%**	+DKKkk(($$)<@)$/T1B	D!%!3!3T[[5E5ETY$$)<:)$/T1B	D!%!3!3T[[5E5ETY$

#=)$/T1B	D #4(;(;E<L<L(M#NO 	8JVVL299Z=N=N=P3Q$Q$&8DN	8 $$)<@)$/T1B	D!%!3!3T[[5E5ETY $++,1D  , 	0)$/DK	0 >>{{t~~ 	4LLJJKK	 	 	C)$/T1B	D	)$/DK 			0 	0*  	DK		s   6Q;Q  Q Q:9Q:c                l   t        | t        j                        ryt        | t        j                        r#| j                  d      s| j                  d      ryt        | t        j                        rd| vryt        | t        j                        r| j                  s*t        j                  dt        |       t        |              yt        | t              r.d| vr*t        j                  dt        |       t        |              y| j                  dd      s*t        j                  dt        |       t        |              yt        | t        j                        r<| j                  d   d	k(  r*t        j                  d
t        |       t        |              yyt        | t        j                         ryy)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']: %sr   orphanz&[i18n] SKIP %r because orphan node: %s)r    r   r_   r   rK   r"   InlineTextElementrH   rE   rF   r7   r?   IGNORED_NODESr[   childrenmetar6   s    r   is_translatablerg      sP   $--. $$$((>*Bdhhuo$%.*D$))*{{LLD-d3[5FHdM*~T/ILL ;-d3[5FH xx-LLN-d3[5FH dE,,-$--2Bh2NLLA-d3[5FH$

#r   c              #  |  K   | j                  t              D ]  }t        |t        j                        r|j                         D ]  }||f 
 :t        |t              r|j                  }|s|j                         }nt        |t        j                        rI|j                  d      r	||d   f |j                  d      r|j                  d|d         }d| }nMd}nJt        |t        j                        r|d   }n*|j                  j                  dd	      j                         }|s||f " y
w)z3Extract translatable messages from a document tree.r`   r_   original_uriuriz.. image:: rB   content
 N)rP   rg   r    r   r_   extract_original_messagesLITERAL_TYPE_NODESrD   rJ   r   rK   r"   rf   replacestrip)doctreer$   msg	image_uris       r   extract_messagesru      s    0 dH112557  Ci d./..Ckkmekk*xxDK''xx' HH^T%[A	#I;/ejj)y/C..((s399;C )O1s   D.D<2
D<c                p    t        |       D ]  }|j                  s|j                  c S  d}t        |      )Nznode source not found)traverse_parentrH   rX   r$   pnoders   s      r   rY   rY     s8     &  <<<<  "C
S/r   c                p    t        |       D ]  }|j                  s|j                  c S  d}t        |      )Nznode line not found)rw   rI   rX   rx   s      r   get_node_liner{     s8     & ::::  C
S/r   c              #  T   K   | r"|t        | |      r|  | j                  } | r!y y wr   )r    rG   )r$   clss     r   rw   rw   #  s*     
;*T3/J{{ s   #((c                h    | j                   j                  |       }|dkD  r| j                   |dz
     S y )Nr   rA   )rG   index)r$   poss     r   get_prev_noder   *  s3    
++

D
!C
Qw{{37##r   c              #     K   t        t        j                  d      }| j                  |      D ]  }d|v r|d   }n|d   }||f  yw)z6Traverse translatable index node from a document tree.F)inlineraw_entriesentriesN)r   r   r   rP   )rr   matcherr$   r   s       r   traverse_translatable_indexr   2  sU      (..7G( D =)G9oGGms   AA
c                \   | j                   j                  }| j                   j                  }g | j                   _        d| j                   _        	 | j                  |||d      || j                   _        || j                   _        S # || j                   _        || j                   _        w xY 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.
    r   rA   )match_titles)memotitle_stylessection_levelnested_parse)staterk   r$   content_offsetsurrounding_title_stylessurrounding_section_levels         r   nested_parse_with_titlesr   ?  s      %zz66 %

 8 8 EJJ EJJ=!!'>4a!P":

#<

  #;

#<

 s   B $B+c                $   | j                         } | j                  t        j                        D ]  }d|d<   	 t	        | j                  t        j
                              D ]  }|j                  j                  |        | j                         S )z&Like node.astext(), but ignore images.rB   r`   )	deepcopyrP   r   rK   rO   rawrG   removerJ   )r$   imgr   s      r   clean_astextr   S  sq    ==?D||EKK( E
DLL+, 

#;;=r   c                    t         j                  |       }|r#d|j                  d      |j                  d      fS d| | fS )z3Split role content into title and target, if given.TrA      F)explicit_title_rer'   group)r>   r'   s     r   split_explicit_titler   ]  s?    ##D)EU[[^U[[^33$r   )singlepairdoubletripleseeseealsoc                   ddl m} g }| j                         } | }d}| j                  d      rd}| dd  j	                         } |D ]{  }| j                  | d      s| t        |      dz   d  j                         }||    d| }t        j                  t        d	      || |d
       |j                  d|||d f        |S  t        D ]U  }| j                  | d      s| t        |      dz   d  j                         }|dk(  rd}|j                  ||||d f        |S  |j                  d      D ]S  }|j                         }d}|j                  d      rd}|dd  j	                         }|s>|j                  d|||d f       U |S )Nr   )pairindextypesrB   !mainrA   :z; zK%r is deprecated for index entries (from entry %r). Use 'pair: %s' instead.r   )typer   r   ,r   )sphinx.domains.pythonr   rq   
startswithlstripr<   rE   warningr	   append
indextypessplit)entrytargetidr   indexentriesoentryr   
index_typer&   s           r   process_index_entryr   j  s   4@BLKKMEFDab	  "$ M
zl!,-#j/A-./557E%j12"UG<ENN2 8 9%ue'  C $ EF( ;M % 	MJ:,a 01c*o12399;)!'J##Z$$MN %	M  c* M##C(!D!!"I,,.E##Xuhd$KLM r   c           
        |j                         }t        |j                  t        j                              D ]  }g }t        t        |d         }|D ]  }	|	|vs	 |j                  |	       t        j                   ||	      dz   d       t        | ||	| j                  j                  |	      ||      }
|j                  |	       t        j                  |	      }|
j                  |_        |j                  t         j"                        D ]  }d|vs|	|d<    |j                  |        |j*                  j-                  ||        |S # t$        $ r% t        j'                  t)        d      |	|       Y *w xY w)	zwInline all toctrees in the *tree*.

    Record all docnames in *docnameset*, and output docnames with *colorfunc*.
    includefilesrm   T)nonl)docnamer   z+toctree contains ref to nonexisting file %rlocation)r   rO   rP   r   toctreemapr;   r   rE   infoinline_all_toctreesenvget_doctreeaddstart_of_filere   r   sectionr#   r   r	   rG   rp   )builder
docnamesetr   tree	colorfunc	traversedtoctreenodenewnodesr   includefilesubtreesofsectionnodes                r   r   r     sp    ==?DDLL)9)9:; :3N ;<' 	)K)+)$$[1KK	+ 6 <4KH1':{29++2I2I+2V2;YHG NN;/
 #00EC#*#3#3CL'*{{5=='A A$K75@K	2A OOC(%	)& 	"";9-:. K ! BNN2&S#T#. # BBs   A+E*E?>E?c                h   | j                  t              }|j                  t              }t        j                  d|      j                  dd      j                  d      }t        j                  ddj                  |j                                     }t        j                  d|      }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.
    NFKDasciiignore-rm   rB   )	translate_non_id_translate_digraphs_non_id_translateunicodedata	normalizeencodedecode_non_id_charsrR   joinr   _non_id_at_endsr;   )stringids     r   _make_idr     s      
		4	5B	'	(B 
		vr	*	1	1'8	D	K	KG	TB			3 4	5B			R	$Br7Nr   z[^a-zA-Z0-9._]+z^[-0-9._]+|-+$   oi  di'  hi1  iiB  lig  ti  bi  i  ci  i  fi  ki  i  ni  pi  i  i  yi  zi  gi%  i4  i5  i6  i7  ji<  i?  si@  iG  eiI  iK  qiM  riO  szaeoedbqp)      iS  i8  i9  c                   d}|r|dz   }n|j                   j                  xs ddz   }|r|rt        ||z        }||k(  rd}n|rt        |      }|dk(  rd}|||j                  v r&|| j	                  |      z  }|||j                  v r&|S )z>Generate an appropriate node_id for given *prefix* and *term*.Nz-%sr   z%srB   )settings	id_prefixr   idsnew_serialno)r   documentprefixrM   node_ididformats         r   make_idr	     s     GE>%%//744? $8d?+fG	4.b=G
/W4S--f55 /W4 Nr   c                x    | D ]5  }t        |t        j                        s|j                  d      |k(  s3|c S  y)zBPick matched pending_xref_condition node up from the pending_xref.	conditionN)r    r   pending_xref_conditionr"   )r$   r  subnodes      r   find_pending_xref_conditionr    s>      w ? ?@K(I5N r   c                    t        j                  ddd      }||k(  r|r||d<   n3|r| j                  ||      dz   |z   |d<   n| j                  ||      |d<   |r||d<   ||z  }|S )z$Shortcut to create a reference node.rB   T)internalrefid#refurireftitle)r   	referenceget_relative_uri)r   fromdocname	todocnamer   childrL   r$   s          r   make_refnoder  $  s     ??2rD1DiH W%66{IN!"$,-DN %55k9MDN ZEMDKr   c                h    | j                   j                  | j                        \  |_        |_        y r   )state_machineget_source_and_linelinenorH   rI   )	directiver$   s     r   set_source_infor   7  s)    33I4D4DE DKr   c                Z    | j                   j                  } ||      \  |_        |_        y r   )reporterr  rH   rI   )inlinerr  r$   gsals       r   set_role_source_infor%  <  s%    //D!&\DKr   c                    t        j                  t              5  t        |       |_        t        |       |_        d d d        y # 1 sw Y   y xY wr   )rV   rW   rX   rY   rH   r{   rI   )srcdsts     r   copy_source_infor)  A  s=    			Z	( &$S)
 %& & &s   !AAc                    t        | j                        D ]*  }t        |t              r y|j	                  dd      du s* y t        | dd      du ryy)z0Check whether the node is smart-quotable or not.Fsupport_smartquotesNT)rw   rG   r    NON_SMARTQUOTABLE_PARENT_NODESr"   getattr)r$   ry   s     r   is_smartquotabler.  R  sY     - e;<99*D1U:	 t*D1U:r   c                   | j                  t        j                        D ]c  }t        ||      r2|j	                  |j
                  xs t        j                                A|j	                  t        j                                e y)z0Filter ``only`` nodes which do not match *tags*.N)rP   r   only_only_node_keep_childrenreplace_selfre   r   comment)r  tagsr$   s      r   process_only_nodesr5  `  s]      / /#D$/dmm>u}}? emmo./r   c                    	 |j                  | d         S # t        $ r+}t        j                  t	        d      ||        Y d}~yd}~ww xY w)z%Keep children if tags match or error.exprz8exception while evaluating only directive expression: %sr   NT)eval_conditionr#   rE   r   r	   )r$   r4  errs      r   r1  r1  m  sQ    ""4<00 IJ 	 	 s    	A
!AA
c                ^   t         j                  | j                        }g |_        | j                  |_        | j
                  |_        | j                  j                         D ci c]  \  }}||dvr|n|dd  c}}|_        | j                  |_        | j                  |_	        |S c c}}w )zMonkey-patch ```nodes.Element.copy``` to not copy the ``_document``
    attribute.

    xref: https://github.com/sphinx-doc/sphinx/issues/11116#issuecomment-1376767086
    >   r  namesr   backrefsdupnamesN)
object__new__r5   re   rD   tagname
attributesr!   rI   rH   )elnewnoder   vs       r   _copy_except__documentrE  y  s     nnR\\*GGGjjGO
 ')mm&9&9&;= #a !"*]!]  #$Q4( =G 77GLYYGNN=s   &B)c                   | j                         }| j                  D cg c]  }|j                          c}|_        |j                  D ]v  }||_        | j                  s| j                  |_        |j
                  | j                  j                  |_        |j                  \| j                  j                  |_        x |S c c}w )z4Monkey-patch ```nodes.Element.deepcopy``` for speed.)	copyre   r   rG   r  rH   current_sourcerI   current_line)rB  rC  r  s      r   	_deepcopyrJ    s    ggiG68kkBU(BG!! 6;;[[EN||#!{{99zz![[55
6 N Cs   C)r$   r   r*   r;   )P   )r$   r   r=   intr*   r;   )r$   r   r*   r+   r,   )rr   r   r*   zIterable[tuple[Element, str]])r$   r   r*   r;   )r$   r   r*   rL  r   )r$   r   r}   r   r*   zIterable[Element])r$   r   r*   zNode | None)rr   r   r*   zEIterable[tuple[Element, list[tuple[str, str, str, str, str | None]]]])r   )
r   r   rk   r   r$   r   r   rL  r*   r;   )r>   r;   r*   ztuple[bool, str, str])r   r;   r   r;   r*   z+list[tuple[str, str, str, str, str | None]])r   r   r   zset[str]r   r;   r   nodes.documentr   r   r   z	list[str]r*   rM  )r   r;   r*   r;   )rB   N)
r   r   r  rM  r  r;   rM   
str | Noner*   r;   )r$   zaddnodes.pending_xrefr  r;   r*   zElement | None)r   r   r  r;   r  r;   r   rN  r  zNode | list[Node]rL   rN  r*   znodes.reference)r  r   r$   r   r*   r+   )r#  r   r  rL  r$   r   r*   r+   )r'  r   r(  r   r*   r+   )r  r   r4  r   r*   r+   )r$   zaddnodes.onlyr4  r   r*   r-   )rB  r   r*   r   )]r1   
__future__r   rV   rQ   r   typingr   r   r   docutilsr   sphinxr   sphinx.localer	   sphinx.utilr
   collections.abcr   docutils.nodesr   r   docutils.parsers.rstr   docutils.parsers.rst.statesr   docutils.statemachiner   sphinx.buildersr   sphinx.environmentr   sphinx.util.tagsr   	getLoggerr.   rE   compileDOTALLr   caption_ref_rer   r7   r?   r]   	InvisiblerU   doctest_blockversionmodifiedrd   rg   
math_blockr   ro   rK   IMAGE_TYPE_NODESru   rY   r{   rw   r   r   r   r   r   r   r   r   r   r   r   r   r   r	  r  r  r   r%  r)  FixedTextElementliteralmathproblematicnot_smartquotabler,  r.  r5  r1  rE  rG  rJ  r   r2   r   r   <module>rk     s8   9 "  	  / /    (,.30'3%			8	$ BJJ?K "2  2 j:(?F 
OO			&T 
			II	  
KK 
:

J
 45=-0=9<=(

(H(V,9ANW+D6 

,-"**-."
C"
C" C" C	"
 C" C" C" C" C" C" C" C" C" C" C"  C!"" C#"$ C%"& C'"( C)"* C+", C-". C/"0 C1"2 C3"4 C5"6 C7"8 C9": C;"< C="> C?"@ CA"B CC" H   26$.:=4%3 @D)2<%&F
*
& 
	MM	JJ	KK	II	" 
/	* ,  # r   