U
    \Sh%                     @  s<  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 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mZ d dlmZ d dlmZmZ d dlmZ ee Z!ddddddddddddgZ"ddddgZ#G dd de$Z%G dd dZ&ddd d!d"d#d$Z'd%d&d'd(d)d*d+Z(G d,d- d-eZ)d.S )/    )annotations)AnyCallable)nodes)ElementNode)RSTState)
StringList)Reporterassemble_option_dict)Config)BuildEnvironment)
DocumenterOptions)logging)SphinxDirectiveswitch_source_input)nested_parse_with_titlesmemberszundoc-memberszinherited-memberszshow-inheritancezprivate-memberszspecial-memberszignore-module-allzexclude-memberszmember-orderzimported-memberszclass-doc-fromzno-valuec                   @  s.   e Zd ZdZddddZdddd	d
ZdS )DummyOptionSpecz"An option_spec allows any options.boolreturnc                 C  s   dS )z&Behaves like some options are defined.T )selfr   r   O/root/rtd-docs/venv/lib/python3.8/site-packages/sphinx/ext/autodoc/directive.py__bool__"   s    zDummyOptionSpec.__bool__strzCallable[[str], str])keyr   c                 C  s   dd S )Nc                 S  s   | S Nr   )xr   r   r   <lambda>'       z-DummyOptionSpec.__getitem__.<locals>.<lambda>r   )r   r   r   r   r   __getitem__&   s    zDummyOptionSpec.__getitem__N)__name__
__module____qualname____doc__r   r#   r   r   r   r   r      s   r   c                   @  s(   e Zd ZdZdddddddd	d
ZdS )DocumenterBridgez'A parameters container for Documenters.r   zReporter | Noner   intr   None)envreporteroptionslinenostater   c                 C  s2   || _ || _|| _|| _t | _t | _|| _d S r   )	r+   Z	_reporterZgenoptr.   setrecord_dependenciesr	   resultr/   )r   r+   r,   r-   r.   r/   r   r   r   __init__-   s    zDocumenterBridge.__init__N)r$   r%   r&   r'   r3   r   r   r   r   r(   *   s   r(   ztype[Documenter]r   dictr   )
documenterconfigr-   r   c                 C  s   t D ]}|| jkrq|d| ddk}||jkr|s||krt|j| tr|tkr|| dk	r|| drd|j| || dd g||< q|j| ||< q|	|dk	r|| 
d||< qtt| | jS )z0Recognize options of Documenter from user input.zno-TN+,   )AUTODOC_DEFAULT_OPTIONSoption_specpopZautodoc_default_options
isinstancer   AUTODOC_EXTENDABLE_OPTIONS
startswithjoingetlstripr   r   items)r5   r6   r-   nameZnegatedr   r   r   process_documenter_options8   s    
rE   r   r	   r   
list[Node])r/   contentr5   r   c              
   C  sj   t | |V |jr0t }| j|_t| || nt }| j|_| |d| |jW  5 Q R  S Q R X dS )z1Parse an item of content generated by Documenter.r   N)	r   Ztitles_allowedr   sectiondocumentr   Z	paragraphZnested_parsechildren)r/   rG   r5   noder   r   r   parse_generated_contentQ   s    rL   c                   @  s4   e Zd ZdZe ZdZdZdZdZ	ddddZ
d	S )
AutodocDirectivezA directive class for all autodoc directives. It works as a dispatcher of Documenters.

    It invokes a Documenter upon running. After the processing, it parses and returns
    the content generated by Documenter.
    Tr9   r   rF   r   c              
   C  sX  | j jj}z|| j\}}W n tk
r:   d\}}Y nX td||| j | j	dd  }| j
jjj| }zt|| j| j}W nP tttfk
r } z,tjd| j	|f | j
j|fd g  W Y S d }~X Y nX t| j
|||| j }||| jd }	|	j| jd |jsg S tdd	|j |jD ]}
| j jjj|
 q*t| j |j|	}|S )
N)NNz[autodoc] %s:%s: input:
%s   z=An option to %s is either unknown or has an invalid value: %s)locationr   )Zmore_contentz[autodoc] output:
%s
) r/   rI   r,   Zget_source_and_liner.   AttributeErrorloggerdebugZ
block_textrD   r+   ZappregistryZdocumentersrE   r6   r-   KeyError
ValueError	TypeErrorerrorZdocnamer(   	argumentsgeneraterG   r2   r@   r1   settingsaddrL   )r   r,   sourcer.   objtypeZdocclsZdocumenter_optionsexcparamsr5   fnr2   r   r   r   runn   s6    


zAutodocDirective.runN)r$   r%   r&   r'   r   r;   Zhas_contentZrequired_argumentsZoptional_argumentsZfinal_argument_whitespacerb   r   r   r   r   rM   b   s   rM   N)*
__future__r   typingr   r   Zdocutilsr   Zdocutils.nodesr   r   Zdocutils.parsers.rst.statesr   Zdocutils.statemachiner	   Zdocutils.utilsr
   r   Zsphinx.configr   Zsphinx.environmentr   Zsphinx.ext.autodocr   r   Zsphinx.utilr   Zsphinx.util.docutilsr   r   Zsphinx.util.nodesr   	getLoggerr$   rR   r:   r>   r4   r   r(   rE   rL   rM   r   r   r   r   <module>   s@   
      