B
    .Kc"                 @   s  d dl Z d dlZd dl mZ d dlmZmZmZmZmZ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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*m+Z+ d dl,m-Z- yd dl.m/Z0 W n" e1k
r:   d dl2m/Z0 Y nX erNd dl3m4Z4 e#5e6Z7G dd dej8Z8G dd de0e%Z/G dd dej9Z9G dd dej:Z:G dd dej;Z;G dd  d e%Z<G d!d" d"e%Z=d#ee>ef d$d%d&Z?dS )'    N)path)TYPE_CHECKINGAnyDictListSequenceTuplecast)nodes)Nodemake_idsystem_message)
directives)imagestables)set_classes)addnodes)RemovedInSphinx60Warning)optional_int)
MathDomain)__)logging)SphinxDirective)set_source_info)SEPos_pathrelpath)
OptionSpec)Meta)Sphinxc                   s*   e Zd ZdZee d fddZ  ZS )FigureziThe figure directive which applies `:name:` option to the figure node
    instead of the image node.
    )returnc                s   | j dd }t  }t|dks4t|d tjr8|S t|dksHtt	tj
|d }|rp|| j d< | | |jd krt|dkrt	tj|d }|j|_|gS )Nname   r      )optionspopsuperrunlen
isinstancer
   r   AssertionErrorr	   figureadd_namelinecaption)selfr"   resultZfigure_noder/   )	__class__ 8lib/python3.7/site-packages/sphinx/directives/patches.pyr(   )   s    


z
Figure.run)__name__
__module____qualname____doc__r   r   r(   __classcell__r3   r3   )r2   r4   r    $   s   r    c                   s&   e Zd Zee d fddZ  ZS )r   )r!   c                sx   t   }xh|D ]`}t|tjrt|jd d tjr|jd d }| j	| jj
|_| j|_|d |_tj|_qW |S )Nr
   r   content)r'   r(   r*   r
   pendingZdetailsr   Zdocutils_metaenvdoc2pathdocnamesourcelinenor.   Z
rawcontentmetar2   )r0   r1   noderA   )r2   r3   r4   r(   ?   s    


zMeta.run)r5   r6   r7   r   r   r(   r9   r3   r3   )r2   r4   r   >   s   r   c                   sJ   e Zd ZdZee d fddZeej	ee
 f d fddZ  ZS )RSTTablezxThe table directive which sets source and line information to its caption.

    Only for docutils-0.13 or older version.)r!   c                s   t dt t  S )NzRSTTable is deprecated.)warningswarnr   r'   r(   )r0   )r2   r3   r4   r(   V   s    zRSTTable.runc                s$   t   \}}|rt| | ||fS )N)r'   
make_titler   )r0   titlemessage)r2   r3   r4   rF   [   s    
zRSTTable.make_title)r5   r6   r7   r8   r   r   r(   r   r
   rG   r   rF   r9   r3   r3   )r2   r4   rC   Q   s   rC   c                   s*   e Zd ZdZee d fddZ  ZS )CSVTablezThe csv-table directive which searches a CSV file from Sphinx project's source
    directory when an absolute path is given via :file: option.
    )r!   c                s   d| j kr| j d ttjfr| jjjj}| j d }t	
|r\tjtd|j| jfd nBt	|jt| j d dd  }t	||j}t||| j d< t  S )Nfilez":file:" option for csv-table directive now recognizes an absolute path as a relative path from source directory. Please update your document.)locationr$   )r%   
startswithr   ossepstatedocumentZsettingsr<   r   existsloggerZwarningr   r>   r@   joinZsrcdirr   dirnamer=   r   r'   r(   )r0   r<   filenameabspathZdocdir)r2   r3   r4   r(   h   s     


 zCSVTable.run)r5   r6   r7   r8   r   r   r(   r9   r3   r3   )r2   r4   rI   c   s   rI   c                   sJ   e Zd ZdZee d fddZeej	ee
 f d fddZ  ZS )	ListTablez}The list-table directive which sets source and line information to its caption.

    Only for docutils-0.13 or older version.)r!   c                s   t dt t  S )NzListTable is deprecated.)rD   rE   r   r'   r(   )r0   )r2   r3   r4   r(   ~   s    zListTable.runc                s$   t   \}}|rt| | ||fS )N)r'   rF   r   )r0   rG   rH   )r2   r3   r4   rF      s    
zListTable.make_title)r5   r6   r7   r8   r   r   r(   r   r
   rG   r   rF   r9   r3   r3   )r2   r4   rW   y   s   rW   c               @   sH   e Zd ZU dZdZejejeje	dZ
eed< dZee dddZd	S )
CodezqParse and mark up content of a code block.

    This is compatible with docutils' :rst:dir:`code` directive.
    r$   )classforcer"   znumber-linesoption_specT)r!   c             C   s   |    t| j d| j}tj||| jdg d| jki d}| | t	| | | j
rl| j
d |d< n| jjd| jj|d< d| jkrd	|d
< | jd r| jd |d d< |gS )N
classesrZ   )r]   rZ   highlight_argsr   languagehighlight_languageznumber-linesTZlinenosr^   Zlinenostart)Zassert_has_contentr   r%   rS   r:   r
   Zliteral_blockgetr-   r   	argumentsr<   Z	temp_dataconfigr`   )r0   coderB   r3   r3   r4   r(      s$    





zCode.runN)r5   r6   r7   r8   optional_argumentsr   class_optionflag	unchangedr   r[   r   __annotations__has_contentr   r   r(   r3   r3   r3   r4   rX      s   
rX   c               @   sb   e Zd ZU dZdZdZdZejejej	ej
dZeed< ee dddZee d	d
ddZd	S )MathDirectiveTr   r$   )labelr"   rY   nowrapr[   )r!   c          	   C   s   d | j}| jr.| jd r.| jd d | }| jd| jd}tj||| jdg | jjd |d| jkd}| 	| | 
| |g}| | |S )	Nr\   r   z

rl   r"   rY   rm   )r]   r>   numberrl   rm   )rS   r:   rb   r%   ra   r
   
math_blockr<   r>   r-   r   
add_target)r0   Zlatexrl   rB   retr3   r3   r4   r(      s    


zMathDirective.runN)rq   r!   c             C   s   t tj|d }|d dks,| jjrL|d sL| jd}d| jj|f |d< |d sXd S t t| j	d}|j
| jj|d |d ||d |d< td	|d  }tjdd|gd
}| jj| |d| d S )Nr   rl    zsphinx.ext.math#equationsz%s:%dmath)rK   rn   zequation-%s)Zids)r	   r
   ro   rc   Zmath_number_allr<   Znew_serialnor>   r   Z
get_domainZnote_equationZget_equation_number_forr   targetrO   rP   Znote_explicit_targetinsert)r0   rq   rB   seqdomainZnode_idrt   r3   r3   r4   rp      s    zMathDirective.add_target)r5   r6   r7   rj   Zrequired_argumentsre   Zfinal_argument_whitespacer   rh   rf   rg   r[   r   ri   r   r   r(   rp   r3   r3   r3   r4   rk      s   
rk   r   )appr!   c             C   sH   t dt t dt t dt t dt t dt ddddS )	Nr,   rA   z	csv-tablerd   rs   ZbuiltinT)versionZparallel_read_safeZparallel_write_safe)r   Zregister_directiver    r   rI   rX   rk   )rx   r3   r3   r4   setup   s    rz   )@rM   rD   r   typingr   r   r   r   r   r   r	   Zdocutilsr
   Zdocutils.nodesr   r   r   Zdocutils.parsers.rstr   Zdocutils.parsers.rst.directivesr   r   Zdocutils.parsers.rst.rolesr   Zsphinxr   Zsphinx.deprecationr   Zsphinx.directivesr   Zsphinx.domains.mathr   Zsphinx.localer   Zsphinx.utilr   Zsphinx.util.docutilsr   Zsphinx.util.nodesr   Zsphinx.util.osutilr   r   r   Zsphinx.util.typingr   Z$docutils.parsers.rst.directives.miscr   ZMetaBaseImportErrorZ$docutils.parsers.rst.directives.htmlZsphinx.applicationr   Z	getLoggerr5   rR   r    rC   rI   rW   rX   rk   strrz   r3   r3   r3   r4   <module>   sB   $
.6