B
    öÀ„\¨#  ã               @   s   d Z ddlmZ ddlmZ ddlmZ ddl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 e e¡ZG dd„ dejejƒZG dd„ dejejƒZG dd„ deeƒZdd„ ZG dd„ deƒZdd„ Z dd„ Z!dd„ Z"dd„ Z#dd„ Z$d d!„ Z%d"d#„ Z&d$d%„ Z'dS )&až  
    sphinx.ext.todo
    ~~~~~~~~~~~~~~~

    Allow todos to be inserted into your documentation.  Inclusion of todos can
    be switched of by a configuration variable.  The todolist directive collects
    all todos of your project and lists them along with a backlink to the
    original location.

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
é    )Únodes)Ú
directives)ÚBaseAdmonitionN)ÚNoUri)Ú_Ú__)Úlogging)ÚSphinxDirective)Úset_source_info)Útex_escape_mapc               @   s   e Zd ZdS )Ú	todo_nodeN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú.lib/python3.7/site-packages/sphinx/ext/todo.pyr   $   s   r   c               @   s   e Zd ZdS )ÚtodolistN)r   r   r   r   r   r   r   r   (   s   r   c                   s>   e Zd ZdZeZdZdZdZdZ	de
jiZ‡ fdd„Z‡  ZS )ÚTodozO
    A todo entry, displayed (if configured) in the form of an admonition.
    Tr   FÚclassc                sš   | j  d¡sdg| j d< tt| ƒ ¡ \}t|tjƒr:|gS | dtj	t
dƒd¡ t| |ƒ d| j d¡ }d| jj|f |d	< tjd
d
|gd}||gS )Nr   zadmonition-todor   r   )Útextzindex-%sÚindexz%s:%sÚ	targetrefÚ )Úids)ZoptionsÚgetÚsuperr   ÚrunÚ
isinstancer   Zsystem_messageÚinsertÚtitler   r
   ÚenvZnew_serialnoÚdocnameÚtarget)ÚselfÚtodoZtargetidÚ
targetnode)Ú	__class__r   r   r   :   s    
zTodo.run)r   r   r   Ú__doc__r   Z
node_classÚhas_contentÚrequired_argumentsÚoptional_argumentsÚfinal_argument_whitespacer   Zclass_optionÚoption_specr   Ú__classcell__r   r   )r&   r   r   ,   s   
r   c          	   C   sÜ   | j j}t|dƒsg |_x¾| t¡D ]°}|  d|¡ y*|j|j |¡d  }t	|t
jƒs\t‚W n tk
rv   d }Y nX | ¡ }|d= |j |j|jp | |j¡|j||dœ¡ |jjr$tjtdƒ|d  ¡ |d q$W d S )NÚtodo_all_todosztodo-definedé   r   )r!   ÚsourceÚlinenor$   r"   zTODO entry found: %s)Úlocation)Úbuilderr    Úhasattrr.   Útraverser   ÚemitÚparentr   r   r   r"   Ú
IndexErrorÚdeepcopyÚappendr!   r0   Zdoc2pathÚlineÚconfigÚtodo_emit_warningsÚloggerZwarningr   Úastext)ÚappÚdoctreer    Únoder%   Únewnoder   r   r   Úprocess_todosM   s,    


rD   c               @   s,   e Zd ZdZdZdZdZdZi Zdd„ Z	dS )ÚTodoListz%
    A list of all todo entries.
    Fr   c             C   s
   t dƒgS )Nr   )r   )r#   r   r   r   r   x   s    zTodoList.runN)
r   r   r   r'   r(   r)   r*   r+   r,   r   r   r   r   r   rE   m   s   rE   c          
   C   s"  | j d s*x| t¡D ]}|j |¡ qW | jj}t|dƒsBg |_xØ| t	¡D ]È}| 
d¡rlt ¡ g}ng }| j d s†| |¡ qPx†|jD ]z}tjdgd}| j d r¸tdƒ}ntdƒ|d	 |d
 f }|d | d¡… }	|| d¡d d … }
|t |	|	¡7 }tjdddd}t tdƒtdƒ¡}yf| j ||d ¡|d< d|d krp|d  d|d d  7  < n |d  d|d d d  7  < W n tk
r¨   Y nX | |¡ ||7 }|t |
|
¡7 }|d }d|krä|d= | ||d | j¡ | |¡ | |¡ qW | |¡ qPW d S )NÚtodo_include_todosr.   r   ztodo-source)ÚclassesÚtodo_link_onlyz<<original entry>>z3(The <<original entry>> is located in %s, line %d.)r0   r1   z<<z>>é   r   T)Zinternalzoriginal entryr!   ZrefuriZrefidr"   ú#r   r$   r   )r<   r5   r   r7   Úremover3   r    r4   r.   r   r   r   r"   Zreplace_selfZ	paragraphr   ÚfindZTextZ	referenceZemphasisZget_relative_urir   r:   Zresolve_references)r@   rA   ZfromdocnamerB   r    ZcontentZ	todo_infoZparaZdescriptionZdesc1Zdesc2rC   Z	innernodeZ
todo_entryr   r   r   Úprocess_todo_nodes   sV    






$


rM   c                s(   t |dƒsd S ‡ fdd„|jD ƒ|_d S )Nr.   c                s   g | ]}|d  ˆ kr|‘qS )r!   r   )Ú.0r$   )r!   r   r   ú
<listcomp>É   s    zpurge_todos.<locals>.<listcomp>)r4   r.   )r@   r    r!   r   )r!   r   Úpurge_todosÅ   s    
rP   c             C   s0   t |dƒsd S t |dƒsg |_|j |j¡ d S )Nr.   )r4   r.   Úextend)r@   r    ZdocnamesÚotherr   r   r   Ú
merge_infoÍ   s
    

rS   c             C   s   |   |¡ d S )N)Zvisit_admonition)r#   rB   r   r   r   Úvisit_todo_nodeÖ   s    rT   c             C   s   |   |¡ d S )N)Zdepart_admonition)r#   rB   r   r   r   Údepart_todo_nodeÜ   s    rU   c             C   sV   |  d¡ ¡  t¡}| j d¡ | d¡}|d k	rB| j d| ¡ | j d| ¡ d S )Nr   z 
\begin{sphinxadmonition}{note}{r   z
\label{%s}z%s:})Úpopr?   Ú	translater   Úbodyr:   r   )r#   rB   r   r"   r   r   r   Úlatex_visit_todo_nodeá   s    
rY   c             C   s   | j  d¡ d S )Nz\end{sphinxadmonition}
)rX   r:   )r#   rB   r   r   r   Úlatex_depart_todo_nodeí   s    rZ   c             C   s¾   |   d¡ |  ddd¡ |  ddd¡ |  ddd¡ |  t¡ | jtttfttfttfttfttfd |  	dt
¡ |  	d	t¡ |  d
t¡ |  dt¡ |  dt¡ |  dt¡ tjdddœS )Nztodo-definedrF   FÚhtmlrH   r=   )r[   Zlatexr   ZmanZtexinfor$   r   zdoctree-readzdoctree-resolvedzenv-purge-doczenv-merge-infor/   T)ÚversionZenv_versionZparallel_read_safe)Z	add_eventZadd_config_valueZadd_noder   r   rT   rU   rY   rZ   Zadd_directiver   rE   ZconnectrD   rM   rP   rS   ÚsphinxZ__display_version__)r@   r   r   r   Úsetupò   s(    

r^   )(r'   Zdocutilsr   Zdocutils.parsers.rstr   Z+docutils.parsers.rst.directives.admonitionsr   r]   Zsphinx.environmentr   Zsphinx.localer   r   Zsphinx.utilr   Zsphinx.util.docutilsr	   Zsphinx.util.nodesr
   Zsphinx.util.texescaper   Z	getLoggerr   r>   Z
AdmonitionZElementr   ZGeneralr   r   rD   rE   rM   rP   rS   rT   rU   rY   rZ   r^   r   r   r   r   Ú<module>   s0   
! F	