B
    \
                 @   sf   d Z ddlmZ ddlZddlmZ ddlmZ G dd dejZ	G dd	 d	eZ
d
d Zdd ZdS )a  
    sphinx.ext.ifconfig
    ~~~~~~~~~~~~~~~~~~~

    Provides the ``ifconfig`` directive that allows to write documentation
    that is included depending on configuration variables.

    Usage::

        .. ifconfig:: releaselevel in ('alpha', 'beta', 'rc')

           This stuff is only included in the built docs for unstable versions.

    The argument for ``ifconfig`` is a plain Python expression, evaluated in the
    namespace of the project configuration (that is, all variables from
    ``conf.py`` are available.)

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
    )nodesN)SphinxDirective)set_source_infoc               @   s   e Zd ZdS )ifconfigN)__name__
__module____qualname__ r	   r	   2lib/python3.7/site-packages/sphinx/ext/ifconfig.pyr   #   s   r   c               @   s(   e Zd ZdZdZdZdZi Zdd ZdS )IfConfigT   r   c             C   sF   t  }| jj|_t| | | jd |d< | jj| j| j|dd |gS )Nr   exprr   )Zmatch_titles)r   stateZdocumentr   Z	argumentsZnested_parseZcontentZcontent_offset)selfnoder	   r	   r
   run/   s    


zIfConfig.runN)	r   r   r   Zhas_contentZrequired_argumentsZoptional_argumentsZfinal_argument_whitespaceZoption_specr   r	   r	   r	   r
   r   '   s   r   c       
      C   s   t dd | jD }|| jj  | jj|d< x|tD ]}yt	|d |}W n^ t
k
r } z@ddlm} d||j|}|jjd| |d	}	||	 W d d }~X Y q>X |s|g  q>||j q>W d S )
Nc             s   s   | ]}|j |jfV  qd S )N)namevalue).0Zconfvalr	   r	   r
   	<genexpr><   s    z)process_ifconfig_nodes.<locals>.<genexpr>builderr   r   )format_exception_only z-Exception occured in ifconfig expression: 
%s)Z	base_node)dictZconfigupdate__dict__copyr   r   Ztraverser   eval	Exception	tracebackr   join	__class__ZreportererrorZreplace_selfZchildren)
appZdoctreeZdocnamensr   Zreserrr   msgZnewnoder	   r	   r
   process_ifconfig_nodes:   s    r'   c             C   s.   |  t | dt | dt tjddS )Nr   zdoctree-resolvedT)versionZparallel_read_safe)Zadd_noder   Zadd_directiver   Zconnectr'   sphinxZ__display_version__)r#   r	   r	   r
   setupQ   s    
r*   )__doc__Zdocutilsr   r)   Zsphinx.util.docutilsr   Zsphinx.util.nodesr   ZElementr   r   r'   r*   r	   r	   r	   r
   <module>   s   