
    -Phh                    H   U d Z ddlmZ ddlZddlZddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlZddlmZ dd	lmZ dd
l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   ej!        e"          Z# ej$        d          Z%erxddl&m'Z'm(Z( ddl)m*Z*m+Z+ ddl
m,Z,m-Z- ddl.m/Z/ ddl0m1Z1m2Z2m3Z3 ddl4m5Z5 ddlm6Z6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z= ddl>m?Z?  G d de-          Z@ G d d e-          ZA G d! d"e-          ZB eC            ZDd#eEd$<   edbd'            ZFdcd+ZGddd/ZHdcd0ZIded3ZJdfd4ZKdgd7ZLdhd8ZMdhd9ZNedbd:            ZOedbd;            ZPedid>            ZQedjdid?            ZR G d@ dA          ZS G dB dCeT          ZU G dD dEeS          ZV G dF dG          ZW G dH dIe          ZX G dJ dKe          ZYedkdP            ZZ G dQ dRe          Z[ G dS dTe          Z\ G dU dV          Z] G dW dXe]          Z^ G dY dZej_                  Z`d[eEd\<   djdldaZadS )mzUtility functions for docutils.    )annotationsN)contextmanager)copy)Path)TYPE_CHECKING)nodes)
FileOutput)	Directive
directivesroles)StateMachine)Reporterunescape)SphinxError)__)logging)nested_parse_to_nodesz>^(.+?:(?:\d+)?): \((DEBUG|INFO|WARNING|ERROR|SEVERE)/(\d+)?\) )IteratorSequence)
ModuleTypeTracebackType)AnyProtocol)Values)ElementNodesystem_message)Inliner)State
StringList)Builder)Config)BuildEnvironment)RoleFunctionc                  .    e Zd ZU ded<   ded<   ded<   dS )_LanguageModulezdict[str, str]labelsz	list[str]author_separatorsbibliographic_fieldsN)__name__
__module____qualname____annotations__     T/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinx/util/docutils.pyr&   r&   ,   s6         $$$$''''''r/   r&   c                      e Zd Zdd	Zd
S )_DirectivesDispatcherdirective_namestrlanguage_moduler&   documentnodes.documentreturn3tuple[type[Directive] | None, list[system_message]]c                   d S Nr.   selfr3   r5   r6   s       r0   __call__z_DirectivesDispatcher.__call__2   s     CF#r/   N)r3   r4   r5   r&   r6   r7   r8   r9   r*   r+   r,   r>   r.   r/   r0   r2   r2   1   s.        	F 	F 	F 	F 	F 	Fr/   r2   c                      e Zd ZddZdS )_RolesDispatcher	role_namer4   r5   r&   linenointreporterr   r8   0tuple[RoleFunction | None, list[system_message]]c                   d S r;   r.   r=   rB   r5   rC   rE   s        r0   r>   z_RolesDispatcher.__call__;   s     @Csr/   N)
rB   r4   r5   r&   rC   rD   rE   r   r8   rF   r?   r.   r/   r0   rA   rA   :   s.        	C 	C 	C 	C 	C 	Cr/   rA   zset[type[Element]]additional_nodesr8   Iterator[None]c               #    K   	 t          t          j                  } t          t          j                  }dV  | t          _        |t          _        t          t                    D ]+}t          |           t                              |           ,dS # | t          _        |t          _        t          t                    D ]+}t          |           t                              |           ,w xY w)z"Create namespace for reST parsers.N)	r   r   _directivesr   _roleslistrI   unregister_nodediscard)rL   rM   nodes      r0   docutils_namespacerR   H   s      +:122el##!,
)** 	+ 	+DD!!!$$T****	+ 	+ "-
)** 	+ 	+DD!!!$$T****	+s   6B AC.namer4   boolc                    | t           j        v S )z1Check the *name* directive is already registered.)r   rL   rS   s    r0   is_directive_registeredrW   Y   s    :)))r/   	directivetype[Directive]Nonec                0    t          j        | |           dS )zRegister a directive to docutils.

    This modifies global state of docutils.  So it is better to use this
    inside ``docutils_namespace()`` to prevent side-effects.
    N)r   register_directive)rS   rX   s     r0   r\   r\   ^   s     !$	22222r/   c                    | t           j        v S )z,Check the *name* role is already registered.)r   rM   rV   s    r0   is_role_registeredr^   g   s    5<r/   roler$   c                0    t          j        | |           dS )zRegister a role to docutils.

    This modifies global state of docutils.  So it is better to use this
    inside ``docutils_namespace()`` to prevent side-effects.
    N)r   register_local_role)rS   r_   s     r0   register_rolerb   l   s     
dD)))))r/   c                F    t           j                            | d           dS )z Unregister a role from docutils.N)r   rM   poprV   s    r0   unregister_rolere   u   s     	LT4     r/   rQ   type[Element]c                F    t          t          j        d| j        z             S )z'Check the *node* is already registered.visit_)hasattrr   GenericNodeVisitorr*   rQ   s    r0   is_node_registeredrl   z   s    5+X-EFFFr/   c                    t          t          j        d| j        z             s6t          j        | j        g           t
                              |            dS dS )zRegister a node to docutils.

    This modifies global state of some visitors.  So it is better to use this
    inside ``docutils_namespace()`` to prevent side-effects.
    rh   N)ri   r   rj   r*   _add_node_class_namesrI   addrk   s    r0   register_noderp      sY     5+X-EFF ##T]O444T"""""# #r/   c                ^   t          t          j        d| j        z             rt	          t          j        d| j        z              t	          t          j        d| j        z              t	          t          j        d| j        z              t	          t          j        d| j        z              dS dS )zaUnregister a node from docutils.

    This is inverse of ``nodes._add_nodes_class_names()``.
    rh   depart_N)ri   r   rj   r*   delattrSparseNodeVisitorrk   s    r0   rO   rO      s    
 u'DM)ABB D((T]*BCCC()dm*CDDD'DM)ABBB'T])BCCCCC	D Dr/   c               #     K   ddl m 	 ddfd
} 	 | t          j        _        dV  t          j        _        dS # t          j        _        w xY w)zPatch docutils.languages.get_language() temporarily.

    This ignores the second argument ``reporter`` to suppress warnings.
    See: https://github.com/sphinx-doc/sphinx/issues/3788
    r   get_languageNlanguage_coder4   rE   Reporter | Noner8   r   c                     |           S r;   r.   rx   rE   rw   s     r0   patched_get_languagez2patched_get_language.<locals>.patched_get_language        |M***r/   r;   rx   r4   rE   ry   r8   r   )docutils.languagesrw   docutils	languagesr|   rw   s    @r0   r|   r|      s       0///// 9=+ + + + + + +
7*>' +7''','6666s	   ; Ac               #     K   ddl m 	 ddfd
} 	 | t          j        j        j        _        dV  t          j        j        j        _        dS # t          j        j        j        _        w xY w)a]  Patch docutils.parsers.rst.languages.get_language().
    Starting from docutils 0.17, get_language() in ``rst.languages``
    also has a reporter, which needs to be disabled temporarily.

    This should also work for old versions of docutils,
    because reporter is none by default.

    See: https://github.com/sphinx-doc/sphinx/issues/10179
    r   rv   Nrx   r4   rE   ry   r8   r   c                     |           S r;   r.   r{   s     r0   r|   z6patched_rst_get_language.<locals>.patched_get_language   r}   r/   r;   r~   )docutils.parsers.rst.languagesrw   r   parsersrstr   r   s    @r0   patched_rst_get_languager      s       <;;;;; 9=+ + + + + + +
C6J&3 7C&333l&3BBBBs   A A,confdirstr | os.PathLike[str] | Nonec              #    K   	 t           j                            dd          }| r>t          | d                                          }t          |          t           j        d<   dV  |"t           j                            dd           dS |t           j        d<   dS # |!t           j                            dd           n|t           j        d<   w xY w)z?Let docutils know the location of ``docutils.conf`` for Sphinx.DOCUTILSCONFIGNzdocutils.conf)osenvirongetr   resolver4   rd   )r   docutils_configdocutils_conf_paths      r0   using_user_docutils_confr      s      
;*..)94@@ 	C!%g!?!?!G!G!I!I+./A+B+BBJ'("JNN+T22222+:BJ'((( "JNN+T2222+:BJ'(::::s   A$B 4Cc              #     K   t                      5  t                      5  t          |           5  dV  ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )zPatch to docutils temporarily.N)r|   r   r   )r   s    r0   patch_docutilsr      sI      	  ""  	!)) 
 	                                               sV   A0AAAAAA	AA0A	A0A	 A00A47A4c                  J    e Zd ZdZddZddZd dZddZddZd!dZ	d"dZ
dS )#CustomReSTDispatcherzCustom reST's mark-up dispatcher.

    This replaces docutils's directives and roles dispatch mechanism for reST parser
    by original one temporarily.
    r8   rZ   c                &    d | _         d | _        d S )Nc                 
    d g fS r;   r.   argss    r0   <lambda>z/CustomReSTDispatcher.__init__.<locals>.<lambda>   s
    D": r/   c                 
    d g fS r;   r.   r   s    r0   r   z/CustomReSTDispatcher.__init__.<locals>.<lambda>   s
    4* r/   )directive_func
roles_funcr=   s    r0   __init__zCustomReSTDispatcher.__init__   s    5M5M,D,Dr/   c                .    |                                   d S r;   )enabler   s    r0   	__enter__zCustomReSTDispatcher.__enter__   s    r/   exc_typetype[BaseException] | None	exc_valueBaseException | None	tracebackTracebackType | Nonec                .    |                                   d S r;   )disable)r=   r   r   r   s       r0   __exit__zCustomReSTDispatcher.__exit__   s     	r/   c                    t           j        | _        t          j        | _        | j        t           _        | j        t          _        d S r;   )r   rX   r   r   r_   	role_funcr   s    r0   r   zCustomReSTDispatcher.enable   s-    (2#~
Y


r/   c                J    | j         t          _        | j        t          _        d S r;   )r   r   rX   r   r   r_   r   s    r0   r   zCustomReSTDispatcher.disable   s    #2
^


r/   r3   r4   r5   r   r6   r7   r9   c                0    |                      |||          S r;   )r   r<   s       r0   rX   zCustomReSTDispatcher.directive  s     "">?HMMMr/   rB   rC   rD   rE   r   )tuple[RoleFunction, list[system_message]]c                2    |                      ||||          S r;   )r   rH   s        r0   r_   zCustomReSTDispatcher.role
  s&     ~~	
 
 	
r/   Nr8   rZ   )r   r   r   r   r   r   r8   rZ   r3   r4   r5   r   r6   r7   r8   r9   
rB   r4   r5   r   rC   rD   rE   r   r8   r   )r*   r+   r,   __doc__r   r   r   r   r   rX   r_   r.   r/   r0   r   r      s         E E E E         $ $ $ $N N N N
 
 
 
 
 
r/   r   c                      e Zd ZdS )ElementLookupErrorN)r*   r+   r,   r.   r/   r0   r   r     s        Dr/   r   c                  <     e Zd ZdZd fdZd fdZd fdZ xZS )sphinx_domainszcMonkey-patch directive and role dispatch, so that domain-specific
    markup takes precedence.
    envr#   r8   rZ   c                x    |j         | _         |j        | _        t                                                       d S r;   )domainscurrent_documentsuperr   )r=   r   	__class__s     r0   r   zsphinx_domains.__init__"  s3    { # 4r/   r3   r4   r5   r   r6   r7   r9   c                   |                                 }d|v r{|                    d          \  }}}	 | j        |         }|                    |          }||g fS nc# t          $ r+ t
                              t          d          |           Y n/w xY w|}| j        j	        }	|	|	                    |          }||g fS | j        j
                            |          }||g fS t                                          |||          S )z>Lookup a directive, given its name which can include a domain.:Nzunknown directive name: %s)lower	partitionr   rX   KeyErrorloggerwarningr   r   default_domainstandard_domainr   )r=   r3   r5   r6   domain_name_rS   domainelementr   r   s             r0   rX   zsphinx_domains.directive'  s;    (--//.  #1#;#;C#@#@ KD'k2 !**400&"B;& '	  Q Q Qr">??PPPPPQ "D!2AN)(22488&"B;& ,.88>>B;ww  (KKK   A 2BBrB   rC   rD   rE   r   r   c                   |                                 }d|v r{|                    d          \  }}}	 | j        |         }|                    |          }	|	|	g fS nc# t          $ r+ t
                              t          d          |           Y n/w xY w|}| j        j	        }
|
|
                    |          }	|	|	g fS | j        j
                            |          }	|	|	g fS t                                          ||||          S )z9Lookup a role, given its name which can include a domain.r   Nzunknown role name: %s)r   r   r   r_   r   r   r   r   r   r   r   r   )r=   rB   r5   rC   rE   r   r   rS   r   r   r   r   s              r0   r_   zsphinx_domains.roleJ  s7    OO%%	)#,#6#6s#;#; KD'k2 !++d++&"B;& '	  G G Gr"9::IFFFFFG D!2AN)(--d33&"B;& ,.33D99B;ww||IIIIr   )r   r#   r8   rZ   r   r   )r*   r+   r,   r   r   rX   r_   __classcell__r   s   @r0   r   r     s              
!L !L !L !L !L !LF"J "J "J "J "J "J "J "J "J "Jr/   r   c                      e Zd ZddZdS )WarningStreamtextr4   r8   rZ   c                f   t                               |          }|s1t                              |                    d          d           d S |                                \  }}}t                               d|                                          }t                              |||d           d S )Nz
r   )type )locationr   )	report_researchr   r   rstripgroupssublog)r=   r   matchedr   r   levelmessages          r0   writezWarningStream.writep  s    ""4(( 	JNN4;;v..ZN@@@@@$+NN$4$4!HdEmmB--4466GJJtWxjJIIIIIr/   N)r   r4   r8   rZ   )r*   r+   r,   r   r.   r/   r0   r   r   o  s.        J J J J J Jr/   r   c                  V     e Zd Zedd            Zej        ej        ddfd fdZ xZ	S )LoggingReporterclstype[LoggingReporter]rE   r   r8   c                R     | |j         |j        |j        |j        |j                  S )zACreate an instance of LoggingReporter from other reporter object.)sourcereport_level
halt_level
debug_flagerror_handler)r   rE   s     r0   from_reporterzLoggingReporter.from_reporter{  s5    
 sO!"
 
 	
r/   Fbackslashreplacer   r4   r   rD   r   debugrT   r   rZ   c                r    t                      }t                                          ||||||           d S )N)r   )r   r   r   )r=   r   r   r   r   r   streamr   s          r0   r   zLoggingReporter.__init__  sF     L*fe= 	 	
 	
 	
 	
 	
r/   )r   r   rE   r   r8   r   )r   r4   r   rD   r   rD   r   rT   r   r4   r8   rZ   )
r*   r+   r,   classmethodr   r   WARNING_LEVELSEVERE_LEVELr   r   r   s   @r0   r   r   z  st        

 

 

 [

 %2"//
 
 
 
 
 
 
 
 
 
 
r/   r   c                  $     e Zd ZdZd fdZ xZS )NullReporterz A dummy reporter; write nothing.r8   rZ   c                N    t                                          ddd           d S )Nr   i     )r   r   )r=   r   s    r0   r   zNullReporter.__init__  s%    S!$$$$$r/   r   )r*   r+   r,   r   r   r   r   s   @r0   r   r     sC        **% % % % % % % % % %r/   r   stateState[list[str]]contentr    c              #     K   	 | j         j        j        }t          g d          }||_        |j        | j         j        _        dV  || j         j        _        dS # || j         j        _        w xY w)z1Switch current source input of state temporarily.N)memorE   get_source_and_liner   input_lines)r   r   gsalstate_machines       r0   switch_source_inputr    sx      7z"6 -9T,B,B$+!2?2S
/ 37
///$
/6666s   AA A,c                  0     e Zd ZdZd
 fdZd fd	Z xZS )SphinxFileOutputz#Better FileOutput class for Sphinx.kwargsr   r8   rZ   c                    |                     dd          | _        |                    dd            t                      j        di | d S )Noverwrite_if_changedFencodingzutf-8r.   )rd   r  
setdefaultr   r   )r=   r  r   s     r0   r   zSphinxFileOutput.__init__  sS    $*JJ/Eu$M$M!*g...""6"""""r/   datar4   c                h   | j         r| j        rd| j        vrz| j        rst          j                            | j                   rOt          | j         | j                  5 }|	                                }d d d            n# 1 swxY w Y   ||k    r|S t                                          |          S )Nb)r	  )destination_path	autoclosemoder  r   pathexistsopenr	  readr   r   )r=   r  fon_diskr   s       r0   r   zSphinxFileOutput.write  s    !		 49$$) %t455 % d+dmDDD #&&((# # # # # # # # # # # # # # # $ww}}T"""s   B  BB)r  r   r8   rZ   )r  r4   r8   r4   )r*   r+   r,   r   r   r   r   r   s   @r0   r  r    sa        --# # # # # #
# # # # # # # # # #r/   r  c                      e Zd ZdZed d            Zed!d            Zd"dZd#dZd$dZ		 d%d&dZ
	 d'dddd(dZddd)dZdS )*SphinxDirectivea  A base class for Sphinx directives.

    This class provides helper methods for Sphinx directives.

    .. versionadded:: 1.8

    .. note:: The subclasses of this class might not work with docutils.
              This class is strongly coupled with Sphinx.
    r8   r#   c                .    | j         j        j        j        S )z[Reference to the :class:`.BuildEnvironment` object.

        .. versionadded:: 1.8
        )r   r6   settingsr   r   s    r0   r   zSphinxDirective.env  s     z"+//r/   r"   c                    | j         j        S )zQReference to the :class:`.Config` object.

        .. versionadded:: 1.8
        r   configr   s    r0   r  zSphinxDirective.config       xr/   tuple[str, int]c                @    | j                             | j                  S )zCGet source and line number.

        .. versionadded:: 3.0
        )r  r   rC   r   s    r0   get_source_infozSphinxDirective.get_source_info  s    
 !55dkBBBr/   rQ   r   rZ   c                H    |                                  \  |_        |_        dS )zOSet source and line number to the node.

        .. versionadded:: 2.1
        Nr!  r   liner=   rQ   s     r0   set_source_infozSphinxDirective.set_source_info  s"    
 "&!5!5!7!7TYYYr/   r4   c                f    |                                  \  }}|r	|r| d| S |r| dS |rd| S dS zNGet current location info for logging.

        .. versionadded:: 4.2
        r   z
<unknown>:r   r!  r=   r   r$  s      r0   get_locationzSphinxDirective.get_location  k    
 ++-- 	&d 	&%%t%%% 	 <<< 	'&&&&rr/   Fallow_section_headingsrT   
list[Node]c                F    t          | j        | j        | j        |          S )a  Parse the directive's content into nodes.

        :param allow_section_headings:
            Are titles (sections) allowed in the directive's content?
            Note that this option bypasses Docutils' usual checks on
            doctree structure, and misuse of this option can lead to
            an incoherent doctree. In Docutils, section nodes should
            only be children of ``Structural`` nodes, which includes
            ``document``, ``section``, and ``sidebar`` nodes.

        .. versionadded:: 7.4
        offsetr-  )r   r   r   content_offset)r=   r-  s     r0   parse_content_to_nodesz&SphinxDirective.parse_content_to_nodes  s.     %JL&#9	
 
 
 	
r/   r   r0  r   r1  rD   c              L    |dk    r| j         }t          | j        |||          S )a  Parse *text* into nodes.

        :param text:
            Text, in string form. ``StringList`` is also accepted.
        :param allow_section_headings:
            Are titles (sections) allowed in *text*?
            Note that this option bypasses Docutils' usual checks on
            doctree structure, and misuse of this option can lead to
            an incoherent doctree. In Docutils, section nodes should
            only be children of ``Structural`` nodes, which includes
            ``document``, ``section``, and ``sidebar`` nodes.
        :param offset:
            The offset of the content.

        .. versionadded:: 7.4
        r4  r0  )r2  r   r   )r=   r   r1  r-  s       r0   parse_text_to_nodesz#SphinxDirective.parse_text_to_nodes  s:    0 R<<(F$J#9	
 
 
 	
r/   )rC   rC   'tuple[list[Node], list[system_message]]c               R    |dk    r| j         }| j                            ||          S )a  Parse *text* as inline elements.

        :param text:
            The text to parse, which should be a single line or paragraph.
            This cannot contain any structural elements (headings,
            transitions, directives, etc).
        :param lineno:
            The line number where the interpreted text begins.
        :returns:
            A list of nodes (text and inline elements) and a list of system_messages.

        .. versionadded:: 7.4
        r4  )rC   r   inline_text)r=   r   rC   s      r0   parse_inlinezSphinxDirective.parse_inline6  s,      R<<[Fz%%dF333r/   Nr8   r#   r8   r"   )r8   r  rQ   r   r8   rZ   r8   r4   )F)r-  rT   r8   r.  )r   )r   r4   r1  rD   r-  rT   r8   r.  )r   r4   rC   rD   r8   r7  )r*   r+   r,   r   propertyr   r  r!  r&  r+  r3  r6  r:  r.   r/   r0   r  r    s         0 0 0 X0    XC C C C8 8 8 8    .3
 
 
 
 
0 

 ',
 
 
 
 
 
D +-4 4 4 4 4 4 4 4r/   r  c                      e Zd ZU dZded<   ded<   ded<   ded<   ded	<   d
ed<   ded<   	 	 d!d"dZd#dZed$d            Zed%d            Z	d&d'dZ
d&d(dZd)d ZdS )*
SphinxRolezA base class for Sphinx roles.

    This class provides helper methods for Sphinx roles.

    .. versionadded:: 2.0

    .. note:: The subclasses of this class might not work with docutils.
              This class is strongly coupled with Sphinx.
    r4   rS   rawtextr   rD   rC   r   inlinerzdict[str, Any]optionsSequence[str]r   Nr.   dict[str, Any] | Noner8   r7  c                n   || _         t          |          | _        || _        || _        ||ni | _        || _        |r|                                | _        nK| j	        j
        j        | _        | j        s| j	        j        j        | _        | j        sd}t          |          |                                 S )Nzcannot determine default role!)rB  r   r   rC   rC  rD  r   r   rS   r   r   default_roler  r   run)	r=   rS   rB  r   rC   rC  rD  r   msgs	            r0   r>   zSphinxRole.__call__d  s     TNN	")"5ww2  	'

DII1>DI9 9 HO8	9 '6!#&&&xxzzr/   c                    t           r;   )NotImplementedErrorr   s    r0   rI  zSphinxRole.run  s    !!r/   r#   c                .    | j         j        j        j        S )z[Reference to the :class:`.BuildEnvironment` object.

        .. versionadded:: 2.0
        )rC  r6   r  r   r   s    r0   r   zSphinxRole.env  s     |$-11r/   r"   c                    | j         j        S )zQReference to the :class:`.Config` object.

        .. versionadded:: 2.0
        r  r   s    r0   r  zSphinxRole.config  r  r/   
int | Noner  c                R    || j         }| j        j                            |          S r;   )rC   rC  rE   r   )r=   rC   s     r0   r!  zSphinxRole.get_source_info  s'    >[F|$88@@@r/   rQ   r   rZ   c                J    |                      |          \  |_        |_        d S r;   r#  )r=   rQ   rC   s      r0   r&  zSphinxRole.set_source_info  s"    !%!5!5f!=!=TYYYr/   c                f    |                                  \  }}|r	|r| d| S |r| dS |rd| S dS r(  r)  r*  s      r0   r+  zSphinxRole.get_location  r,  r/   Nr.   rS   r4   rB  r4   r   r4   rC   rD   rC  r   rD  rF  r   rE  r8   r7  )r8   r7  r;  r<  r;   )rC   rO  r8   r  )rQ   r   rC   rO  r8   rZ   r>  )r*   r+   r,   r   r-   r>   rI  r?  r   r  r!  r&  r+  r.   r/   r0   rA  rA  K  s.          IIILLLIIIKKK   *.!#    <" " " " 2 2 2 X2    XA A A A A> > > > >     r/   rA  c                       e Zd ZU dZded<   ded<   ded<   ded<    ej        dej                  Z	 	 dd fdZ	 xZ
S )ReferenceRolea  A base class for reference roles.

    The reference roles can accept ``link title <target>`` style as a text for
    the role.  The parsed result; link title and target will be stored to
    ``self.title`` and ``self.target``.

    .. versionadded:: 2.0
    rT   has_explicit_titledisabledr4   titletargetz^(.+?)\s*(?<!\x00)<(.*?)>$Nr.   rS   rB  r   rC   rD   rC  r   rD  rF  r   rE  r8   r7  c           	        |i }|                     d          | _        | j                            |          }|rVd| _        t          |                    d                    | _        t          |                    d                    | _        n/d| _        t          |          | _        t          |          | _        t                      
                    |||||||          S )N!T      F)
startswithrX  explicit_title_rematchrW  r   grouprY  rZ  r   r>   )
r=   rS   rB  r   rC   rC  rD  r   r   r   s
            r0   r>   zReferenceRole.__call__  s     ?G ,,(..t44 	)&*D#!'--"2"233DJ"7==#3#344DKK&+D#!$DJ"4..DKwwgtVWgwWWWr/   rS  rT  )r*   r+   r,   r   r-   recompileDOTALLr`  r>   r   r   s   @r0   rV  rV    s           NNNJJJKKK #
#@")LL *.!#X X X X X X X X X X Xr/   rV  c                  D     e Zd ZdZd fdZd fdZd fdZddZ xZS )SphinxTranslatora  A base class for Sphinx translators.

    This class adds a support for visitor/departure method for super node class
    if visitor/departure method for node class is not found.

    It also provides helper methods for Sphinx translators.

    .. versionadded:: 2.0

    .. note:: The subclasses of this class might not work with docutils.
              This class is strongly coupled with Sphinx.
    r6   r7   builderr!   r8   rZ   c                    t                                          |           || _        |j        | _        |j        | _        |j        j        | _        d S r;   )r   r   rh  r  r  r   r   _domains)r=   r6   rh  r   s      r0   r   zSphinxTranslator.__init__  sE    """n )+r/   rQ   r   c                    |j         j        D ]+}t          | d|j        z  d          }|r ||            dS ,t	                                          |           dS )zDispatch node to appropriate visitor method.
        The priority of visitor method is:

        1. ``self.visit_{node_class}()``
        2. ``self.visit_{super_node_class}()``
        3. ``self.unknown_visit()``
        zvisit_%sN)r   __mro__getattrr*   r   dispatch_visitr=   rQ   
node_classmethodr   s       r0   rn  zSphinxTranslator.dispatch_visit  ss     .0 	) 	)JT:
0C#CTJJF t GG""4(((((r/   c                    |j         j        D ]+}t          | d|j        z  d          }|r ||            dS ,t	                                          |           dS )zDispatch node to appropriate departure method.
        The priority of departure method is:

        1. ``self.depart_{node_class}()``
        2. ``self.depart_{super_node_class}()``
        3. ``self.unknown_departure()``
        z	depart_%sN)r   rl  rm  r*   r   dispatch_departurero  s       r0   rs  z#SphinxTranslator.dispatch_departure  ss     .0 	- 	-JT;1D#DdKKF t GG&&t,,,,,r/   c                Z    t                               t          d          ||           d S )Nzunknown node type: %r)r   )r   r   r   r%  s     r0   unknown_visitzSphinxTranslator.unknown_visit  s)    r122D4HHHHHr/   )r6   r7   rh  r!   r8   rZ   r=  )	r*   r+   r,   r   r   rn  rs  ru  r   r   s   @r0   rg  rg    s         , , , , , ,) ) ) ) ) ) - - - - - - I I I I I I I Ir/   rg  ztuple[Values, Reporter]__document_cache__source_pathr  r   r7   c                   	 t           \  }}nB# t          $ r5 t          j                            |           }|j        |j        fxa \  }}Y nw xY w|t          |          }t          j	        |||           }|
                    | d           |S )a&  Return a new empty document object.  This is an alternative of docutils'.

    This is a simple wrapper for ``docutils.utils.new_document()``.  It
    caches the result of docutils' and use it on second call for instantiation.
    This makes an instantiation of document nodes much faster.
    N)r   r4  )rv  	NameErrorr   utilsnew_documentr  rE   r   r   r6   note_source)rw  r  cached_settingsrE   docr6   s         r0   r{  r{    s    T$6! T T Tn))+669<s|9SS6_hhhT (( ~hEEEHb)))Os   
 <AA)r8   rJ   )rS   r4   r8   rT   )rS   r4   rX   rY   r8   rZ   )rS   r4   r_   r$   r8   rZ   )rS   r4   r8   rZ   )rQ   rf   r8   rT   )rQ   rf   r8   rZ   )r   r   r8   rJ   r;   )r   r   r   r    r8   rJ   )rw  r4   r  r   r8   r7   )br   
__future__r   r   rc  
contextlibr   r   pathlibr   typingr   r   r   docutils.ior	   docutils.parsers.rstr
   r   r   docutils.statemachiner   docutils.utilsr   r   sphinx.errorsr   sphinx.localer   sphinx.utilr   sphinx.util.parsingr   	getLoggerr*   r   rd  r   collections.abcr   r   typesr   r   r   r   docutils.frontendr   docutils.nodesr   r   r   docutils.parsers.rst.statesr   r   r    sphinx.buildersr!   sphinx.configr"   sphinx.environmentr#   sphinx.util.typingr$   r&   r2   rA   setrI   r-   rR   rW   r\   r^   rb   re   rl   rp   rO   r|   r   r   r   r   	Exceptionr   r   r   r   r   r  r  r  rA  rV  NodeVisitorrg  r{  r.   r/   r0   <module>r     s   % % % " " " " " " 				 				 % % % % % %                                " " " " " " = = = = = = = = = = . . . . . . - - - - - - - - % % % % % %             5 5 5 5 5 5		8	$	$BJH 	  %C22222222////////$$$$$$$$((((((<<<<<<<<<<33333377777777''''''$$$$$$333333//////( ( ( ( (( ( ( (
F F F F F F F FC C C C C8 C C C (+suu  , , , , + + + + * * * *
3 3 3 3       
* * * *! ! ! !
G G G G
# # # #	D 	D 	D 	D 7 7 7 7* C C C C2 ; ; ; ;     5
 5
 5
 5
 5
 5
 5
 5
p	 	 	 	 	 	 	 	OJ OJ OJ OJ OJ) OJ OJ OJdJ J J J J J J J
 
 
 
 
h 
 
 
8% % % % %8 % % % 7 7 7 7"# # # # #z # # #2@4 @4 @4 @4 @4i @4 @4 @4F` ` ` ` ` ` ` `F.X .X .X .X .XJ .X .X .Xb6I 6I 6I 6I 6Iu( 6I 6I 6Iv , + + +      r/   