B
    \                 @   s   d 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 eeZd	d
ddddddgZG dd deZG dd deZdd Zdd ZG dd deZdS )z
    sphinx.ext.autodoc.directive
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    :copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
    )nodes)ViewList)assemble_option_dict)Optionsget_documenters)logging)SphinxDirectiveswitch_source_input)nested_parse_with_titlesmemberszundoc-memberszinherited-memberszshow-inheritancezprivate-memberszspecial-memberszignore-module-allzexclude-membersc               @   s   e Zd ZdZdd ZdS )DummyOptionSpecz"An option_spec allows any options.c             C   s   dd S )Nc             S   s   | S )N )xr   r   ;lib/python3.7/site-packages/sphinx/ext/autodoc/directive.py<lambda>*   s    z-DummyOptionSpec.__getitem__.<locals>.<lambda>r   )selfkeyr   r   r   __getitem__(   s    zDummyOptionSpec.__getitem__N)__name__
__module____qualname____doc__r   r   r   r   r   r   %   s   r   c               @   s    e Zd ZdZdd Zdd ZdS )DocumenterBridgez'A parameters container for Documenters.c             C   s,   || _ || _|| _|| _t | _t | _d S )N)envreporterZgenoptlinenosetfilename_setr   result)r   r   r   optionsr   r   r   r   __init__0   s    zDocumenterBridge.__init__c             C   s   t j|| jj| jfd d S )N)location)loggerZwarningr   Zdocnamer   )r   msgr   r   r   warn9   s    zDocumenterBridge.warnN)r   r   r   r   r    r$   r   r   r   r   r   -   s   	r   c             C   s`   xJt D ]B}|| jkrqq|d| ddk}||jkr|s|j| ||< qW tt| | jS )z0Recognize options of Documenter from user input.zno-TN)AUTODOC_DEFAULT_OPTIONSoption_specpopZautodoc_default_optionsr   r   items)
documenterconfigr   nameZnegatedr   r   r   process_documenter_options>   s    

r,   c          	   C   s^   t | |J |jr0t }| j|_t| || nt }| j|_| |d| |jS Q R X dS )z(Parse a generated content by Documenter.r   N)	r	   Ztitles_allowedr   Zsectiondocumentr
   Z	paragraphZnested_parseZchildren)statecontentr)   Znoder   r   r   parse_generated_contentL   s    r0   c               @   s.   e Zd ZdZe ZdZdZdZdZ	dd Z
dS )AutodocDirectivezA directive class for all autodoc directives. It works as a dispatcher of Documenters.

    It invokes a Documenter on running. After the processing, it parses and returns
    the generated content by Documenter.
    T   r   c          
   C   sL  | j jj}y|| j\}}W n tk
r:   d\}}Y nX td||| j | j	dd  }t
| jj| }yt|| j| j}W nD tttfk
r } z tjd| j	|f ||fd g S d }~X Y nX t| j|||}||| jd }	|	j| jd |js g S tdd	|j x"|jD ]}
| j jjj|
 qW 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)r!   r   )Zmore_contentz[autodoc] output:
%s
)r.   r-   r   Zget_source_and_liner   AttributeErrorr"   debugZ
block_textr+   r   r   Zappr,   r*   r   KeyError
ValueError	TypeErrorerrorr   Z	argumentsZgenerater/   r   joinr   ZsettingsZrecord_dependenciesaddr0   )r   r   sourcer   ZobjtypeZdocclsZdocumenter_optionsexcZparamsr)   fnr   r   r   r   runi   s0    
zAutodocDirective.runN)r   r   r   r   r   r&   Zhas_contentZrequired_argumentsZoptional_argumentsZfinal_argument_whitespacer@   r   r   r   r   r1   ]   s   r1   N)r   Zdocutilsr   Zdocutils.statemachiner   Zdocutils.utilsr   Zsphinx.ext.autodocr   r   Zsphinx.utilr   Zsphinx.util.docutilsr   r	   Zsphinx.util.nodesr
   Z	getLoggerr   r"   r%   objectr   r   r,   r0   r1   r   r   r   r   <module>   s    
