
    P&i[                        d Z ddlZddlZddlmZmZmZmZmZm	Z	m
Z
mZmZmZ d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rddlm Z  ddl!m"Z" ddl#m$Z$ ddl%m&Z&  ej'        e(          Z) ej*        dej+                  Z,e,Z- G d d          Z.dede/fdZ0ddede1de/fdZ2deddfdZ3ej4        ej5        ej6        ej7        fZ8dede9fdZ:dede9fdZ;ej5        ej6        ej<        ej=        fZ>ej?        fZ@ejA        fZBdedeeee/f                  fdZCdede	e/         fdZDdede	e1         fdZEdded edee         fd!ZFdede	e         fd"ZGdedeeeed#         f                  fd$ZHd%ed&edede/fd'ZIdede/fd(ZJd)e/dee9e/e/f         fd*ZKg d+ZLd,e/d-e/deee/e/e/e/e	e/         f                  fd.ZMd/d0d1e
e/         d2e/d3ejN        d4ed5ee/         dejN        fd6ZOd7e/de/fd8ZP ej*        d9          ZQ ej*        d:          ZRi d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdHdJdKdLd>dMdNdOdPdQdDdRdSdTdUdVdFdWdFi dXdYdZd[d\d]d^d[d_dDd`dSdadFdbdcdddKdedfdgd[dhdidjdcdkdldmdndodYZSdpdqdrdsdtduZT	 ddwdxdyejN        dze/d{e	e/         de/f
d|ZUdejV        d}e/de	e         fd~ZW	 dd/d0de/de/d-e/deeee         f         de	e/         dejX        fdZYdededdfdZZdede1deddfdZ[dededdfdZ\ej]        ej^        ej_        ej?        ej=        ej`        eja        fZbdede9fdZcdyeddddfdZddedefdZeeeej        _f        dS )z3Docutils node-related utility functions for Sphinx.    N)
TYPE_CHECKINGAnyCallableIterableListOptionalSetTupleTypeUnion)nodes)ElementNode)	Directive)Inliner)
StringList)addnodes)__)logging)Builder)
IndexEntry)BuildEnvironment)Tagsz^(.+?)\s*(?<!\x00)<([^<]*?)>$c                   R    e Zd ZdZdee         deddfdZdedefdZ	dedefd	Z
dS )
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 ...>, ...]
    node_classesattrsreturnNc                 "    || _         || _        d S N)classesr   )selfr   r   s      ^/home/geonatureadmin/si_en_reseau/tutos/venv/lib/python3.11/site-packages/sphinx/util/nodes.py__init__zNodeMatcher.__init__6   s    #


    nodec                 D   	 | j         rt          || j                   sdS | j        rht          |t          j                  sdS | j                                        D ]2\  }}||vr dS |t          u r|                    |          |k    r dS 3dS # t          $ r Y dS w xY w)NFT)	r!   
isinstancer   r   r   itemsr   get	Exception)r"   r&   keyvalues       r#   matchzNodeMatcher.match:   s    	| JtT\$B$B uz 
%!$66 ! 5"&*"2"2"4"4 % %JC$$uu# #%//$uu 0 4 	 	 	55	s(   B !B #B ($B B 
BBc                 ,    |                      |          S r    )r.   )r"   r&   s     r#   __call__zNodeMatcher.__call__P   s    zz$r%   )__name__
__module____qualname____doc__r   r   r   r$   boolr.   r0    r%   r#   r   r       s         *d4j 3 4    $ 4    , T  d            r%   r   r&   r   c                 L    d                     | j        | j        j                  S )z
    Return full module dotted path like: 'docutils.nodes.paragraph'

    :param nodes.Node node: target node
    :return: full module dotted path
    z{}.{})formatr2   	__class__r1   r&   s    r#   get_full_module_namer;   T   s     >>$/4>+BCCCr%   P   lengthc                     	 |                                                                  }n# t          $ r t          |           }Y nw xY w|r t	          |          |k    r|d|         dz   }|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...)asdomtoxmlr+   strlen)r&   r=   texts      r#   repr_domxmlrD   ^   s{    zz||!!##   4yy %#d))f$$GVG}u$Ks   &) AAc                    t          | t          j                  ry| j        srt                              dt          |           t          |                      | j        }|j	        | _	        |j
        dz
  | _
        |                                 | _        n2t          | t          j                  r| j	        s| j        j	        | _	        t          | t          j                  r`| j	        Yt                              dt          |           t          |                      | j        j	        | j        j
        c| _	        | _
        t          | t          j                  r`| j	        Yt                              dt          |           t          |                      | j        j	        | j        j
        c| _	        | _
        t          | t          j                  rt                              dt          |           t          |                      t          t!          | j                            t          j                                      D ]I}t%          j        dt%          j        |                                          z  d| j                  | _        Jt          | t          j                  r`| j	        Yt                              dt          |           t          |                      | j        j	        | j        j
        c| _	        | _
        t          | t          j                  r| j	        t/          |           | _	        | j        s|                                 | _        | j	        r	| j        rd S t          | t          j        t          j
        t          j        t          j        f          rUt                              dt          |           t          |                      t/          |           pd| _	        d	| _
        d S d S )
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debugr;   rD   parentsourcelineastextimagetitletermreversedlistfindallresubescapetopicliteral_blockget_node_sourcerubric
field_name)r&   definition_list_itemrH   s      r#   apply_source_workaroundr_   r   s    $()) 	)$. 	)N)$//T1B1B	D 	D 	D#{*1(-1		D%*	+	+ )DK )k($$$ F)<@)$//T1B1B	D 	D 	D!%!3T[5ETY$$$ F)<:)$//T1B1B	D 	D 	D!%!3T[5ETY$
## 8=)$//T1B1B	D 	D 	D #4(;(;E<L(M(M#N#NOO 	8 	8JVL29Z=N=N=P=P3Q3Q$Q$&8 8DNN$$$ F)<@)$//T1B1B	D 	D 	D!%!3T[5ETY $+,, ,1D%d++ > '{ t~  	4LJK	 	 	 
 	C)$//T1B1B	D 	D 	D%d++1r	
 
r%   c                     t          | t          j                  r<t          | j                            dd g          d         t
          j                  rdS dS )Nr   r   TF)r(   r   pendingdetailsr*   r   metar:   s    r#   is_pending_metard      sM    4'' $,""7TF33A6FFtur%   c                 T   t          | t          j                  rdS t          | t          j                  r,|                     d          s|                     d          rdS t          | t          j                  rd| vrdS t          | t          j                  rC| j        s8t          
                    dt          |           t          |                      dS t          | t                    r<d| vr8t          
                    dt          |           t          |                      dS |                     dd          s8t          
                    dt          |           t          |                      dS t          | t          j                  rI| j        d         d	k    r8t          
                    d
t          |           t          |                      dS dS t!          |           st          | t          j                  rdS t          | t          j                  rdS dS )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   rf   r   rP   r*   InlineTextElementrM   rJ   rK   r;   rD   IGNORED_NODESr]   childrenrd   rc   docutils_metar:   s    r#   is_translatablern      s   $-.. t $$$ $((>*B*B dhhuoo t$%% .*D*Du$)** { 	LLD-d33[5F5FH H H5dM** 	~T/I/ILL ;-d33[5F5FH H H 5xx-- 	LLN-d33[5F5FH H H5 dE,-- 	$-2Bh2N2NLLA-d33[5F5FH H H5tt 
4 ? ? t	D(0	1	1 t5r%   doctreec              #   L  K   |                      t                    D ]}t          |t          j                  r|                                D ]}||fV  	;t          |t                    r|j        }|s|                                }nt          |t          j
                  rE|                    d          r||d         fV  |                    d          rd|d         z  }nd}nt          |t                    r|j        }nt          |t          j                  r(t          |          r|j        d         d         j        }nPt          |t          j                  r	|d         }n-|j                            d	d
                                          }|r||fV  dS )z3Extract translatable messages from a document tree.rg   rf   z.. image:: %surirG   r   r   content
 N)rU   rn   r(   r   rf   extract_original_messagesLITERAL_TYPE_NODESrI   rO   r   rP   r*   META_TYPE_NODES
rawcontentra   rd   rb   rm   replacestrip)ro   r&   msgs      r#   extract_messagesr|      s     00  dH122 	5577    Cid.// 	<.C $kkmmek** 	<xx (DK''''xx'' %U3o.. 
	</CCem,, 	<1F1F 	<,w'*5CCh455 	<y/CC.((s3399;;C  	)OOO= r%   c                 J    t          |           D ]}|j        r	|j        c S d S r    )traverse_parentrM   r&   pnodes     r#   r[   r[     s;     &&    < 	 <	 4r%   c                 J    t          |           D ]}|j        r	|j        c S d S r    )r~   rN   r   s     r#   get_node_liner   &  s;     &&  : 	:	4r%   clsc              #   P   K   | r!|t          | |          r| V  | j        } | d S d S r    )r(   rL   )r&   r   s     r#   r~   r~   -  sO      
 ;*T3//;JJJ{      r%   c                 f    | j                             |           }|dk    r| j         |dz
           S d S )Nr   rF   )rL   index)r&   poss     r#   get_prev_noder   4  s6    
+

D
!
!C
Qww{37##tr%   r   c              #      K   t          t          j        d          }|                     |          D ]}d|v r	|d         }n|d         }||fV  dS )z6Traverse translatable index node from a document tree.F)inlineraw_entriesentriesN)r   r   r   rU   )ro   matcherr&   r   s       r#   traverse_translatable_indexr   <  sr      (.777G((  D  =)GG9oGGm r%   staterr   c                     | j         j        }| j         j        }g | j         _        d| j         _        	 |                     |d|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   rF   )match_titles)memotitle_stylessection_levelnested_parse)r   rr   r&   surrounding_title_stylessurrounding_section_levels        r#   nested_parse_with_titlesr   G  s      %z6 %
 8 EJ EJ=!!'1d!CC":
#<
   #;
#<
 <<<<s   A# #A=c                 2   |                                  } |                     t          j                  D ]}d|d<   t	          |                     t          j                            D ]}|j                            |           |                                 S )z&Like node.astext(), but ignore images.rG   rg   )	deepcopyrU   r   rP   rT   rawrL   removerO   )r&   imgr   s      r#   clean_astextr   Z  s    ==??D||EK((  E

DLL++,,  
#;;==r%   rC   c                     t                               |           }|r+d|                    d          |                    d          fS d| | fS )z3Split role content into title and target, if given.TrF      F)explicit_title_rer.   group)rC   r.   s     r#   split_explicit_titler   d  sK    ##D))E 4U[[^^U[[^^33$r%   )singlepairdoubletripleseeseealsoentrytargetidc                 r   ddl m} g }|                                 } | }d}|                     d          rd}| dd                                          } |D ]p}|                     |dz             rV| t          |          dz   d                                          }||         dz   |z   }|                    d	|||d f            nqt          D ]j}|                     |dz             rP| t          |          dz   d                                          }|d
k    rd	}|                    ||||d f            nk|                    d          D ]h}|                                }d}|                    d          rd}|dd                                          }|sN|                    d|||d f           i|S )Nr   )pairindextypesrG   !mainrF   :z; r   r   ,r   )	sphinx.domains.pythonr   rz   
startswithlstriprB   append
indextypessplit)r   r   r   indexentriesoentryr   typer-   s           r#   process_index_entryr   q  s   444444CELKKMMEFD #abb	  "" M MD3J'' 	#d))a-..)//11E"4(4/%7E$ EFFFE		  	M 	MDs
++ c$ii!mnn-33558##!D##T5(D$$GHHH  c** M M##C(( /!D!!""I,,..E ##Xuhd$KLLLLr%   builderr   
docnamesetdocnametree	colorfunc	traversedc           
      P   |                                 }t          |                    t          j                            D ]c}g }t          t          |d                   }|D ]$}	|	|vr	 |                    |	           t          	                     ||	          dz   d           t          | ||	| j                            |	          ||          }
|                    |	           t          j        |	          }|
j        |_        |                    t           j                  D ]}d|vr|	|d<   |                    |           # t$          $ r. t                              t)          d          |	|           Y  w xY w&|j                            ||           e|S )	zwInline all toctrees in the *tree*.

    Record all docnames in *docnameset*, and output docnames with *colorfunc*.
    includefilesrt   T)nonl)r   r   z+toctree contains ref to nonexisting file %rlocation)r   rT   rU   r   toctreemaprA   r   rJ   infoinline_all_toctreesenvget_doctreeaddstart_of_filerl   r   sectionr+   warningr   rL   ry   )r   r   r   r   r   r   toctreenodenewnodesr   includefilesubtreesofsectionnodes                r#   r   r     s    ==??DDLL)9::;; : :3N ;<<' 	) 	)K)++)$$[111KK		+ 6 6 <4KHHH1':{29+2I2I+2V2V2;YH HG NN;///
 #0EEEC#*#3CL'*{{5='A'A A A$K775@K	2OOC(((( ! B B BNN2&S#T#T#. # B B B B BB ,$ 	"";9999Ks   ,A>E4FFstringc                    |                      t                    }|                     t                    }t          j        d|                              dd                              d          }t                              dd	                    |
                                                    }t                              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-rt   rG   )	translate_non_id_translate_digraphs_non_id_translateunicodedata	normalizeencodedecode_non_id_charsrW   joinr   _non_id_at_endsrA   )r   ids     r#   _make_idr     s      
		4	5	5B	'	(	(B 
	vr	*	*	1	1'8	D	D	K	KG	T	TB			3 4 4	5	5B			R	$	$Br77Nr%   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  rG   r   r   documentprefixrR   c                    d}|r|dz   }n|j         j        pddz   }|r|rt          ||z            }||k    rd}n|rt          |          }|dk    rd}|	||j        v r#||                     |          z  }|||j        v #|S )z>Generate an appropriate node_id for given *prefix* and *term*.Nz-%sr   z%srG   )settings	id_prefixr   idsnew_serialno)r   r  r  rR   node_ididformats         r#   make_idr    s     G @E>%/744?  $ 8d?++fG	 4..b==G
/W44S--f555 /W44 Nr%   	conditionc                 ~    | D ]9}t          |t          j                  r|                    d          |k    r|c S :dS )zBPick matched pending_xref_condition node up from the pending_xref.r  N)r(   r   pending_xref_conditionr*   )r&   r  subnodes      r#   find_pending_xref_conditionr    sN       w ?@@ 	K((I55NNNtr%   fromdocname	todocnamechildrQ   c                     t          j        ddd          }||k    r|r||d<   n;|r |                     ||          dz   |z   |d<   n|                     ||          |d<   |r||d<   ||z  }|S )z$Shortcut to create a reference node.rG   T)internalrefid#refurireftitle)r   	referenceget_relative_uri)r   r  r  r   r  rQ   r&   s          r#   make_refnoder  (  s     ?2rD111DiH W 	N%66{INN!"$,-DNN %55k9MMDN ! ZEMDKr%   	directivec                 ^    | j                             | j                  \  |_        |_        d S r    )state_machineget_source_and_linelinenorM   rN   )r   r&   s     r#   set_source_infor%  ;  s*    33I4DEE DKr%   inlinerr$  c                 T    | j                             |          \  |_        |_        d S r    )reporterr#  rM   rN   )r&  r$  r&   s      r#   set_role_source_infor)  @  s%    $-AA&IIDKr%   srcdstc                 V    t          |           |_        t          |           |_        d S r    )r[   rM   r   rN   )r*  r+  s     r#   copy_source_infor-  D  s$     %%CJS!!CHHHr%   c                     t          | j                  D ]5}t          |t                    r dS |                    dd          du r dS 6t          | dd          du rdS dS )z0Check whether the node is smart-quotable or not.Fsupport_smartquotesNT)r~   rL   r(   NON_SMARTQUOTABLE_PARENT_NODESr*   getattrr   s     r#   is_smartquotabler2  T  s     --  e;<< 	55YY,d33u<<55 = t*D11U::u4r%   tagsr   c                 
   |                      t          j                  D ]}	 |                    |d                   }|r.|                    |j        pt          j                               N|                    t          j                               u# t          $ ra}t          
                    t          d          ||           |                    |j        pt          j                               Y d}~d}~ww xY wdS )z0Filter ``only`` nodes which do not match *tags*.exprz8exception while evaluating only directive expression: %sr   N)rU   r   onlyeval_conditionreplace_selfrl   r   commentr+   rJ   r   r   )r  r3  r&   reterrs        r#   process_only_nodesr<  b  s     // 3 3	3%%d6l33C  3!!$-"B5=??CCCC !!%-//2222  	@ 	@ 	@NN2XYY[^$(  * * *dm>u}????????	@3 3s   B
D AC;;D r"   c                      | j         | j        fi | j        }t          | t          j                  r| 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/
    )r9   rI   
attributesr(   r   r   rM   rN   )r"   newnodes     r#   	_new_copyr@  v  sL     dnT^??t??G$&& !yNr%   )r<   r    )rG   N)gr4   rV   r   typingr   r   r   r   r   r   r	   r
   r   r   docutilsr   docutils.nodesr   r   docutils.parsers.rstr   docutils.parsers.rst.statesr   docutils.statemachiner   sphinxr   sphinx.localer   sphinx.utilr   sphinx.buildersr   sphinx.domainr   sphinx.environmentr   sphinx.util.tagsr   	getLoggerr1   rJ   compileDOTALLr   caption_ref_rer   rA   r;   intrD   r_   	InvisiblerZ   doctest_blockversionmodifiedrk   r5   rd   rn   
math_blockr   rv   rP   IMAGE_TYPE_NODESrc   rw   r|   r[   r   r~   r   r   r   r   r   r   r   r  r   r   r   r   r   r   r  pending_xrefr  r  r  r%  r)  r-  FixedTextElementliteralmathproblematicnot_smartquotabler0  r2  r<  r@  copyr6   r%   r#   <module>r_     sX	   9 9 				                                  ( ( ( ( ( ( ( ( * * * * * * / / / / / / , , , , , ,                   &''''''((((((333333%%%%%%		8	$	$ BJ?KK "1  1  1  1  1  1  1  1 hDt D D D D D d C     (;' ;d ; ; ; ;~ 
O			$ 4    *$ *4 * * * *\ 
			I	  
K  M
 g  (5#3F*G        F' hsm     HSM     '  x7H     $     XeGTR^M_D_>`5a    =C =* =D =S = = = =&w 3    s uT3^'<      

$s $c $!%S#sHSM(I"JK$ $ $ $N C 3 #n9ANRSVi"^   DS S    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    59 # u~ $,SM=@   4h&;  %-g%6    IM ) # # QT dDJ./8@o   &Fy F F F F F F
J' J3 Jd Jt J J J J"' " "D " " " " 
	M	J	K	I	" 4 D    3 3V 3 3 3 3 3(
G 
 
 
 
 
    r%   