
    Fe@                    L   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 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 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	rd dl,m-Z-m.Z. d dl/m0Z0 d dl1m2Z2  ejf                  d      Z4 e#jj                  e6      Z7d,dZ8 G d de&      Z9 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&      Z? G d' d(e&      Z@ G d) d*ee&      Zd-d+ZAy).    )annotationsN)abspathrelpath)Path)TYPE_CHECKINGAnycast)nodes)
directives)BaseAdmonition)Class)Include)StateMachine)addnodes)VersionChange)StandardDomain)___)docname_joinloggingurl_re)SphinxDirective)Matcher	patfilter)explicit_title_re)ElementNode)Sphinx)
OptionSpecz
.*[*?\[].*c                    | syt        |       S )Ni  )int)arguments    9/usr/lib/python3/dist-packages/sphinx/directives/other.pyint_or_nothingr$   #   s    x=    c            
          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Zd
dZy)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reversedc                   t        j                         }| j                  j                  |d<   g |d<   g |d<   | j                  j                  dd      |d<   | j                  j                  d      |d<   d| j                  v |d<   d| j                  v |d<   d	| j                  v |d	<   | j                  j                  d
d      |d
<   d| j                  v |d<   | j                  |       t        j                  dg      }|j                  |       | j                  |       | j                  |      }|j                  |       |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
   compoundappendadd_nameparse_content)selfsubnodewrappernoderets       r#   runzTocTree.run>   s/   ""$ HH,,  	"$"ll..z2>
!\\--i8	 DLL0$4#2dll#B "ll..z1=
 , <W%nn.?-@A7#k"  )

;
r%   c                n   t        t        j                        }| j                  j                  }| j
                  j                  }|d   }| j
                  j                  j                         |z  }|j                  |       t        |      }g }t        | j                  j                        }	| j                  D ]4  }
|
st        j                  |
      }t        j                  |
      d u}|rt         j                  |
      r|s|st#        ||
      }t%        t'        ||            }|D ]B  }||v r|j                  |       |d   j)                  d |f       |d   j)                  |       D |s!t*        j-                  t/        d      |
|       |r%|j1                  d      }|j1                  d      }|}n|
x}}d }|D ]&  }|j3                  |      s|j5                  |      } n t#        ||      }|s|dk(  r|d   j)                  ||f       ]||vrs |	| j
                  j7                  |d	            rt/        d
      }d}nt/        d      }d}t*        j-                  ||d||       | j
                  j9                          ||v r|j                  |       n!t*        j-                  t/        d      ||       |d   j)                  ||f       |d   j)                  |       7 d| j:                  v r4t=        t?        |d               |d<   t=        t?        |d               |d<   |S )Nr+   r3   r4   z2toctree glob pattern %r didn't match any documentslocation      rA   Fz2toctree contains reference to excluded document %rexcludedz5toctree contains reference to nonexisting document %rnot_readabletoc)typesubtyperH   z%duplicated entry found in toctree: %sr0   ) 	frozensetr   _virtual_doc_namesconfigsource_suffixr8   r9   
found_docscopyremover   exclude_patternscontentr   matchr   glob_rer   sortedr   r>   loggerwarningr   groupendswithremovesuffixdoc2pathnote_rereadr:   listr0   )rA   r7   generated_docnamessuffixescurrent_docnamer+   all_docnamesfrozen_all_docnamesrD   rK   entryexplicit	url_matchpat_name	doc_namesr9   reftitlesuffixmessagerO   s                        r#   r@   zTocTree.parse_contentV   s!   &~'H'HI;;,,((**v xx**//14FFO,'54;;778\\ >	4E )..u5HU+47Ie,Xi'?"9\8#DE	( <G"44  ''0I&--tWo>N+227;< !NN2&Z#[#(7 # <nnQ' q) %%g # ##F+%226:G #?G<GC6M	"))5#,711DHH--gu=> !UVG(G !XYG,GweW(/  1$$&,&##G,r"IJG(/  1 I%%ug&67N#**73}>	4B %!%hwy/A&B!CGI&*8GN4K+L&MGN#
r%   Nreturn
list[Node])r7   zaddnodes.toctreers   rt   )__name__
__module____qualname____doc__has_contentrequired_argumentsoptional_argumentsfinal_argument_whitespacer!   r   	unchangedunchanged_requiredflagr$   option_specrE   r@    r%   r#   r'   r'   )   sm     K %$$00//#" ooOO
K0Rr%   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Z
y	)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.
    FrJ   r   Tr   r   c                   | j                   j                  sg S t        j                  d      }t        j                         }||z  }| j
                  dk(  rt        d      }nA| j
                  dk(  rt        d      }n&| j
                  dk(  rt        d      }nt        d	      }|t        j                  |      z  }| j                  j                  | j                  d
   | j                        \  }}|j                  |       |g}||z  }|S )NF)translatablesectionauthorzSection author: moduleauthorzModule author: 
codeauthorzCode author: zAuthor: r   )rR   show_authorsr
   	paragraphemphasisr)   r   Textstateinline_text	argumentslinenoextend)rA   paraemphtextinodesmessagesrD   s          r#   rE   z
Author.run   s    {{''IU;~~99''(DYY.(&'DYY,&_%DZ=D

4  ::11$..2CT[[QF&x
r%   Nrr   ru   rv   rw   rx   ry   rz   r{   r|   r   __annotations__rE   r   r%   r#   r   r      s/     K $ K r%   r   c                  (    e Zd ZdZej
                  Zy)SeeAlsozB
    An admonition mentioning things to look at as reference.
    N)ru   rv   rw   rx   r   seealso
node_classr   r%   r#   r   r      s     !!Jr%   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Z
y	)TabularColumnszL
    Directive to give an explicit tabulary column definition to LaTeX.
    FrJ   r   Tr   r   c                v    t        j                         }| j                  d   |d<   | j                  |       |gS )Nr   spec)r   tabular_col_specr   r<   rA   nodes     r#   rE   zTabularColumns.run   s7    ((*~~a(VT"vr%   Nrr   r   r   r%   r#   r   r      s/     K $ K r%   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Z
y	)Centeredz;
    Directive to create a centered line of bold text.
    FrJ   r   Tr   r   c                    | j                   sg S t        j                         }| j                  j	                  | j                   d   | j
                        \  }}|j                  |       |g}||z  }|S )Nr   )r   r   centeredr   r   r   r   )rA   rB   r   r   rD   s        r#   rE   zCentered.run   se    ~~I#,,.::11$..2CT[[Qv")x
r%   Nrr   r   r   r%   r#   r   r      s/     K $ K 	r%   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Z
y)
Acksz(
    Directive for a list of names.
    Tr   Fr   r   c                   t        j                         }| j                  j                  |_        | j                  j	                  | j
                  | j                  |       t        |j                        dk7  s't        |j                  d   t        j                        sBt        j                  t        d      | j                  j                   | j"                  f       g S |gS )NrJ   r   z.. acks content is not a listrG   )r   acksr   documentnested_parserX   content_offsetlenchildren
isinstancer
   bullet_listr\   r]   r   r8   r9   r   r   s     r#   rE   zAcks.run  s    }}

++

d.A.A4Ht}}"*T]]15E5:5F5F+HNN2=>%)XX%5%5t{{$C  EIvr%   Nrr   r   r   r%   r#   r   r      s/     K % K 	r%   r   c                  <    e Zd ZU dZdZdZdZdZdeiZ	de
d<   d
dZy	)HListz@
    Directive for a list that gets compacted horizontally.
    Tr   Fcolumnsr   r   c                X   | j                   j                  dd      }t        j                         }| j                  j
                  |_        | j                  j                  | j                  | j                  |       t        |j                        dk7  s't        |j                  d   t        j                        sBt        j                  t        d      | j                   j"                  | j$                  f       g S |j                  d   }t'        t        |      |      \  }}d}t)        j*                         }t-        |      |d<   t/        |      D ]R  }|||k  r|dz   n|z   }	t        j                         }
|
|j                  ||	 z  }
|t)        j0                  d|
      z  }|	}T |gS )	Nr   rI   rJ   r   z.. hlist content is not a listrG   ncolumns )r:   r;   r
   r   r   r   r   rX   r   r   r   r   r   r\   r]   r   r8   r9   r   divmodr   hliststrrangehlistcol)rA   r   r   fulllistnpercolnmoreindexnewnodecolumnendindexr   s              r#   rE   z	HList.run  sl   <<##Iq1 

++

d.A.A4Ht}}"*T]]15E5:5F5F+HNN2>?%)XX%5%5t{{$C  EI==#Hx8.."!(m
Ho 	F%1WMH++-K8,,U8<<Kx(([99GE	 yr%   Nrr   )ru   rv   rw   rx   ry   rz   r{   r|   r!   r   r   rE   r   r%   r#   r   r     s8     K %3K r%   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Z
y)
OnlyzI
    Directive to only include text if the given tag(s) are enabled.
    TrJ   r   r   r   c                   t        j                         }| j                  j                  |_        | j	                  |       | j
                  d   |d<   | j                  j                  }|j                  }|j                  }g |_        d|_        	 | j                  j                  | j                  | j                  |d       |j                  }|r|r|d   |vs| j                  j                  s|g||_        ||_        S d}| j                  j                  }|r|dz  }|j                  }|r|dz  }|d   }t        |      }	||v r|j                  |      }	||	z
  dz   }
t        t         j"                  | j                  j                        }t%        |
      D ]  }|j                  s|j                  } |j'                  |       g ||_        ||_        S # ||_        ||_        w xY w)Nr   exprT)match_titlesrJ   rI   )r   onlyr   r   r<   r   memotitle_stylessection_levelr   rX   r   r2   r   r   r	   r
   r   r   r>   )rA   r   r   surrounding_title_stylessurrounding_section_levelr   current_depthr2   title_stylenested_depthn_sects_to_raise_is               r#   rE   zOnly.run@  s   }}

++T"~~a(V JJOO#'#4#4 $($6$6! 	;JJ##DLL$2E2E$(t $ =,,L,$ O+CC

))v, !9D!:D+ MZZ&&F"  QM&q/K78L667==kJ  -|;a?%--):):;F,- +==#]]F+ MM$ 8D!:D !9D!:Ds    A"G -G /A:G * G G)Nrr   r   r   r%   r#   r   r   6  s/     K $ K -;r%   r   c                  $     e Zd ZdZd fdZ xZS )r   z
    Like the standard "Include" directive, but interprets absolute paths
    "correctly", i.e. relative to source directory.
    c                     fd} j                   j                  j                  j                  j	                  d      r| j
                  _         j                  d   j                  d      r, j                  d   j                  d      rt         -         S  j                   j                   j                  d         \  }}| j                  d<    j                   j                  |       t         -         S )Nc                   dj                  | d d       }t        t        t        |      j                  j
                              }j                  j                  }|g}j                  j                  j                  j                  d|||       |d   }|j                         | dd  z   } t        j                  j                  | |      S )N
)startinclude-readr   )joinr   r   r   r8   srcdirr9   appeventsemit
splitlinesr   insert_inputstate_machine)include_linessourcer   pathr9   argrA   s         r#   _insert_inputz"Include.run.<locals>._insert_input}  s     99]3B/0DtxxGHDhh&&G &CHHLL$$^T7CHq6D !OO-bc0BBM
  ,,T-?-?PVWWr%   r   r   <>)r8   r   r   	listenersr;   r   r   r   
startswithr_   superrE   
relfn2pathnote_included)rA   r   rel_filenamefilename	__class__s   `   r#   rE   zInclude.runv  s    	X2 88<<((,,^<.;D+>>!'',>>!%%c*7;= !%!4!4T^^A5F!Gh$qx(w{}r%   rr   )ru   rv   rw   rx   rE   __classcell__)r   s   @r#   r   r   p  s    
+ +r%   r   c                   t        j                  dt               t        j                  dt               t        j                  dt               t        j                  dt               t        j                  dt               t        j                  dt
               t        j                  dt               t        j                  dt               t        j                  d	t               t        j                  d
t               t        j                  dt               t        j                  dt               t        j                  dt               ddddS )Nr7   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   s    r#   setupr     s    !!)W5!!/6:!!.&9!!,7!!)W5!!"2NC!!*h7!!&$/!!'51!!&$/!!)W5 !!*e4!!+u5 "# r%   )r"   r   rs   r!   )r   r   rs   zdict[str, Any])B
__future__r   reos.pathr   r   pathlibr   typingr   r   r	   docutilsr
   docutils.parsers.rstr   +docutils.parsers.rst.directives.admonitionsr   $docutils.parsers.rst.directives.miscr   r   BaseIncludedocutils.statemachiner   sphinxr   sphinx.domains.changesetr   sphinx.domains.stdr   sphinx.localer   r   sphinx.utilr   r   r   sphinx.util.docutilsr   sphinx.util.matchingr   r   sphinx.util.nodesr   docutils.nodesr   r   sphinx.applicationr   sphinx.util.typingr   compilerZ   	getLoggerru   r\   r$   r'   r   r   r   r   r   r   r   r   r   r%   r#   <module>r     s    " 	 $  + +  + F 6 G .  2 -  5 5 0 3 /,)- "**]
#			8	$o D_ D"n "_ " ,? ,"O "J7;? 7;t1k? 1hr%   