
    ~Ti{I                       d Z ddlmZ ddlZddlZddl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 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#m$Z$ erCddl%m&Z&m'Z' ddlm(Z(m)Z)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8 ddd fZ9 ejt                  e;      Z< e=h d      Z> G d de      Z? G d  d!e      Z@ G d" d#e?      ZAdGd$ZB G d% d&e?      ZC G d' d(e?      ZD G d) d*e?      ZE G d+ d,e?      ZFe	j                  e	j                  e	j                  ej                  e	j                  d-ZL G d. d/e?      ZM G d0 d1e?      ZN G d2 d3e?      ZO G d4 d5e?      ZP G d6 d7e?      ZQ G d8 d9e?      ZR G d: d;e      ZS G d< d=ee?      ZT G d> d?e?      ZU G d@ dAe?      ZV G dB dCe?      ZWdHdDZXdIdEZYdJdFZZy)Kz:Docutils transforms used by Sphinx when reading documents.    )annotationsN)TYPE_CHECKINGcast)nodes)	TransformTransformer)ContentsFilter)	Footnotes)SmartQuotes)normalize_language_tag)
smartchars)addnodes)_deprecation_warning)___)logging)format_date)apply_source_workaroundis_smartquotable)IterableIterator)AnyClassVarLiteral)Node)TypeIs)Sphinx)Config)StandardDomain)BuildEnvironment)ExtensionMetadata_DEFAULT_SUBSTITUTION_NAMESc                     t         d   S )N)versionreleasetodaytranslation progress)r        M/home/agent/.local/lib/python3.12/site-packages/sphinx/transforms/__init__.pyr"   r"   %   s    w	 ( r)   >   r&   r%   r$   r'   c                  F    e Zd ZdZedd       Zedd       Zedd       Zy)	SphinxTransformzA base class of Transforms.

    Compared with ``docutils.transforms.Transform``, this class improves accessibility to
    Sphinx APIs.
    c                    | j                   j                  }| j                   j                  }t        || dd       | j                  j
                  S )z)Reference to the :class:`.Sphinx` object.z.app)   r   )remove)	__class__
__module____qualname__r   env_app)self
cls_modulecls_names      r*   appzSphinxTransform.app>   sC     ^^..
>>..ZH:T):7Kxx}}r)   c                B    | j                   j                  j                  S )z3Reference to the :class:`.BuildEnvironment` object.)documentsettingsr3   r5   s    r*   r3   zSphinxTransform.envF   s     }}%%)))r)   c                .    | j                   j                  S )z)Reference to the :class:`.Config` object.)r3   configr<   s    r*   r>   zSphinxTransform.configK   s     xxr)   N)returnr   )r?   r    )r?   r   )__name__r1   r2   __doc__propertyr8   r3   r>   r(   r)   r*   r,   r,   7   sC       * *  r)   r,   c                  F     e Zd ZU dZded<   dZded<   d	dZd
 fdZ xZS )SphinxTransformerzA transformer for Sphinx.nodes.documentr:   NzBuildEnvironment | Noner3   c                    || _         y N)r3   )r5   r3   s     r*   set_environmentz!SphinxTransformer.set_environmentW   s	    r)   c                   t        | j                  t        j                        r`t        | j                  j                  d      s1| j
                  r%| j
                  | j                  j                  _        t        |           y 	 ddlm	}  |d      }| j
                  r| j
                  |j                  _        || j                  z  }|| _        t        |           | j                  d   | _        y # | j                  d   | _        w xY w)Nr3   r   )new_document )

isinstancer:   r   hasattrr;   r3   superapply_transformssphinx.util.docutilsrJ   )r5   rJ   r:   r0   s      r*   rO   z"SphinxTransformer.apply_transformsZ   s    dmmU^^44==1159dhh-1XX&&*G$&
1='+88,0HHH%%)DMM) ((* $a 0a 0s   AC5 5D)r3   r    r?   None)r?   rQ   )	r@   r1   r2   rA   __annotations__r3   rH   rO   __classcell__r0   s   @r*   rD   rD   Q   s&    ##'C	 '1 1r)   rD   c                  ,    e Zd ZdZdZddZ	 	 	 	 ddZy)DefaultSubstitutionszBReplace some substitutions if they aren't defined in the document.   c                    t         t        | j                  j                        z
  }| j                  j	                  t
        j                        D ],  }|d   x}|v s|j                  | j                  |             . y )Nrefname)	_DEFAULT_SUBSTITUTIONSsetr:   substitution_defsfindallr   substitution_referencereplace_self_handle_default_substitution)r5   kwargs	to_handlerefnames        r*   applyzDefaultSubstitutions.applyu   sk    *S1P1P-QQ	==(()E)EF 	JCI&94  !B!B4!HI	Jr)   c                   |dk(  r(t        j                  t        | j                              S |dk(  r| j                  j
                  x}rt        j                  |      S | j                  j                  xs t        d      }t        j                  t        || j                  j                              S t        j                  t        | j                  |            S )Nr'   r&   z	%b %d, %Y)language)r   Text_calculate_translation_progressr:   r>   r&   	today_fmtr   r   rg   getattr)r5   rd   textrj   s       r*   r`   z1DefaultSubstitutions._handle_default_substitution|   s     ))::=dmmLMM7?{{(((t(zz$''--?;I::k)dkk>R>RSTTzz'$++t455r)   Nra   r   r?   rQ   )rd   r"   r?   z
nodes.Text)r@   r1   r2   rA   default_priorityre   r`   r(   r)   r*   rV   rV   o   s(    L J6/6	6r)   rV   c                    	 | d   }|d   }|d   }|dk  rt        d      S ||z  dS # t         $ r t        d      cY S w xY w)Ntranslation_progressz)could not calculate translation progress!total
translatedr   zno translated elements!z.2%)KeyErrorr   )r:   rp   rq   rr   s       r*   ri   ri      si    >'(>? !)E%l3Jz*++5 %&  ><==>s   ( ??c                      e Zd ZdZdZddZy)MoveModuleTargetszqMove module targets that are the first thing in a section to the section
    title.

    XXX Python specific
    rW   c                r   t        | j                  j                  t        j                              D ]  }|d   s	d|v st        |j                        t        j                  u s4|j                  j                  |      dk(  sS|d   |j                  d   dd |j                  j                  |        y )Nidsismod   r   )
listr:   r]   r   targettypeparentsectionindexr/   r5   ra   nodes      r*   re   zMoveModuleTargets.apply   s    ..u||<= 	)D;4%6 KK%%d+q0*.u+E"1Q'""4(	)r)   Nrm   r@   r1   r2   rA   rn   re   r(   r)   r*   ru   ru      s     )r)   ru   c                      e Zd ZdZdZddZy)HandleCodeBlocksz+Several code block related transformations.rW   c                    | j                   j                  t        j                        D ]:  }t	        d |j
                  D              s |j                  |j
                         < y )Nc              3  P   K   | ]  }t        |t        j                           y wrG   )rL   r   doctest_block).0childs     r*   	<genexpr>z)HandleCodeBlocks.apply.<locals>.<genexpr>   s     Ue:eU%8%89Us   $&)r:   r]   r   block_quoteallchildrenr_   r   s      r*   re   zHandleCodeBlocks.apply   sJ    MM))%*;*;< 	1DUt}}UU!!$--0	1r)   Nrm   r   r(   r)   r*   r   r      s    51r)   r   c                      e Zd ZdZdZddZy)AutoNumberingzERegister IDs of tables, figures and literal_blocks to assign numbers.rW   c                0   | j                   j                  j                  }| j                  j	                  t
        j                        D ]J  }|j                  |      s|j                  |      '|d   g k(  s0| j                  j                  |       L y )Nrw   )
r3   domainsstandard_domainr:   r]   r   Elementis_enumerable_nodeget_numfig_titlenote_implicit_target)r5   ra   domainr   s       r*   re   zAutoNumbering.apply   sv    !%!1!1!A!AMM))%--8 	9D))$/++D1=K2%2248	9r)   Nrm   r   r(   r)   r*   r   r      s    O	9r)   r   c                      e Zd ZdZdZddZy)SortIdsz7Sort section IDs so that the "id[0-9]+" one comes last.i  c                    | j                   j                  t        j                        D ]A  }t	        |d         dkD  s|d   d   j                  d      s-g |d   dd  |d   d   |d<   C y )Nrw      r   id)r:   r]   r   r~   len
startswithr   s      r*   re   zSortIds.apply   sq    MM))%--8 	AD4;!#UA(A(A$(G@UAB@eQ@U	Ar)   Nrm   r   r(   r)   r*   r   r      s    AAr)   r   )zliteral-blockzdoctest-blockrawr   imagec                      e Zd ZdZdZddZy)ApplySourceWorkaroundz&Update source and rawsource attributes
   c                    | j                   j                         D ]G  }t        |t        j                  t        j
                  t        j                  f      s=t        |       I y rG   )r:   r]   rL   r   TextElementr   topicr   r   s      r*   re   zApplySourceWorkaround.apply   sE    MM))+ 	.D$!2!2EKK MN'-	.r)   Nrm   r   r(   r)   r*   r   r      s    0.r)   r   c                      e Zd ZdZdZddZy)AutoIndexUpgraderzQDetect old style (4 column based indices) and automatically upgrade to new style.rW   c                J   | j                   j                  t        j                        D ]w  }d|v st	        d |d   D              st        d      |d   z  }t        j                  ||       t        |d         D ]!  \  }}t        |      dk(  sg |d |d   |<   # y y )Nentriesc              3  8   K   | ]  }t        |      d k(    yw)   N)r   )r   entrys     r*   r   z*AutoIndexUpgrader.apply.<locals>.<genexpr>   s     (VUUq(Vs   zG4 column based index found. It might be a bug of extensions you use: %r)locationr   )
r:   r]   r   r   anyr   loggerwarning	enumerater   )r5   ra   r   msgir   s         r*   re   zAutoIndexUpgrader.apply   s    MM))(..9 	<DD S(Vd9o(V%VF 9o	&  sT2 )$y/ : <HAu5zQ-;u^d^Y*<	<r)   Nrm   r   r(   r)   r*   r   r      s    [<r)   r   c                      e Zd ZdZdZddZy)ExtraTranslatableNodeszMake nodes translatabler   c                &   t        | j                  j                        t        fdt        j                         D              sy dfd}| j                  j                  |      D ]#  }t        |t        j                        sJ d|d<   % y )Nc              3  2   K   | ]  \  }}|v s|  y wrG   r(   )r   kvtargetss      r*   r   z/ExtraTranslatableNodes.apply.<locals>.<genexpr>  s     V41agQVs   c                    t        |       S rG   )rL   )r   target_nodess    r*   is_translatable_nodez:ExtraTranslatableNodes.apply.<locals>.is_translatable_node  s    dL11r)   Ttranslatable)r   r   r?   zTypeIs[nodes.Element])	frozensetr>   gettext_additional_targetstupleTRANSLATABLE_NODESitemsr:   r]   rL   r   r   )r5   ra   r   r   r   r   s       @@r*   re   zExtraTranslatableNodes.apply  s{    DKKBBCV+=+C+C+EVV	2 MM))*>? 	(DdEMM222#'D 	(r)   Nrm   r   r(   r)   r*   r   r     s    !(r)   r   c                  6    e Zd ZdZej
                  dz   ZddZy)UnreferencedFootnotesDetectorz/Detect unreferenced footnotes and emit warningsry   c                   | j                   j                  D ]D  }|d   r	|d   st        j                  t	        d      |d   r|d   d   n|d   d   dd|       F | j                   j
                  D ]*  }|d   r	t        j                  t	        d	      dd|       , | j                   j                  D ]0  }|d   r	|d   st        j                  t	        d
      dd|       2 y )Nbackrefsnamesz Footnote [%s] is not referenced.r   dupnamesrc   footnote)r|   subtyper   zFootnote [*] is not referenced.zFootnote [#] is not referenced.)r:   	footnotesr   r   r   symbol_footnotesautofootnotesr   s      r*   re   z#UnreferencedFootnotesDetector.apply%  s    MM++ 	D 
#W9:(,WDM!$4
;KA;N&!  	 MM22 	D
#89&!	  	 MM// 
	D 
#W89&!	  
	r)   Nrm   )r@   r1   r2   rA   r
   rn   re   r(   r)   r*   r   r      s    9 11A5r)   r   c                      e Zd ZdZdZddZy)DoctestTransformz.Set "doctest" style to each doctest_block node  c                    | j                   j                  t        j                        D ]  }|d   j	                  d        y )Nclassesdoctest)r:   r]   r   r   appendr   s      r*   re   zDoctestTransform.applyL  s8    MM))%*=*=> 	.DO""9-	.r)   Nrm   r   r(   r)   r*   r   r   G  s    8.r)   r   c                      e Zd ZdZdZddZy)FilterSystemMessagesz&Filter system messages from a doctree.i  c                6   | j                   j                  rdnd}t        | j                  j	                  t
        j                              D ]J  }|d   |k  st        j                  d|j                                |j                  j                  |       L y )Nry      levelz%s [filtered system message])r>   keep_warningsrz   r:   r]   r   system_messager   debugastextr}   r/   )r5   ra   filterlevelr   s       r*   re   zFilterSystemMessages.applyV  sq    ;;44a!..u/C/CDE 	)DG}{*;T[[]K""4(	)r)   Nrm   r   r(   r)   r*   r   r   Q  s    0)r)   r   c                  0    e Zd ZdZej
                  ZddZy)SphinxContentsFilterzsUsed with BuildEnvironment.add_toc_from() to discard cross-file links
    within table-of-contents link nodes.
    c                "    t         j                  rG   )r   SkipNode)r5   r   s     r*   visit_imagez SphinxContentsFilter.visit_imagee  s    nnr)   N)r   znodes.imager?   rQ   )r@   r1   r2   rA   r	    ignore_node_but_process_childrenvisit_pending_xrefr   r(   r)   r*   r   r   ^  s     (HHr)   r   c                  d     e Zd ZU dZdZej                  Zded<   d fdZd	dZ		 	 	 	 d
dZ
 xZS )SphinxSmartQuoteszmCustomized SmartQuotes to avoid transform for some extra node types.

    refs: sphinx.parsers.RSTParser
    i  zClassVar[str]smartquotes_actionc                z    | j                         sy | j                  j                  | _        t        |           y rG   )is_availabler>   r   rN   re   )r5   ra   r0   s     r*   re   zSphinxSmartQuotes.applyr  s/      " #'++"@"@r)   c                   | j                   j                  j                  dg       }| j                   j                  j                  dg       }| j                  j                  j
                  du ry| j                   j                  du ry| j                  j                  j                  |v ry| j                   j                  |v ry| j                  j                  d   }t        d t        |      D              S )Nbuilders	languagesFlanguage_codec              3  @   K   | ]  }|t         j                  v   y wrG   )r   quotes)r   tags     r*   r   z1SphinxSmartQuotes.is_available.<locals>.<genexpr>  s     X3*+++Xs   )r>   smartquotes_excludesgetr:   r;   smart_quotessmartquotesr3   _builder_clsrd   rg   r   r   )r5   r   r   rg   s       r*   r   zSphinxSmartQuotes.is_available~  s    ;;3377
BGKK4488bI	==!!..%7;;""e+88  %%1;;9, 88$$_5X7Mh7WXXXr)   c              #     K   |D ]H  }t        |      r't        j                  ddt        |            }d|f 5d|j	                         f J y w)Nz(?<=\x00)([-\\\'".`])z\\\1plainliteral)r   resubstrr   )r5   txtnodestxtnoderl   s       r*   
get_tokenszSphinxSmartQuotes.get_tokens  sT     
   	2G(vv6WNtm#  !111	2s   AArm   )r?   bool)r   zIterable[Node]r?   z1Iterator[tuple[Literal['literal', 'plain'], str]])r@   r1   r2   rA   rn   r   r   rR   re   r   r  rS   rT   s   @r*   r   r   i  sA    
 (3(F(FF
Y*2&2	:2r)   r   c                      e Zd ZdZdZddZy)DoctreeReadEventz!Emit :event:`doctree-read` event.ip  c                d    | j                   j                  j                  d| j                         y )Nzdoctree-read)r3   eventsemitr:   )r5   ra   s     r*   re   zDoctreeReadEvent.apply  s    ^T]];r)   Nrm   r   r(   r)   r*   r  r    s    +<r)   r  c                      e Zd ZdZdZddZy)GlossarySorterz.Sort glossaries that have the ``sorted`` flag.r   c                    | j                   j                  t        j                        D ](  }|d   s	t	        d|d         }t        |d       |d d  * y )Nsortedznodes.definition_listr   c                    t        j                  dt        d|       d   j                         j	                               S )NNFDz
nodes.termr   )unicodedata	normalizer   r   lower)items    r*   <lambda>z&GlossarySorter.apply.<locals>.<lambda>  s4    [%:%:tL$7:AACIIK& r)   key)r:   r]   r   glossaryr   r  )r5   ra   r  definition_lists       r*   re   zGlossarySorter.apply  sV    --h.?.?@ 	H!"&'>"L%+#&"	r)   Nrm   r   r(   r)   r*   r	  r	    s    8 	r)   r	  c                      e Zd ZdZdZddZy)%ReorderConsecutiveTargetAndIndexNodesa  Index nodes interspersed between target nodes prevent other
    Transformations from combining those target nodes,
    e.g. ``PropagateTargets``.  This transformation reorders them:

    Given the following ``document`` as input::

        <document>
            <target ids="id1" ...>
            <index entries="...1...">
            <target ids="id2" ...>
            <target ids="id3" ...>
            <index entries="...2...">
            <target ids="id4" ...>

    The transformed result will be::

        <document>
            <index entries="...1...">
            <index entries="...2...">
            <target ids="id1" ...>
            <target ids="id2" ...>
            <target ids="id3" ...>
            <target ids="id4" ...>
       c                v    | j                   j                  t        j                        D ]  }t	        |        y rG   )r:   r]   r   r{   _reorder_index_target_nodes)r5   ra   r{   s      r*   re   z+ReorderConsecutiveTargetAndIndexNodes.apply  s,    mm++ELL9 	0F'/	0r)   Nrm   r   r(   r)   r*   r  r    s    4 0r)   r  c                   g }| j                  dd      D ]?  }t        |t        j                  t        j
                  f      r|j                  |       ? n t        |      dk  ry|d   j                  }||d   j                  k(  rU|j                  |d         }|j                  |d         }|t        |      z   dz
  |k(  rt        |t        	      |||dz    yyy)
zSort target and index nodes.

    Find all consecutive target and index nodes starting from ``start_node``,
    and move all index nodes to before the first target node.
    FT)descendsiblingsry   Nr   r   r  )r]   rL   r   r{   r   r   r   r   r}   r  	_sort_key)
start_nodenodes_to_reorderr   r}   	first_idxlast_idxs         r*   r  r    s     =?
 ""54"@ dU\\8>>:;##D)	 q a ''F!"%,,,LL!1!!45	<< 0 45s+,,q0H</56FI/VF9x!|, = -r)   c                    t        | t        j                        ryt        | t        j                        rydt        |       }t        |      )Nr   r   z+_sort_key called with unexpected node type )rL   r   r   r   r{   r|   
ValueError)r   r   s     r*   r   r     s>    $'$%7T
~
FC
S/r)   c                   | j                  t               | j                  t               | j                  t               | j                  t               | j                  t
               | j                  t               | j                  t               | j                  t               | j                  t               | j                  t               | j                  t               | j                  t               | j                  t               | j                  t               | j                  t               ddddS )NbuiltinT)r$   parallel_read_safeparallel_write_safe)add_transformr   r   rV   ru   r   r   r   r   r   r   r   r   r  r	  r  )r8   s    r*   setupr,    s    +,,-*+'(&'g&'m$'(*+34'(&'n%;< "# r)   )r:   rE   r?   r   )r!  znodes.targetr?   rQ   )r   z
nodes.Noder?   int)r8   r   r?   r!   )[rA   
__future__r   r   r  typingr   r   docutilsr   docutils.transformsr   r   docutils.transforms.partsr	   docutils.transforms.referencesr
   docutils.transforms.universalr   docutils.utilsr   docutils.utils.smartquotesr   sphinxr   sphinx.deprecationr   sphinx.localer   r   sphinx.utilr   sphinx.util.i18nr   sphinx.util.nodesr   r   collections.abcr   r   r   r   r   docutils.nodesr   typing_extensionsr   sphinx.applicationr   sphinx.configr   sphinx.domains.stdr   sphinx.environmentr    sphinx.util.typingr!   r"   	getLoggerr@   r   r   rZ   r,   rD   rV   ri   ru   r   r   r   literal_blockr   r   r   r   r   r   r   r   r   r   r   r   r   r  r	  r  r  r   r,  r(   r)   r*   <module>rG     s   @ " 	  &  6 4 4 5 1 1  3   ( G2--#()$134 
		8	$" $  i 41 1<6? 6:
') )2	1 	1,9O 9"Ao A ((((99^^[[ .O .< <*(_ (&$O $N. .
)? 
)> 62_ 62r< <_ &0O 0DW8r)   