o
    Ni@                     @  s  d dl mZ d dlZd dlmZmZ d dl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 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!m"Z"m#Z# d dl$m%Z% d dl&m'Z'm(Z( d dl)m*Z* e	rd dl+m,Z, d dl-m.Z.m/Z/ d dl0m1Z1 d dl2m3Z3m4Z4 e5dZ6e"7e8Z9d5ddZ:G dd de%Z;G d d! d!e%Z<G d"d# d#eZ=G d$d% d%e%Z>G d&d' d'e%Z?G d(d) d)e%Z@G d*d+ d+e%ZAG d,d- d-e%ZBG d.d/ d/ee%Zd6d3d4ZCdS )7    )annotationsN)abspathrelpath)Path)TYPE_CHECKINGAnyClassVarcast)nodes)
directives)BaseAdmonition)Class)Include)StateMachine)addnodes)StandardDomain)___)docname_joinloggingurl_re)SphinxDirective)Matcher	patfilter)explicit_title_re)Sequence)ElementNode)Sphinx)ExtensionMetadata
OptionSpecz
.*[*?\[].*argumentstrreturnintc                 C  s   | sdS t | S )Ni  )r$   )r!    r%   K/home/ubuntu/.local/lib/python3.10/site-packages/sphinx/directives/other.pyint_or_nothing$   s   r'   c                   @  s^   e Zd ZdZdZdZdZdZee	j
e	je	je	je	je	jee	je	jd
Zddd	ZdddZdS )TocTreez
    Directive to notify Sphinx about the hierarchical structure of the docs,
    and to include a table-of-contents like tree in the current document.
    Tr   F)
maxdepthnameclasscaptionglobhiddenincludehiddennumbered
titlesonlyreversedr#   
list[Node]c                 C  s   t  }| jj|d< g |d< g |d< | jdd|d< | jd|d< d| jv |d< d| jv |d< d	| jv |d	< | jd
d|d
< d| jv |d< | | | | tj	dg| jddd}|
| | | |gS )Nparententriesincludefilesr)   r,   r-   r.   r/   r0   r   r1   ztoctree-wrapperr+   r%   )classes)r   toctreeenvdocnameoptionsgetset_source_infoparse_contentr
   compoundappendadd_name)selfsubnodewrappernoder%   r%   r&   runA   s&   



zTocTree.runr9   addnodes.toctreeNonec                   sV  t tj | jj}| jj}|d }| jj  B }|	| t |}t
| jj}| jD ]}|s0q+t|}	t|du}
|rt|r|	s|
st||}t fddt||D }|sftjtd||d |D ]}|	| |d d|f |d | qhq+|	r|	d	}|	d
}|}n| }}d}|D ]}||r||} nqt||}|
s|dkr|d ||f q+||vr|t| j|drtd}d}ntd}d}tj||d||d | j  q+||v r|	| n
tjtd||d |d ||f |d | q+d| jv r)tt |d |d< tt |d |d< dS dS )z_
        Populate ``toctree['entries']`` and ``toctree['includefiles']`` from content.
        r-   Nc                 3  s    | ]	}| vr|V  qd S )Nr%   ).0r;   generated_docnamesr%   r&   	<genexpr>r   s    z(TocTree.parse_content.<locals>.<genexpr>z2toctree glob pattern %r didn't match any documentslocationr5   r6         rC   Fz2toctree contains reference to excluded document %rexcludedz5toctree contains reference to nonexisting document %rnot_readabletoc)typesubtyperN   z%duplicated entry found in toctree: %sr2   )!	frozensetr   _virtual_doc_namesconfigsource_suffixr:   r;   
found_docscopyremover   exclude_patternscontentr   matchr   glob_rer   sortedr   loggerwarningr   rA   groupendswithremovesuffixr"   doc2pathnote_rereadr<   listr2   )rC   r9   suffixescurrent_docnamer-   all_docnamesfrozen_all_docnamesrQ   entryexplicit	url_matchpat_name	doc_namesr;   reftitlesuffixmsgrU   r%   rJ   r&   r?   Z   s   












zTocTree.parse_contentNr#   r3   )r9   rG   r#   rH   )__name__
__module____qualname____doc__has_contentrequired_argumentsoptional_argumentsfinal_argument_whitespacer$   r   	unchangedclass_optionunchanged_requiredflagr'   option_specrF   r?   r%   r%   r%   r&   r(   *   s&    
r(   c                   @  8   e Zd ZU dZdZdZdZdZi Zde	d< dd
dZ
dS )Authorz
    Directive to give the name of the author of the current document
    or section. Shown in the output only if the show_authors option is on.
    FrP   r   TClassVar[OptionSpec]r   r#   r3   c                 C  s   | j jsg S tjdd}t }||7 }| jdkrtd}n| jdkr(td}n| jdkr2td}ntd	}|t|7 }| | j	d
 \}}|
| |g}||7 }|S )NF)translatablesectionauthorzSection author: moduleauthorzModule author: 
codeauthorzCode author: zAuthor: r   )rX   show_authorsr
   	paragraphemphasisr*   r   Textparse_inline	argumentsextend)rC   paraemphtextinodesmessagesretr%   r%   r&   rF      s$   






z
Author.runNrw   rx   ry   rz   r{   r|   r}   r~   r   r   __annotations__rF   r%   r%   r%   r&   r      s   
 r   c                   @  s   e Zd ZdZejZdS )SeeAlsozB
    An admonition mentioning things to look at as reference.
    N)rx   ry   rz   r{   r   seealso
node_classr%   r%   r%   r&   r      s    
r   c                   @  r   )TabularColumnszL
    Directive to give an explicit tabulary column definition to LaTeX.
    FrP   r   Tr   r   r#   r3   c                 C  s&   t  }| jd |d< | | |gS )Nr   spec)r   tabular_col_specr   r>   )rC   noder%   r%   r&   rF      s   
zTabularColumns.runNrw   r   r%   r%   r%   r&   r         
 r   c                   @  r   )Centeredz;
    Directive to create a centered line of bold text.
    FrP   r   Tr   r   r#   r3   c                 C  sB   | j sg S t }| | j d \}}|| |g}||7 }|S )Nr   )r   r   centeredr   r   )rC   rD   r   r   r   r%   r%   r&   rF     s   
zCentered.runNrw   r   r%   r%   r%   r&   r      r   r   c                   @  s8   e Zd ZU dZdZdZdZdZi Zde	d< dd	d
Z
dS )Acksz(
    Directive for a list of names.
    Tr   Fr   r   r#   r3   c                 C  sX   |   }t|dkst|d tjs"tjtd| jj	| j
fd g S tjdg|R  gS )NrP   r   z.. acks content is not a listrM    )parse_content_to_nodeslen
isinstancer
   bullet_listrb   rc   r   r:   r;   linenor   acks)rC   childrenr%   r%   r&   rF     s   zAcks.runNrw   r   r%   r%   r%   r&   r     r   r   c                   @  s<   e Zd ZU dZdZdZdZdZdeiZ	de
d< dd
dZdS )HListz@
    Directive for a list that gets compacted horizontally.
    Tr   Fcolumnsr   r   r#   r3   c                 C  s   | j dd}|  }t|dkst|d tjs)tjt	d| j
j| jfd g S |d }tt||\}}d}t }t||d< t|D ]%}|||k rQ|d n| }	t }
|
|j||	 7 }
|td|
7 }|	}qF|gS )	Nr   rO   rP   r   z.. hlist content is not a listrM   ncolumnsr   )r<   r=   r   r   r   r
   r   rb   rc   r   r:   r;   r   divmodr   hlistr"   ranger   hlistcol)rC   r   r   fulllistnpercolnmoreindexnewnodecolumnendindexr   r%   r%   r&   rF   0  s(   z	HList.runNrw   )rx   ry   rz   r{   r|   r}   r~   r   r$   r   r   rF   r%   r%   r%   r&   r   #  s   
 r   c                   @  s8   e Zd ZU dZdZdZdZdZi Zde	d< dd	d
Z
dS )OnlyzI
    Directive to only include text if the given tag(s) are enabled.
    TrP   r   r   r   r#   r3   c                 C  sF  t  }| jj|_| | | jd |d< | jj}|j}|j}g |_d|_zv| jj	| j
| j|dd |j}|rC|rC|d |vsC| jjsM|gW ||_||_S d}| jj}|r^|d7 }|j}|sU|d8 }|d }t|}	||v rs||}	||	 d }
ttj| jj}t|
D ]}|jr|j}q|| g W ||_||_S ||_||_w )Nr   exprT)match_titlesrP   rO   )r   onlystatedocumentr>   r   memotitle_stylessection_levelnested_parser^   content_offsetr4   r   r   r	   r
   r   r   rA   )rC   r   r   surrounding_title_stylessurrounding_section_levelr   current_depthr4   title_stylenested_depthn_sects_to_raise_ir%   r%   r&   rF   S  s^   



zOnly.runNrw   r   r%   r%   r%   r&   r   H  r   r   c                      s"   e Zd ZdZd fddZ  ZS )r   z
    Like the standard "Include" directive, but interprets absolute paths
    "correctly", i.e. relative to source directory.
    r#   Sequence[Node]c                   s   d fdd} j jjjd	r| j_ jd
 dr) jd
 	dr)t
  S  j  jd
 \}}| jd
<  j | t
  S )Ninclude_lines	list[str]sourcer"   r#   rH   c                   sz   d | d d }ttt| jjd} jj}|g} jjj	d||| |d }|
 | dd   } t j| |S )N
)startinclude-readr   )joinr   r   r   r:   srcdirr;   appeventsemit
splitlinesr   insert_inputstate_machine)r   r   r   pathr;   argrC   r%   r&   _insert_input  s   z"Include.run.<locals>._insert_inputr   r   <>)r   r   r   r"   r#   rH   )r:   r   r   	listenersr=   r   r   r   
startswithre   superrF   
relfn2pathnote_included)rC   r   rel_filenamefilename	__class__r   r&   rF     s    


zInclude.run)r#   r   )rx   ry   rz   r{   rF   __classcell__r%   r%   r   r&   r     s    r   r   r   r   c                 C  s   t dt t dt t dt t dt t dt t dt t dt t dt t d	t t d
t	 t dt
 t dt t dt ddddS )Nr9   r   r   r   r   tabularcolumnsr   r   r   r   includecssclassz	rst-classbuiltinT)versionparallel_read_safeparallel_write_safe)r   register_directiver(   r   r   r   r   r   r   r   r   r   )r   r%   r%   r&   setup  s"   r   )r!   r"   r#   r$   )r   r   r#   r   )D
__future__r   reos.pathr   r   pathlibr   typingr   r   r   r	   docutilsr
   docutils.parsers.rstr   +docutils.parsers.rst.directives.admonitionsr   $docutils.parsers.rst.directives.miscr   r   BaseIncludedocutils.statemachiner   sphinxr   sphinx.domains.stdr   sphinx.localer   r   sphinx.utilr   r   r   sphinx.util.docutilsr   sphinx.util.matchingr   r   sphinx.util.nodesr   collections.abcr   docutils.nodesr   r   sphinx.applicationr   sphinx.util.typingr   r    compiler`   	getLoggerrx   rb   r'   r(   r   r   r   r   r   r   r   r   r%   r%   r%   r&   <module>   sJ    


 #%>2