U
    \ShP9                     @  s  d dl mZ d dl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 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% d dl&m'Z' erd dl(m)Z) e*dZ+e,e-Z.dddddZ/G dd de Z0G dd de Z1G dd deZ2G dd  d e Z3G d!d" d"e Z4G d#d$ d$e Z5G d%d& d&e Z6G d'd( d(e Z7G d)d* d*ee Zd+d,d-d.d/Z8dS )0    )annotationsN)TYPE_CHECKINGAnycast)nodes)ElementNode)
directives)BaseAdmonition)Class)Include)addnodes)VersionChange)___)docname_joinloggingurl_re)SphinxDirective)Matcher	patfilter)explicit_title_re)
OptionSpec)Sphinxz
.*[*?\[].*strint)argumentreturnc                 C  s   | sdS t | S )Ni  )r   )r    r   J/root/rtd-docs/venv/lib/python3.8/site-packages/sphinx/directives/other.pyint_or_nothing   s    r    c                
   @  sd   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e	je	jd	Zdddd	Zd
d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captionglobhiddenincludehiddennumbered
titlesonlyreversed
list[Node]r   c                 C  s   t  }| jj|d< g |d< g |d< | jdd|d< | jd|d< d| jk|d< d| jk|d< d	| jk|d	< | jd
d|d
< d| jk|d< | | tjdgd}|	| | 
| | |}|	| |S )Nparententriesincludefilesr"   r$   r%   r&   r'   r(   r   r)   ztoctree-wrapper)classes)r   toctreeenvdocnameoptionsgetset_source_infor   ZcompoundappendZadd_nameparse_content)selfsubnodeZwrappernoderetr   r   r   run9   s$    




zTocTree.runzaddnodes.toctree)r2   r   c                 C  sp  t | jjd j}| jj}| jj |B }|| jj	 g }t
| jj}| jD ]}|sZqNt|}|d rt|r|st|st| jj	|}	tt||	}
|
D ]8}||krq|| |d d |f |d | q|
stjtd||d qN|r|d}|d}|}n| }}d }|D ]*}||r(|d t|  } qTq(t| jj	|}t|sx|d	kr|d ||f qN|| jj|B kr|| j|d
rtd}d}ntd}d}tj||d||d | j  qN||kr|| ntjtd||d |d ||f |d | qNd| jkrltt|d |d< tt|d |d< |S )NZstdr%   r.   r/   z2toctree glob pattern %r didn't match any documentslocation      r:   Fz2toctree contains reference to excluded document %rexcludedz5toctree contains reference to nonexisting document %rZnot_readableZtoc)typesubtyper?   z%duplicated entry found in toctree: %sr*   ) 	frozensetr3   domainsZ_virtual_doc_namesconfigZsource_suffixZ
found_docscopyremover4   r   Zexclude_patternscontentr   matchglob_rer   r   sortedr   r8   loggerwarningr   groupendswithlenZdoc2pathZnote_rereadr5   listr*   )r:   r2   Zgenerated_docnamessuffixesZall_docnamesr<   rB   entryexplicitZpatnameZdocnamesr4   reftitlesuffixmessagerD   r   r   r   r9   Q   s|    


 



zTocTree.parse_contentN)__name__
__module____qualname____doc__has_contentrequired_argumentsoptional_argumentsfinal_argument_whitespacer   r	   Z	unchangedZunchanged_requiredflagr    option_specr=   r9   r   r   r   r   r!   $   s"   r!   c                   @  s<   e Zd ZU dZdZdZdZdZi Zde	d< 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.
    FrA   r   Tr   rd   r+   r,   c                 C  s   | j jsg S tjdd}t }||7 }| jdkr<td}n0| jdkrPtd}n| jdkrdtd}ntd	}|t|7 }| j	| j
d
 | j\}}|| |g}||7 }|S )NF)ZtranslatablesectionauthorzSection author: moduleauthorzModule author: 
codeauthorzCode author: zAuthor: r   )rG   Zshow_authorsr   	paragraphZemphasisr#   r   Textstateinline_text	argumentslinenoextend)r:   paraZemphtextinodesmessagesr<   r   r   r   r=      s$    






z
Author.runNr[   r\   r]   r^   r_   r`   ra   rb   rd   __annotations__r=   r   r   r   r   re      s   
re   c                   @  s   e Zd ZdZejZdS )SeeAlsozB
    An admonition mentioning things to look at as reference.
    N)r[   r\   r]   r^   r   seealsoZ
node_classr   r   r   r   rv      s   rv   c                   @  s<   e Zd ZU dZdZdZdZdZi Zde	d< dd	d
dZ
dS )TabularColumnszL
    Directive to give an explicit tabulary column definition to LaTeX.
    FrA   r   Tr   rd   r+   r,   c                 C  s&   t  }| jd |d< | | |gS )Nr   spec)r   Ztabular_col_specrm   r7   r:   noder   r   r   r=      s    
zTabularColumns.runNrt   r   r   r   r   rx      s   
rx   c                   @  s<   e Zd ZU dZdZdZdZdZi Zde	d< dd	d
dZ
dS )Centeredz;
    Directive to create a centered line of bold text.
    FrA   r   Tr   rd   r+   r,   c                 C  sH   | j s
g S t }| j| j d | j\}}|| |g}||7 }|S )Nr   )rm   r   centeredrk   rl   rn   ro   )r:   r;   rr   rs   r<   r   r   r   r=      s    
zCentered.runNrt   r   r   r   r   r|      s   
r|   c                   @  s<   e Zd ZU dZdZdZdZdZi Zde	d< ddd	d
Z
dS )Acksz(
    Directive for a list of names.
    Tr   Fr   rd   r+   r,   c                 C  sl   t  }| jj|_| j| j| j| t|jdksFt	|jd t
jsftjtd| jj| jfd g S |gS )NrA   r   z.. acks content is not a listr>   )r   acksrk   documentnested_parserJ   content_offsetrR   children
isinstancer   bullet_listrN   rO   r   r3   r4   rn   rz   r   r   r   r=      s    

zAcks.runNrt   r   r   r   r   r~      s   
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
dZdS )HListz@
    Directive for a list that gets compacted horizontally.
    Tr   Fcolumnsr   rd   r+   r,   c                 C  s  | j dd}t }| jj|_| j| j| j| t	|j
dksTt|j
d tjsttjtd| jj| jfd g S |j
d }tt	||\}}d}t }t||d< t|D ]J}|||k r|d n| }	t }
|
|j
||	 7 }
|td|
7 }|	}q|gS )	Nr   r@   rA   r   z.. hlist content is not a listr>   ncolumns )r5   r6   r   ri   rk   r   r   rJ   r   rR   r   r   r   rN   rO   r   r3   r4   rn   divmodr   hlistr   rangeZhlistcol)r:   r   r{   ZfulllistZnpercolZnmoreindexZnewnodecolumnZendindexr   r   r   r   r=     s.    


z	HList.runN)r[   r\   r]   r^   r_   r`   ra   rb   r   rd   ru   r=   r   r   r   r   r     s   
 r   c                   @  s<   e Zd ZU dZdZdZdZdZi Zde	d< ddd	d
Z
dS )OnlyzI
    Directive to only include text if the given tag(s) are enabled.
    TrA   r   r   rd   r+   r,   c                 C  s4  t  }| jj|_| | | jd |d< | jj}|j}|j}g |_d|_z| jj	| j
| j|dd |j}|r|r|d |ks| jjs|gW S d}| jj}|r|d7 }|j}q|d8 }|d }t|}	||kr||}	||	 d }
ttj| jj}t|
D ]}|jr|j}q|| g W S ||_||_X d S )Nr   exprT)Zmatch_titlesrA   r@   )r   onlyrk   r   r7   rm   memotitle_stylesZsection_levelr   rJ   r   r-   rR   r   r   r   r   r   r8   )r:   r{   r   Zsurrounding_title_stylesZsurrounding_section_levelr   Zcurrent_depthr-   title_styleZnested_depthZn_sects_to_raiseZ_ir   r   r   r=   1  sT    

 



zOnly.runNrt   r   r   r   r   r   '  s   
r   c                      s&   e Zd ZdZd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+   r,   c                   s`   | j d dr*| j d dr*t  S | j| j d \}}|| j d< | j| t  S )Nr   <>)rm   
startswithrQ   superr=   r3   Z
relfn2pathZnote_included)r:   Zrel_filenamefilename	__class__r   r   r=   g  s    

zInclude.run)r[   r\   r]   r^   r=   __classcell__r   r   r   r   r   a  s   r   r   zdict[str, Any])appr   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 )Nr2   rf   rg   rh   rw   Ztabularcolumnsr}   r   r   r   includeZcssclassz	rst-classbuiltinT)versionZparallel_read_safeZparallel_write_safe)r	   Zregister_directiver!   re   rv   rx   r|   r~   r   r   r   r   )r   r   r   r   setupr  s"    r   )9
__future__r   retypingr   r   r   Zdocutilsr   Zdocutils.nodesr   r   Zdocutils.parsers.rstr	   Z+docutils.parsers.rst.directives.admonitionsr
   Z$docutils.parsers.rst.directives.miscr   r   ZBaseIncludeZsphinxr   Zsphinx.domains.changesetr   Zsphinx.localer   r   Zsphinx.utilr   r   r   Zsphinx.util.docutilsr   Zsphinx.util.matchingr   r   Zsphinx.util.nodesr   Zsphinx.util.typingr   Zsphinx.applicationr   compilerL   	getLoggerr[   rN   r    r!   re   rv   rx   r|   r~   r   r   r   r   r   r   r   <module>   s>   

x"%: