
    Fe                       d 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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 ddlmZmZ er&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(  ejR                  e*      Z+ G d dejX                  ej:                        Z- G d dej\                  ej:                        Z/ G d dee      Z0 G d de      Z1 G d de      Z2 G d d      Z3d%d Z4d%d!Z5d&d"Z6d&d#Z7d'd$Z8y)(zAllow 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.
    )annotations)TYPE_CHECKINGAnycast)nodes)
directives)BaseAdmonitionN)addnodes)Domain)NoUri)___)logging	texescape)SphinxDirectivenew_document)ElementNode)Sphinx)BuildEnvironment)
OptionSpec)HTML5Translator)LaTeXTranslatorc                      e Zd Zy)	todo_nodeN__name__
__module____qualname__     1/usr/lib/python3/dist-packages/sphinx/ext/todo.pyr   r   $       r!   r   c                      e Zd Zy)todolistNr   r    r!   r"   r%   r%   (   r#   r!   r%   c                  v     e Zd ZU dZeZdZdZdZdZ	e
j                  e
j                  dZded<   d	 fdZ xZS )
TodozO
    A todo entry, displayed (if configured) in the form of an admonition.
    Tr   F)classnamer   option_specc                   | j                   j                  d      sdg| j                   d<   t        |          \  }t	        |t
        j                        r|gS t	        |t              r|j                  dt        j                  t        d                   | j                  j                  |d<   | j                  |       | j                  |       | j                  j                   j#                  |       |gS t$        )Nr(   zadmonition-todor   r'   )textdocname)optionsgetsuperrun
isinstancer   system_messager   inserttitler   envr-   add_nameset_source_infostatedocumentnote_explicit_targetRuntimeError)selftodo	__class__s     r"   r1   zTodo.run;   s    ||(%6$7DLL!'+-dE0016Mi(KK5;;AfI67"hh..DOMM$  &JJ44T:6Mr!   returnz
list[Node])r   r   r   __doc__r   
node_classhas_contentrequired_argumentsoptional_argumentsfinal_argument_whitespacer   class_option	unchangedr*   __annotations__r1   __classcell__)r?   s   @r"   r'   r'   ,   sP     JK %(($$K 
 r!   r'   c                  F    e Zd ZdZdZedd       ZddZd	dZ	 	 	 	 d
dZ	y)
TodoDomainr>   c                :    | j                   j                  di       S Ntodos)data
setdefaultr=   s    r"   rP   zTodoDomain.todosQ   s    yy##GR00r!   c                <    | j                   j                  |d        y N)rP   pop)r=   r-   s     r"   	clear_doczTodoDomain.clear_docU   s    

w%r!   c                <    |D ]  }|d   |   | j                   |<    y rO   )rP   )r=   docnames	otherdatar-   s       r"   merge_domaindatazTodoDomain.merge_domaindataX   s)     	>G"+G"4W"=DJJw	>r!   c                \   | j                   j                  |g       }|j                  t              D ]x  }|j                  j                  d|       |j                  |       |j                  j                  sGt        j                  t        d      |d   j                         |       z y )Ntodo-definedzTODO entry found: %s   )location)rP   rR   findallr   appemitappendconfigtodo_emit_warningsloggerwarningr   astext)r=   r6   r-   r:   rP   r>   s         r"   process_doczTodoDomain.process_doc\   s    

%%gr2$$Y/ 	.DGGLL.LLzz,,r"8947>>;K(,  .	.r!   N)rA   zdict[str, list[todo_node]])r-   strrA   None)rY   z	list[str]rZ   dictrA   rk   )r6   r   r-   rj   r:   nodes.documentrA   rk   )
r   r   r   r)   labelpropertyrP   rW   r[   ri   r    r!   r"   rM   rM   M   s=    DE1 1&>	.,	.15	.r!   rM   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)	TodoListz%
    A list of all todo entries.
    Fr   r   r*   c                    t        d      gS )N )r%   rS   s    r"   r1   zTodoList.runs   s     ~r!   Nr@   )r   r   r   rB   rD   rE   rF   rG   r*   rJ   r1   r    r!   r"   rq   rq   h   s/     K % K r!   rq   c                  ,    e Zd ZddZddZddZd	dZy)
TodoListProcessorc                
   |j                   | _         |j                  | _        |j                  | _        t        t        |j                  j                  d            | _        t        d      | _        | j                  ||       y )Nr>   rs   )
builderrd   r6   r   rM   
get_domaindomainr   r:   process)r=   ra   doctreer-   s       r"   __init__zTodoListProcessor.__init__z   sZ    {{jj77:sww'9'9&'AB$R(Wg&r!   c                ^   t        | j                  j                  j                         g       }t	        |j                  t                    D ]  }| j                  j                  s|j                  j                  |       5|j                  d      rt        j                         g}ng }|D ]k  }|j                         }|d   j                          | j!                  ||       |j#                  |       | j%                  ||      }|j#                  |       m |j'                  |        y )Nids)sumry   rP   valueslistr`   r%   rd   todo_include_todosparentremover/   r   targetdeepcopyclearresolve_referencerc   create_todo_referencereplace_self)	r=   r{   r-   rP   nodecontentr>   new_todotodo_refs	            r"   rz   zTodoListProcessor.process   s    !$T[[%6%6%=%=%?!D23 	'D;;11""4(xx*/,,.)9 	)==?%%'&&x9x(55dGDx(	) g&+	'r!   c                   | j                   j                  rt        d      }n$t        d      |j                  |j                  fz  }|d |j                  d       }||j                  d      dz   d  }t        j                  dg      }|t        j                  |      z  }t        j                  t        d      t        d            }t        j                  d	d	|d
      }	 | j                  j                  ||d         |d<   |dxx   d|d   d   z   z  cc<   ||z  }|t        j                  |      z  }|S # t        $ r Y *w xY w)Nz<<original entry>>z3(The <<original entry>> is located in %s, line %d.)z<<z>>   ztodo-source)classeszoriginal entryrs   T)internalr-   refuri#r~   r   )rd   todo_link_onlyr   sourcelinefindr   	paragraphTextemphasis	referencerw   get_relative_urir   )	r=   r>   r-   descriptionprefixsuffixparalinktextr   s	            r"   r   z'TodoListProcessor.create_todo_reference   s?   ;;%%01KRS KK34K 4k..t45[--d3a7897

6"" >>!$4"5q9I7JKOOBHtD		"&,,"?"?i"YIhh3eQ#77
 		

6""  		s   #8D: :	EEc                "   |j                  t        j                        D ]  }d|v s||d<    | xj                  |z  c_        | j                  j                  | j                  || j                         | j                  j                  |       y)z'Resolve references in the todo content.refdocN)r`   r
   pending_xrefr:   r6   resolve_referencesrw   r   )r=   r>   r-   r   s       r"   r   z#TodoListProcessor.resolve_reference   sq    LL!6!67 	)D4!(X	)
 	##DMM7DLLIT"r!   N)ra   r   r{   rm   r-   rj   rA   rk   )r{   rm   r-   rj   rA   rk   )r>   r   r-   rj   rA   znodes.paragraph)r>   r   r-   rj   rA   rk   )r   r   r   r|   rz   r   r   r    r!   r"   ru   ru   y   s    ''28	#r!   ru   c                r    | j                   j                  r| j                  |       y t        j                  rU   )rd   r   visit_admonitionr   SkipNoder=   r   s     r"   visit_todo_noder      s'    {{%%d#nnr!   c                &    | j                  |       y rU   )depart_admonitionr   s     r"   depart_todo_noder      s    4 r!   c                   | j                   j                  r| j                  j                  d       | j                  j                  | j	                  |             t        t        j                  |d         }t        j                  |j                         | j                   j                        }| j                  j                  d|z         |j                  d       y t        j                  )Nz 
\begin{sphinxadmonition}{note}{r   z%s:})rd   r   bodyrc   hypertarget_tor   r   r5   r   escaperh   latex_enginerV   r   )r=   r   
title_noder5   s       r"   latex_visit_todo_noder      s    {{%%		=>		,,T23%++tAw/
  !2!2!4dkk6N6NO		%(nnr!   c                :    | j                   j                  d       y )Nz\end{sphinxadmonition}
)r   rc   r   s     r"   latex_depart_todo_noder      s    II01r!   c           	     0   | j                  d       | j                  ddd       | j                  ddd       | j                  ddd       | j                  t               | j                  t        t
        t        ft        t        ft
        t        ft
        t        ft
        t        f       | j                  dt               | j                  d	t               | j                  t               | j                  d
t               t         j"                  dddS )Nr]   r   Fhtmlr   re   )r   latexr,   mantexinfor>   r%   zdoctree-resolvedr   T)versionenv_versionparallel_read_safe)	add_eventadd_config_valueadd_noder%   r   r   r   r   r   add_directiver'   rq   
add_domainrM   connectru   sphinx__display_version__)ra   s    r"   setupr      s    MM.!-uf=)5&9-uf=LLLL&(89-/EF&(89%'78)+;<  > fd#j(+NN:KK"$56--" r!   )r=   r   r   r   rA   rk   )r=   r   r   r   rA   rk   )ra   r   rA   zdict[str, Any])9rB   
__future__r   typingr   r   r   docutilsr   docutils.parsers.rstr   +docutils.parsers.rst.directives.admonitionsr	   r   r
   sphinx.domainsr   sphinx.errorsr   sphinx.localer   r   sphinx.utilr   r   sphinx.util.docutilsr   r   docutils.nodesr   r   sphinx.applicationr   sphinx.environmentr   sphinx.util.typingr   sphinx.writers.htmlr   sphinx.writers.latexr   	getLoggerr   rf   
Admonitionr   Generalr%   r'   rM   rq   ru   r   r   r   r   r   r    r!   r"   <module>r      s    # + +  + F   !   * >,)3-34			8	$	  %-- 		u}}emm 	>? B. .6 "H# H#V!
2r!   