B
    \h;                 @   sx  d 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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 ddlmZmZ ddlmZmZmZ e dZ!d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Z)G d!d" d"eZ*G d#d$ d$eZ+G d%d& d&eeZ
d'd( Z,dS ))z
    sphinx.directives.other
    ~~~~~~~~~~~~~~~~~~~~~~~

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
    N)nodes)
directives)BaseAdmonition)Class)Include)range)addnodes)VersionChange)_)url_redocname_join)SphinxDirective)Matcher	patfilter)explicit_title_reset_source_infoprocess_index_entryz
.*[*?\[].*c             C   s   | sdS t | S )Ni  )int)Zargument r   6lib/python3.7/site-packages/sphinx/directives/other.pyint_or_nothing%   s    r   c            
   @   sV   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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reversedc             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| | 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getr   r   ZcompoundappendZadd_nameparse_content)selfsubnodeZwrappernoderetr   r   r   runA   s$    




zTocTree.runc             C   s*  | j j}| jj }|| jj g }t| j j}x| j	D ]}|sHq<t
|}|d rt|r|st|st| jj|}tt||}	x6|	D ].}
||
 |d d |
f |d |
 qW |	s|| jjjjd| | jd q<|r|d}|d}|}
n| }}
d }x.|D ]&}|
|r|
d t|  }
P qW t| jj|
}
t|sl|dkr|d ||f q<|
| jjkr|| j|
d rd	}nd
}|| jjjj||
 | jd | j  q<||
 |d ||
f |d |
 q<W d| jkr&tt|d |d< |S )Nr   r"   r#   z2toctree glob pattern %r didn't match any documents)line      r-   z2toctree contains reference to excluded document %rz5toctree contains reference to nonexisting document %rr    ) configZsource_suffixr'   Z
found_docscopyremover(   r   Zexclude_patternscontentr   matchglob_rer   r   sortedr   r+   statedocumentreporterwarninglinenogroupendswithlenZdoc2pathZnote_rereaddiscardr)   listr    )r-   r&   suffixesZall_docnamesr/   ZexcludedentryZexplicitZpatnameZdocnamesr(   reftitlesuffixmessager   r   r   r,   Z   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_specr0   r,   r   r   r   r   r   ,   s    
r   c               @   s,   e Zd ZdZdZdZdZdZi Z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.
    Fr3   r   Tc             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| S )NF)ZtranslatablesectionauthorzSection author: moduleauthorzModule author: 
codeauthorzCode author: zAuthor: r   )r4   Zshow_authorsr   	paragraphZemphasisr   r
   ZTextr;   inline_text	argumentsr?   extend)r-   ZparaZemphtextinodesmessagesr   r   r   r0      s"    






z
Author.runN)
rK   rL   rM   rN   rO   rP   rQ   rR   rT   r0   r   r   r   r   rU      s   rU   c               @   s,   e Zd ZdZdZdZdZdZi Zdd Z	dS )	Indexz0
    Directive to add entries to the index.
    Fr3   r   Tc             C   s   | j d d}d| jd }tjdd|gd}| jj| t	
 }g |d< d|d	< t| | x |D ]}|d t|| qhW ||gS )
Nr   
zindex-%sindex )Zidsr"   FZinline)r[   splitr'   Znew_serialnor   targetr;   r<   Znote_explicit_targetr   rb   r   r\   r   )r-   r[   ZtargetidZ
targetnodeZ	indexnoderF   r   r   r   r0      s    

z	Index.runN)
rK   rL   rM   rN   rO   rP   rQ   rR   rT   r0   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)rK   rL   rM   rN   r   seealsoZ
node_classr   r   r   r   rf      s   rf   c               @   s,   e Zd ZdZdZdZdZdZi Zdd Z	dS )	TabularColumnszL
    Directive to give an explicit tabulary column definition to LaTeX.
    Fr3   r   Tc             C   s&   t  }| jd |d< t| | |gS )Nr   spec)r   Ztabular_col_specr[   r   )r-   noder   r   r   r0      s    
zTabularColumns.runN)
rK   rL   rM   rN   rO   rP   rQ   rR   rT   r0   r   r   r   r   rh      s   rh   c               @   s,   e Zd ZdZdZdZdZdZi Zdd Z	dS )	Centeredz;
    Directive to create a centered line of bold text.
    Fr3   r   Tc             C   s@   | j s
g S t }| j| j d | j\}}|| |g| S )Nr   )r[   r   centeredr;   rZ   r?   r\   )r-   r.   r^   r_   r   r   r   r0      s    
zCentered.runN)
rK   rL   rM   rN   rO   rP   rQ   rR   rT   r0   r   r   r   r   rk      s   rk   c               @   s,   e Zd ZdZdZdZdZdZi Zdd Z	dS )Acksz(
    Directive for a list of names.
    Tr   Fc             C   sd   t  }| jj|_| j| j| j| t|jdksFt	|jd t
js^| jjjjd| jdgS |gS )Nr3   r   z.. acks content is not a list)r1   )r   acksr;   r<   nested_parser7   content_offsetrB   children
isinstancer   bullet_listr=   r>   r?   )r-   rj   r   r   r   r0     s    

zAcks.runN)
rK   rL   rM   rN   rO   rP   rQ   rR   rT   r0   r   r   r   r   rm     s   rm   c               @   s0   e Zd ZdZdZdZdZdZdeiZ	dd Z
dS )	HListz@
    Directive for a list that gets compacted horizontally.
    Tr   Fcolumnsc             C   s   | j dd}t }| jj|_| j| j| j| t	|j
dksTt|j
d tjsl| jjjjd| jdgS |j
d }tt	||\}}d}t }xbt|D ]V}|||k r|d p| }	t }
|
t 7 }
|
d  |j
||	 7  < |	}||
7 }qW |gS )Nru   r2   r3   r   z.. hlist content is not a list)r1   )r)   r*   r   rY   r;   r<   ro   r7   rp   rB   rq   rr   rs   r=   r>   r?   divmodr   hlistr   Zhlistcol)r-   Zncolumnsrj   ZfulllistZnpercolZnmorerb   ZnewnodecolumnZendindexcolr   r   r   r0   $  s(    


z	HList.runN)rK   rL   rM   rN   rO   rP   rQ   rR   r   rT   r0   r   r   r   r   rt     s   rt   c               @   s,   e Zd ZdZdZdZdZdZi Zdd Z	dS )OnlyzI
    Directive to only include text if the given tag(s) are enabled.
    Tr3   r   c             C   sD  t  }| jj|_t| | | jd |d< | jjj}| jjj}g | jj_d| jj_z| jj	| j
| j|dd | jjj}|r|r|d |ks| jjs|gS d}| jj}x|r|d7 }|j}qW |d8 }|d }t|}||kr||}|| d }	| jj}x t|	D ]}
|jr|j}qW || g S || jj_|| jj_X d S )Nr   exprr3   )Zmatch_titlesr2   )r   onlyr;   r<   r   r[   memotitle_stylesZsection_levelro   r7   rp   r!   rB   rb   r   r+   )r-   rj   Zsurrounding_title_stylesZsurrounding_section_levelr~   Zcurrent_depthr!   Ztitle_styleZnested_depthZn_sects_to_raiseir   r   r   r0   G  sH    











zOnly.runN)
rK   rL   rM   rN   rO   rP   rQ   rR   rT   r0   r   r   r   r   rz   =  s   rz   c               @   s   e Zd ZdZdd ZdS )r   z
    Like the standard "Include" directive, but interprets absolute paths
    "correctly", i.e. relative to source directory.
    c             C   s`   | j d dr*| j d dr*t| S | j| j d \}}|| j d< | j| t| S )Nr   <>)r[   
startswithrA   BaseIncluder0   r'   Z
relfn2pathZnote_included)r-   Zrel_filenamefilenamer   r   r   r0   }  s    

zInclude.runN)rK   rL   rM   rN   r0   r   r   r   r   r   w  s   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 t dt ddddS )Nr&   rV   rW   rX   rb   rg   Ztabularcolumnsrl   rn   rw   r|   ZincludeZcssclassz	rst-classZbuiltinT)versionZparallel_read_safeZparallel_write_safe)r   Zregister_directiver   rU   r`   rf   rh   rk   rm   rt   rz   r   r   )Zappr   r   r   setup  s"    r   )-rN   reZdocutilsr   Zdocutils.parsers.rstr   Z+docutils.parsers.rst.directives.admonitionsr   Z$docutils.parsers.rst.directives.miscr   r   r   Z	six.movesr   Zsphinxr   Zsphinx.domains.changesetr	   Zsphinx.localer
   Zsphinx.utilr   r   Zsphinx.util.docutilsr   Zsphinx.util.matchingr   r   Zsphinx.util.nodesr   r   r   compiler9   r   r   rU   r`   rf   rh   rk   rm   rt   rz   r   r   r   r   r   <module>   s6   	
n!%: