
    -PhEX                    0   U d Z ddlmZ ddl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 ddlmZ ddlmZmZ ddlmZ dd	lmZmZ er.dd
lmZ ddlmZmZ ddlmZmZmZmZ ddlm Z  ddl!m"Z" ddl#m$Z$m%Z% ej&        e
j'        ej(        ej&        ej(        ej(        ej&        e
j)        dZ* G d de          Z+ G d de+          Z, G d de          Z- G d de          Z. G d de          Z/ G d de          Z0dFd Z1 G d! d"e          Z2 G d# d$e2          Z3 G d% d&e          Z4 G d' d(e          Z5 G d) d*e          Z6 G d+ d,e          Z7	 	 dGdHd:Z8ej9        j:        j;        j<        ej9        j:        j;        j=        d;e8_>         e+ej?        <           e,d=>           e-             e.             e/             e0             e2             e3             e4             e4             e5             e6             e7            d?Z@d@eAdA<   dIdEZBdS )Jz#Handlers for additional ReST roles.    )annotationsN)TYPE_CHECKING)nodesutils)addnodes)___)ws_re)ReferenceRole
SphinxRole)Sequence)AnyFinal)ElementNodeTextElementsystem_message)Sphinx)BuildEnvironment)ExtensionMetadataRoleFunction)commanddfn
mailheadermakevarmimetype	newsgroupprogramregexpc                       e Zd ZU dZej        Zded<   ej	        Z
ded<   	 	 	 	 	 d%d& fdZd'dZd(dZd(dZd(dZd)dZd*d$Z xZS )+XRefRolea<  A generic cross-referencing role.  To create a callable that can be used as
    a role function, create an instance of this class.

    The general features of this role are:

    * Automatic creation of a reference and a content node.
    * Optional separation of title and target with `title <target>`.
    * The implementation is a class rather than a function to make
      customization easier.

    Customization can be done in two ways:

    * Supplying constructor parameters:
      * `fix_parens` to normalize parentheses (strip from target, and add to
        title if configured)
      * `lowercase` to lowercase the target
      * `nodeclass` and `innernodeclass` select the node classes for
        the reference and the content node

    * Subclassing and overwriting `process_link()` and/or `result_nodes()`.
    ztype[Element]	nodeclassztype[TextElement]innernodeclassFN
fix_parensbool	lowercasetype[Element] | Nonetype[TextElement] | Nonewarn_danglingreturnNonec                    || _         || _        || _        ||| _        ||| _        t                                                       d S N)r$   r&   r)   r"   r#   super__init__)selfr$   r&   r"   r#   r)   	__class__s         L/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinx/roles.pyr/   zXRefRole.__init__F   sR     %"* &DN%"0D    titlestrtargettuple[str, str]c                    | j         s<| j        j        r|                    d          s|dz  }n|                    d          }|                    d          }||fS )Nz())has_explicit_titleconfigadd_function_parenthesesendswithremovesuffix)r0   r4   r6   s      r2   update_title_and_targetz XRefRole.update_title_and_targetX   sj    & 	1{3 1~~d++ "TME **400$$T**f}r3   'tuple[list[Node], list[system_message]]c                D   d| j         vr#d| j         c| _        | _        d| j        g| _        nF| j                             dd          \  | _        | _        d| j        | j         d| j         g| _        | j        r|                                 S |                                 S )N: xref   -)name	refdomainreftypeclassessplitdisabledcreate_non_xref_nodecreate_xref_node)r0   s    r2   runzXRefRole.rune   s    di+-ty(DNDL"DL1DLL+/9??3+B+B(DNDL"DNt~4V4V4V4VWDL= 	+,,...((***r3   c                &   t          j        | j        dd                    }| j        r d| _        |                     |d          \  }}|                     | j        || j                  }| 	                    | j
        j        | j        |d          S )NrD   FrB   rI   is_ref)r   unescapetextr$   r9   r>   r#   rawtextrI   result_nodesinlinerdocumentenv)r0   rT   r6   nodes       r2   rL   zXRefRole.create_non_xref_noder   s    ~dim,,? 	B&+D#77bAALD&""4<t|"LL  !6$u UUUr3   c                    | j         }| j        }| j        r|                                }| j        r|                     ||          \  }}| j        j        | j        | j	        | j
        | j        d} | j        | j        fi |}|                     |           |                     | j        || j
        ||          \  }}||d<   ||                     | j        || j                  z  }|                     | j        j        | j        |d          S )N)refdocrG   rH   refexplicitrefwarn	reftargetrP   TrQ   )r6   r4   r&   lowerr$   r>   rY   docnamerG   rH   r9   r)   r"   rU   set_source_infoprocess_linkr#   rI   rV   rW   rX   )r0   r6   r4   optionsrefnodes        r2   rM   zXRefRole.create_xref_node{   s'   
> 	$\\^^F? 	H 88GGME6 h&|2)
 
 !$.9999W%%% ))Hgt6v
 
v  &4&&t|UDL&QQQ  !6'RV WWWr3   rY   r   re   r   r9   c                0    |t          j        d|          fS )zCalled after parsing title and target text, and creating the
        reference node (given in *refnode*).  This method can alter the
        reference node and must return a new (or the same) ``(title, target)``
        tuple.
         )r
   sub)r0   rY   re   r9   r4   r6   s         r2   rc   zXRefRole.process_link   s     eiV,,,,r3   rX   nodes.documentrZ   rR   c                    |gg fS )a(  Called before returning the finished nodes.  *node* is the reference
        node if one was created (*is_ref* is then true), else the content node.
        This method can add other nodes and must return a ``(nodes, messages)``
        tuple (the usual return value of a role function).
         )r0   rX   rY   rZ   rR   s        r2   rV   zXRefRole.result_nodes   s     vrzr3   )FFNNF)r$   r%   r&   r%   r"   r'   r#   r(   r)   r%   r*   r+   )r4   r5   r6   r5   r*   r7   r*   r?   rY   r   re   r   r9   r%   r4   r5   r6   r5   r*   r7   )
rX   ri   rY   r   rZ   r   rR   r%   r*   r?   )__name__
__module____qualname____doc__r   pending_xrefr"   __annotations__r   literalr#   r/   r>   rN   rL   rM   rc   rV   __classcell__r1   s   @r2   r!   r!   ,   s         ,  (4I4444(-N5555 !*.37#      $   + + + +V V V VX X X X<- - - -       r3   r!   c                        e Zd Zd fdZ xZS )AnyXRefRolerY   r   re   r   r9   r%   r4   r5   r6   r*   r7   c                    t                                          |||||          }|j                            |j                   |S r-   )r.   rc   
attributesupdateref_context)r0   rY   re   r9   r4   r6   resultr1   s          r2   rc   zAnyXRefRole.process_link   sC     %%c74FvVV!!#/222r3   rm   )rn   ro   rp   rc   ru   rv   s   @r2   rx   rx      s=                 r3   rx   c                  .    e Zd ZU dZded<   d
dZddZd	S )CVEz%https://www.cve.org/CVERecord?id=CVE-r   	_BASE_URLr*   r?   c                   d| j                             d           }dt          d          | j        z  |dd fg}t	          j        |          }t          j        dd|g          }| j        j        	                    |           	 | 
                                }t          j        ddd|d	g
          }| j        r#|t          j        | j        | j                  z  }n"d| j         }|t          j        ||          z  }nw# t          $ rj | j        j                            t%          d          | j        z  | j                  }| j                            | j        | j        |          }	|	g|gfcY S w xY w|||gg fS )Nindex-indexsinglez,Common Vulnerabilities and Exposures; CVE %srB   entriesidsFcveinternalrefurirI   zCVE zinvalid CVE number %slinerY   new_serialnor   r6   r   r   r   rW   rX   note_explicit_target	build_uri	referencer9   strongr4   
ValueErrorreportererrorr	   linenoproblematicrU   
r0   	target_idr   r   r6   r   r   r4   msgprbs
             r2   rN   zCVE.run   s   =TX227;;==	 @AADKO
 w///b"9+666226:::	 ^^%%FBvw  I & 8U\$*djAAA		+tz++U\%777	 	  	  	 ,'--*++dk9 .  C ,**4<sKKC53%<	  vy)2--   A:D A1E76E7r5   c                    | j                             dd          }t          |          dk    rt          j         |d          d|d          S t          j         |d          S N#rD      r   )r6   rJ   lenr   r   r0   rets     r2   r   zCVE.build_uri   sb    kQ''s88q==m6SV66c!f666-)Q)))r3   Nrl   r*   r5   rn   ro   rp   r   rs   rN   r   rk   r3   r2   r   r      sP         >I>>>>!. !. !. !.F* * * * * *r3   r   c                  .    e Zd ZU dZded<   d
dZddZd	S )CWEz'https://cwe.mitre.org/data/definitions/r   r   r*   r?   c                   d| j                             d           }dt          d          | j        z  |dd fg}t	          j        |          }t          j        dd|g          }| j        j        	                    |           	 | 
                                }t          j        ddd|d	g
          }| j        r#|t          j        | j        | j                  z  }n"d| j         }|t          j        ||          z  }nw# t          $ rj | j        j                            t%          d          | j        z  | j                  }| j                            | j        | j        |          }	|	g|gfcY S w xY w|||gg fS )Nr   r   r   z#Common Weakness Enumeration; CWE %srB   r   r   Fcwer   zCWE zinvalid CWE number %sr   r   r   s
             r2   rN   zCWE.run   s   =TX227;;==	 7884;F
 w///b"9+666226:::	 ^^%%FBvw  I & 8U\$*djAAA		+tz++U\%777	 	  	  	 ,'--*++dk9 .  C ,**4<sKKC53%<	  vy)2--r   r5   c                    | j                             dd          }t          |          dk    r,t          j         t          |d                    d|d          S t          j         t          |d                    dS )Nr   rD   r   r   z.html#z.html)r6   rJ   r   r   r   intr   s     r2   r   zCWE.build_uri  sq    kQ''s88q==m@SQ[[@@A@@@-3SV3333r3   Nrl   r   r   rk   r3   r2   r   r      sP         @I@@@@!. !. !. !.F4 4 4 4 4 4r3   r   c                      e Zd ZddZddZdS )	PEPr*   r?   c                   d| j                             d          z  }dt          d          | j        z  |dd fg}t	          j        |          }t          j        dd|g          }| j        j        	                    |           	 | 
                                }t          j        ddd|d	g
          }| j        r#|t          j        | j        | j                  z  }n"d| j        z   }|t          j        ||          z  }nw# t          $ rj | j        j                            t%          d          | j        z  | j                  }| j                            | j        | j        |          }	|	g|gfcY S w xY w|||gg fS )Nindex-%sr   r   z$Python Enhancement Proposals; PEP %srB   r   r   Fpepr   zPEP zinvalid PEP number %sr   r   r   s
             r2   rN   zPEP.run!  s   !6!6w!?!??	 899DKG
 w///b"9+666226:::	 ^^%%FBvw  I & 8U\$*djAAA		+U\%777	 	  	  	 ,'--*++dk9 .  C ,**4<sKKC53%<	  vy)2--r   r5   c                   | j         j        j        j        }| j                            dd          }t          |          dk    r#|dt          |d                   |d         fz  z   S |dt          |d                   z  z   S )Nr   rD   r   zpep-%04d/#%sr   z	pep-%04d/)rW   rX   settingspep_base_urlr6   rJ   r   r   r0   base_urlr   s      r2   r   zPEP.build_uriD  su    <(1>kQ''s88q==nCFSV/DDDDkCAKK777r3   Nrl   r   rn   ro   rp   rN   r   rk   r3   r2   r   r      s=        !. !. !. !.F8 8 8 8 8 8r3   r   c                      e Zd ZddZddZdS )	RFCr*   r?   c                   d| j                             d          z  }t          | j                  }dd| |dd fg}t	          j        |          }t          j        dd|g          }| j        j        	                    |           	 | 
                                }t          j        ddd|d	g
          }| j        r#|t          j        | j        | j                  z  }n|}|t          j        ||          z  }nw# t          $ rj | j        j                            t%          d          | j        z  | j                  }	| j                            | j        | j        |	          }
|
g|	gfcY S w xY w|||gg fS )Nr   r   r   zRFC; rB   r   r   Frfcr   zinvalid RFC number %sr   )rY   r   _format_rfc_targetr6   r   r   r   rW   rX   r   r   r   r9   r   r4   r   r   r   r	   r   r   rU   )r0   r   formatted_targetr   r   r6   r   r   r4   r   r   s              r2   rN   zRFC.runN  s   !6!6w!?!??	-dk::8&688)RNOw///b"9+666226:::	 ^^%%FBvw  I & 8U\$*djAAA		(U\%777	 	  	  	 ,'--*++dk9 .  C ,**4<sKKC53%<	  vy)2--s   
A2C= =A1E10E1r5   c                6   | j         j        j        j        }| j                            dd          }t          |          dk    r1|| j         j        t          |d                   z  z   dz   |d         z   S || j         j        t          |d                   z  z   S r   )	rW   rX   r   rfc_base_urlr6   rJ   r   rfc_urlr   r   s      r2   r   zRFC.build_urij  s    <(1>kQ''s88q==dl2SQ[[@@3FQOOdl2SQ[[@@@r3   Nrl   r   r   rk   r3   r2   r   r   M  sB        . . . .8A A A A A Ar3   r   r6   r5   r*   c                   |                      d          \  }}}|rV|                     d          \  }}}|dv r9|rd| d|                                 d| S d| d|                                 S d|  S )zTakes an RFC number with an optional anchor (like ``123#section-2.5.3``)
    and attempts to produce a human-friendly title for it.

    We have a set of known anchors that we format nicely,
    everything else we leave alone.
    r   rE   >   pagesectionappendixzRFC rg   )	partitionr4   )r6   numberr   anchorfirst	remainings         r2   r   r   s  s     ((--FAv 3$..s33q)333 CBfBBu{{}}BByBBB2&225;;==222&??r3   c                  6    e Zd Z ej        d          ZddZdS )GUILabelz(?<!&)&(?![&\s])r*   r?   c                   t          j        | j        | j        g          }| j                            | j                  }|t          j        |                    d                    z  }|D ]o}|	                    dd          }t          j        |d                   }t          j        dd|dg          }||z  }|t          j        |dd                    z  }p|gg fS )	N)rU   rI   r   z&&&rB   acceleratorrP   rD   )
r   inlinerU   rF   amp_rerJ   rT   Textpopreplace)r0   rZ   spansspanletterr   s         r2   rN   zGUILabel.run  s    |DL49+FFF!!$),,
599Q<<((( 	) 	)D<<c**DZQ((F,r2vOOOKKDEJtABBx(((DDvrzr3   Nrl   )rn   ro   rp   recompiler   rN   rk   r3   r2   r   r     s:        RZ+,,F     r3   r   c                  $     e Zd ZdZd fdZ xZS )MenuSelectionu   ‣r*   r?   c                    | j                             d| j                  | _         t                                                      S )Nz-->)rT   r   BULLET_CHARACTERr.   rN   )r0   r1   s    r2   rN   zMenuSelection.run  s1    I%%eT-BCC	ww{{}}r3   rl   )rn   ro   rp   r   rN   ru   rv   s   @r2   r   r     sC        .         r3   r   c                  >    e Zd Z ej        d          Zd
dZddZd	S )EmphasizedLiteralz(\\\\|\\{|\\}|{|})r*   r?   c                    |                      | j                  }t          j        | j        dg|R | j                                        | j        gd}|gg fS )NrB   )rolerI   )parserT   r   rt   rU   rF   r`   )r0   childrenrZ   s      r2   rN   zEmphasizedLiteral.run  sg    ::di((}L"
'
 
.2ioo.?.?$)
 
 
 vrzr3   rT   r5   
list[Node]c                   g }dg}| j                             |          D ]}|dk    r|dxx         dz  cc<   |dk    rFt          |          dk    r|d         dk    r|dxx         dz  cc<   P|                    d           f|d	k    rt          |          d
k    r|d         dk    rt          |d                   dk    rn|d         r-|                    t          j        |d                              |                    t          j        |d         |d                              dg}|                    d	           d                    |          g}?|dk    r|dxx         dz  cc<   W|dk    r|dxx         d	z  cc<   o|dxx         |z  cc<   d                    |          r<d                    |          }|                    t          j        |                     |S )NrB   z\\\{r   )r   rB   }   rD   r   z\{z\})		parens_rerJ   r   extendappendr   r   emphasisjoin)r0   rT   r}   stackparts        r2   r   zEmphasizedLiteral.parse  s   N((.. 	" 	"Dv~~b			T!				u::??uRyC'7'7"III$IIII LL++++u::??uQx33uQx==1;L;LQx <ejq&:&:;;;MM%.q58"D"DEEEDEE LL%%%WWU^^,EEb			S 				b			S 				b			T!				775>> 	,775>>DMM%*T**+++r3   Nrl   )rT   r5   r*   r   )rn   ro   rp   r   r   r   rN   r   rk   r3   r2   r   r     sN        
011I   $ $ $ $ $ $r3   r   c                  B    e Zd Z ej        dej                  ZddZdS )Abbreviationz	\((.*)\)$r*   r?   c                R   | j                                         }| j                            | j                  }|rL| j        d |                                                                         }|                    d          |d<   n| j        }t          j	        | j
        |fi |gg fS )NrD   explanation)rd   copyabbr_researchrT   startstripgroupr   abbreviationrU   )r0   rd   matchedrT   s       r2   rN   zAbbreviation.run  s    ,##%%,%%di00 	9.w}}./5577D%,]]1%5%5GM""9D"4<AAAABBFFr3   Nrl   )rn   ro   rp   r   r   DOTALLr   rN   rk   r3   r2   r   r     sC        bjry11G	G 	G 	G 	G 	G 	Gr3   r   c                  ^    e Zd ZU dZ ej        d          Zded<   ddZe	dd            Z
dS )Keyboardz~Implement the :kbd: role.

    Split words in the text by separator or whitespace,
    but keep multi-word keys together.
    z(?<=.)([\-+^]| +)(?=.)r   _patternr*   r?   c                   dg}d| j         v r |                    | j         d                    | j                            | j                  }t          |          dk    s|                     |          r$t          j        | j	        | j        |          gg fS g }|r|                     |          r%d
                    |d d                   }g |d d<   n|                    d          }|                    t          j        |||                     	 |                    d          }|                    t          j        |                     n# t          $ r Y nw xY w||g fS )NkbdrI   rD   rP   rB   r   r   )rd   r   r  rJ   rT   r   _is_multi_word_keyr   rt   rU   r   r   r   r   
IndexError)r0   rI   partscompoundkeyseps         r2   rN   zKeyboard.run  sr   '$$NN4<	2333##DI..u::??d55e<<?M$,	7KKKLbPP! 	1&&u-- #ggeBQBi((bqb		iillOOEM#sGDDDEEE1iill 
30000      	1 |s   E 
E E r  	list[str]r%   c                    t          |           dk    s| d                                         sdS | d                                         | d                                         f}|t          h d          v S )Nr   rD   Fr   >   numlocksysrqbackspacecapsr  r   upr   downscrollr  )r   isspacer`   	frozenset)r  rF   s     r2   r  zKeyboard._is_multi_word_key  sx    u::??%("2"2"4"4?5Qx~~q!1!11y "
 "
 "
    	r3   Nrl   )r  r  r*   r%   )rn   ro   rp   rq   r   r   r  rs   rN   staticmethodr  rk   r3   r2   r  r    st           !bj!:;;H;;;;   6    \  r3   r  c                  6    e Zd Z ej        d          ZddZdS )Manpagez5^(?P<path>(?P<page>.+)[(.](?P<section>[1-9]\w*)?\)?)$r*   r?   c                   t          j        d| j                  }| j                            |          x}r|                                }n||dd}| j        r| j        dd          n| j        }| j        sJ| j        j	        r>| j        j	        
                    |          }t          j        d|| j        g|          }nt          j        |          }t          j        | j        d|fd| j        gi|}|gg fS )Nrg   rB   )pathr   r   rD   )rI   r   rI   )r
   rh   r6   _manpage_rematch	groupdictrK   r4   r:   manpages_url
format_mapr   r   rF   r   r   manpagerU   )r0   r*  minforT   uriinnerrZ   s           r2   rN   zManpage.run  s    )C-- &&w///1 	E;;==DD#WDDD "&>tz!""~~DJ} 	%!9 	%+*55d;;COBtyk#NNNEEJt$$Eb%UU$)UPTUUvrzr3   Nrl   )rn   ro   rp   r   r   r%  rN   rk   r3   r2   r"  r"    s:        "*UVVK     r3   r"  rk   rF   rU   rT   r   r   rW   #docutils.parsers.rst.states.Inlinerrd   dict[str, Any] | NonecontentSequence[str]r?   c                   |i }|                                 }t          j        j        j                            |           |                    dd          }dg}|r|                    d           d|v r|                    |d                    |r||vr|                    |           t          j
        ||||          }	|	gg fS )NlanguagerB   code	highlightrI   )rI   r4  )r   docutilsparsersrstrolesset_classesgetr   r   r   rt   )
rF   rU   rT   r   rW   rd   r1  r4  rI   rZ   s
             r2   	code_roler=  B  s     llnnG**7333{{:r**HhG ${###Gwy)*** !HG++x   =$(KKKD62:r3   )classr4  )r"   T)r)   )downloadanyr   r   r   r   guilabelmenuselectionfilesampabbrr  r*  zdict[str, RoleFunction]specific_docrolesappr   r   c                   ddl m} t                                          D ]K\  }}|                    ||          }|                    ||d|gi          }|                    ||           Lt                                          D ]\  }}|                    ||           |                    dt                     ddddS )Nr   )r:  rI   r5  builtinT)versionparallel_read_safeparallel_write_safe)
docutils.parsers.rstr:  generic_docrolesitemsGenericRole
CustomRoleregister_local_rolerF  register_canonical_roler=  )rG  r:  rolenamer"   genericr   funcs          r2   setuprW  z  s    ******/5577 2 2)##Hi88'Iz3JKK!!(D1111+1133 2 2$!!(D1111 
!!&)444 "#  r3   )r6   r5   r*   r5   )Nrk   )rF   r5   rU   r5   rT   r5   r   r   rW   r/  rd   r0  r1  r2  r*   r?   )rG  r   r*   r   )Crq   
__future__r   r   typingr   docutils.parsers.rst.directivesr7  docutils.parsers.rst.rolesdocutils.parsers.rst.statesr   r   sphinxr   sphinx.localer   r	   sphinx.utilr
   sphinx.util.docutilsr   r   collections.abcr   r   r   docutils.nodesr   r   r   r   sphinx.applicationr   sphinx.environmentr   sphinx.util.typingr   r   literal_strongr   literal_emphasisrt   rN  r!   rx   r   r   r   r   r   r   r   r   r   r  r"  r=  r8  r9  
directivesclass_option	unchangedrd   download_referencerF  rs   rW  rk   r3   r2   <module>rl     s   ) ) ) " " " " " " 				             & & & & ! ! ! ! " " " " ! ! ! ! ! ! ! !                     : : : : : : : : C((((((!!!!!!!!IIIIIIIIIIII))))))333333BBBBBBBB &>+&)*&m	 	 H H H H H} H H HV    (   ** ** ** ** **- ** ** **Z*4 *4 *4 *4 *4- *4 *4 *4Z*8 *8 *8 *8 *8- *8 *8 *8Z#A #A #A #A #A- #A #A #AL   "    z   $    H   / / / / /
 / / /dG G G G G: G G G2 2 2 2 2z 2 2 2j    m   h &*    : !,9 $/9 	  8#>???;T***355355355355

"]__LNN8::wyy%. .     ,     r3   