
\c           @   s  d  Z  d d l Z d d l 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 r d d	 l m Z m Z m Z m Z m Z m Z d d
 l m Z d d l m Z n  e j d  Z e j d  Z  e j d  Z! e j d  Z" e j d  Z# e j d  Z$ e j d  Z% e j d  Z& d e f d     YZ' d e' f d     YZ( d S(   s   
    sphinx.ext.napoleon.docstring
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


    Classes for docstring parsing and formatting.


    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
iN(   t   partial(   t   string_typest   u(   t   range(   t   modify_iter(   t   _(   t   UnicodeMixin(   t   Anyt   Callablet   Dictt   Listt   Tuplet   Union(   t   Sphinx(   t   Configs
   \.\. \S+::s   ^(\s|\w)+:\s*$s   \s*(.+?)\s*\(\s*(.*[^\s]+)\s*\)s   ^[=\-`:\'"~^_*+#<>]{2,}\s*$s   (?<!:):(?!:)s.   (:(?:[a-zA-Z0-9]+[\-_+:.])*[a-zA-Z0-9]+:`.+?`)s   ^(\*|\+|\-)(\s+\S|\s*$)sP   ^(?P<paren>\()?(\d+|#|[ivxlcdm]+|[IVXLCDM]+|[a-zA-Z])(?(paren)\)|\.)(\s+\S|\s*$)t   GoogleDocstringc           B   s!  e  Z d  Z d< d< d d d< d< d  Z d   Z d   Z d d  Z d   Z d   Z	 e
 e d	  Z e
 e d
  Z d   Z d   Z d   Z d   Z d   Z d   Z e d  Z d   Z d   Z d   Z d< d  Z d d d  Z d   Z d   Z d d  Z d   Z d   Z d   Z d  d!  Z  d d"  Z! d#   Z" d$   Z# d%   Z$ d&   Z% d'   Z& d(   Z' d)   Z( d*   Z) d+   Z* d,   Z+ d-   Z, d.   Z- d/   Z. d0   Z/ d1   Z0 d2   Z1 d3   Z2 d4   Z3 d5   Z4 d6   Z5 d7   Z6 d8   Z7 d9   Z8 d:   Z9 d;   Z: RS(=   sV  Convert Google style docstrings to reStructuredText.

    Parameters
    ----------
    docstring : :obj:`str` or :obj:`list` of :obj:`str`
        The docstring to parse, given either as a string or split into
        individual lines.
    config: :obj:`sphinx.ext.napoleon.Config` or :obj:`sphinx.config.Config`
        The configuration settings to use. If not given, defaults to the
        config object on `app`; or if `app` is not given defaults to the
        a new :class:`sphinx.ext.napoleon.Config` object.


    Other Parameters
    ----------------
    app : :class:`sphinx.application.Sphinx`, optional
        Application object representing the Sphinx process.
    what : :obj:`str`, optional
        A string specifying the type of the object to which the docstring
        belongs. Valid values: "module", "class", "exception", "function",
        "method", "attribute".
    name : :obj:`str`, optional
        The fully qualified name of the object.
    obj : module, class, exception, function, method, or attribute
        The object to which the docstring belongs.
    options : :class:`sphinx.ext.autodoc.Options`, optional
        The options given to the directive: an object with attributes
        inherited_members, undoc_members, show_inheritance and noindex that
        are True if the flag option of same name was given to the auto
        directive.


    Example
    -------
    >>> from sphinx.ext.napoleon import Config
    >>> config = Config(napoleon_use_param=True, napoleon_use_rtype=True)
    >>> docstring = '''One line summary.
    ...
    ... Extended description.
    ...
    ... Args:
    ...   arg1(int): Description of `arg1`
    ...   arg2(str): Description of `arg2`
    ... Returns:
    ...   str: Description of return value.
    ... '''
    >>> print(GoogleDocstring(docstring, config))
    One line summary.
    <BLANKLINE>
    Extended description.
    <BLANKLINE>
    :param arg1: Description of `arg1`
    :type arg1: int
    :param arg2: Description of `arg2`
    :type arg2: str
    <BLANKLINE>
    :returns: Description of return value.
    :rtype: str
    <BLANKLINE>

    t    c   	      C   s  | |  _  | |  _ |  j  sO d d l m } |  j r@ |  j j pF |   |  _  n  | s t j |  rm d } q t j |  r d } q t | t	 j
  r d } q d } n  | |  _ | |  _ | |  _ | |  _ t | t  r | j   } n  | |  _ t | d d   |  _ g  |  _ t |  _ d	 |  _ t |  d
  sBg  |  _ n  t |  d  si |  j d 6|  j d 6t |  j d  d 6|  j d 6t |  j d  d 6t |  j d  d 6t |  j d  d 6|  j d 6|  j d 6t |  j d  d 6t |  j d  d 6|  j d 6|  j d 6|  j  d 6t |  j d  d 6|  j! d 6|  j" d 6|  j d 6|  j# d 6|  j# d 6|  j$ d  6|  j% d! 6|  j& d" 6t |  j d#  d# 6t |  j d$  d$ 6t |  j d%  d% 6t |  j d%  d& 6|  j' d' 6|  j( d( 6|  j( d) 6|  _) n  |  j*   |  j+   d  S(*   Ni(   R   t   classt   modulet   functiont   objectt   modifierc         S   s
   |  j    S(   N(   t   rstrip(   t   s(    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyt   <lambda>   s    i    t   _directive_sectionst	   _sectionst   argst	   argumentst	   attentiont
   attributest   cautiont   dangert   errort   examplet   examplest   hintt	   importants   keyword argss   keyword argumentst   methodst   notet   notess   other parameterst
   parameterst   returnt   returnst   raisest
   referencess   see alsot   tipt   todot   warningt   warningst   warnst   yieldt   yields(,   t   _configt   _appt   sphinx.ext.napoleonR   t   configt   inspectt   isclasst   ismodulet
   isinstancet   collectionsR   t   _whatt   _namet   _objt   _optR   t
   splitlinest   _linesR   t
   _line_itert   _parsed_linest   Falset   _is_in_sectiont   _section_indentt   hasattrR   t   _parse_parameters_sectionR    t   _parse_admonitiont   _parse_attributes_sectiont   _parse_examples_sectiont    _parse_keyword_arguments_sectiont   _parse_methods_sectiont   _parse_notes_sectiont   _parse_other_parameters_sectiont   _parse_returns_sectiont   _parse_raises_sectiont   _parse_references_sectiont   _parse_see_also_sectiont   _parse_warns_sectiont   _parse_yields_sectionR   t   _load_custom_sectionst   _parse(	   t   selft	   docstringR8   t   appt   whatt   namet   objt   optionsR   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyt   __init__l   sx    			$												


















c         C   s   t  d  j |  j    S(   s   Return the parsed docstring in reStructuredText format.

        Returns
        -------
        unicode
            Unicode version of the docstring.

        s   
(   R   t   joint   lines(   RZ   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyt   __unicode__   s    
c         C   s   |  j  S(   s   Return the parsed lines of the docstring in reStructuredText format.

        Returns
        -------
        list(str)
            The lines of the docstring in a list.

        (   RE   (   RZ   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRc      s    
i   c         C   sk   g  } |  j  j   } xO |  j   rf | s> |  j | |  rf | j t |  j    |  j  j   } q W| S(   N(   RD   t   peekt   _is_section_breakt   _is_indentedt   appendt   next(   RZ   t   indentRc   t   line(    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyt   _consume_indented_block   s    c         C   sR   g  } xE |  j  j   rM |  j  j   rM |  j   rM | j t |  j    q	 W| S(   N(   RD   t   has_nextRe   t   _is_section_headerRh   Ri   (   RZ   Rc   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyt   _consume_contiguous   s    c         C   s[   g  } |  j  j   } x? |  j  j   rV | rV | j t |  j    |  j  j   } q W| S(   N(   RD   Re   Rm   Rh   Ri   (   RZ   Rc   Rk   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyt   _consume_empty   s    c         C   s   t  |  j  } |  j |  \ } } } | d | } } }	 | rz t j |  }
 |
 rz |
 j d  } |
 j d  } qz n  |  j |  } | r | r | | } } n  |  j |  d } |	 g |  j |  j	 |   } |  j
 | |  j  j   } | | | f S(   NR   i   i   (   Ri   RD   t   _partition_field_on_colont   _google_typed_arg_regext   matcht   groupt   _escape_args_and_kwargst   _get_indentt   _dedentRl   t	   __class__R5   Rc   (   RZ   t
   parse_typet   prefer_typeRk   t   beforet   colont   afterR?   t   _typet   _descRs   Rj   t   _descs(    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyt   _consume_field   s    c         C   sm   |  j    g  } xV |  j   sh |  j | |  \ } } } | sL | sL | r | j | | | f  q q W| S(   N(   Rp   Rf   R   Rh   (   RZ   Ry   Rz   t   fieldsR?   R~   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyt   _consume_fields   s    
c         C   s~   t  |  j  } |  j |  \ } } } | s= | | } } n  | g |  j |  j    } |  j | |  j  j   } | | f S(   N(   Ri   RD   Rq   Rw   t   _consume_to_endRx   R5   Rc   (   RZ   Rk   R~   R|   R   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyt   _consume_inline_attribute  s    c         C   s   |  j  |  j    } | r |  j | d  \ } } } d d | } } } | r~ | rk | g | d } n
 | d } | } n  |  j | |  j  j   } | | | f g Sg  Sd  S(   Ni    R   i   (   Rw   t   _consume_to_next_sectionRq   Rx   R5   Rc   (   RZ   Rc   R{   R|   R}   R?   R~   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyt   _consume_returns_section  s    
	c         C   s   |  j  |  j    } | S(   N(   Rw   R   (   RZ   Rc   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyt   _consume_usage_section%  s    c         C   s@   t  |  j  } | j d  } | j   |  j k r< | } n  | S(   Nt   :(   Ri   RD   t   stript   lowerR   (   RZ   t   sectiont   stripped_section(    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyt   _consume_section_header*  s
    	c         C   s6   g  } x) |  j  j   r1 | j t |  j    q	 W| S(   N(   RD   Rm   Rh   Ri   (   RZ   Rc   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyR   2  s    c         C   sG   |  j    g  } x& |  j   s8 | j t |  j   q W| |  j    S(   N(   Rp   Rf   Rh   Ri   RD   (   RZ   Rc   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyR   9  s
    
c         C   sQ   | r# g  | D] } | j    ^ q S|  j |  } g  | D] } | | ^ q9 Sd  S(   N(   t   lstript   _get_min_indent(   RZ   Rc   t   fullRk   t
   min_indent(    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRw   A  s    c         C   s@   | d  d k r d | d S| d  d k r8 d | d S| Sd  S(   Ni   s   **s   \*\*i   t   *s   \*(    (   RZ   R^   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRu   I  s
    c         C   s   |  j  |  r d g | } n~ | d j d  r | d } |  j | d  } |  j |  } | | k rz d g | } q d | d g |  j | d  } n  | S(   Nu    i    s   ::i   R   i   (   t   _is_listt   endswithRv   t   _get_initial_indentt   _indent(   RZ   t   desct
   desc_blockRj   t   block_indent(    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyt   _fix_field_descR  s    
#c         C   s   |  j  |  } t |  d k r? d | | d j   f d g S| ry |  j |  j |  d  } d | d g | d g Sd | d g Sd  S(   Ni   s
   .. %s:: %si    R   i   u   .. %s::u    (   t   _strip_emptyt   lenR   R   Rw   (   RZ   t
   admonitionRc   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyt   _format_admonition`  s    c         C   s   | r | d  k r% d t |  } n  g  } xg t |  D]Y \ } } | d k rj | j | | j    q8 | r | j | |  q8 | j d  q8 W| S| g Sd  S(   Nt    i    R   (   t   NoneR   t	   enumerateRh   R   (   RZ   t   prefixRc   t   paddingt   result_linest   iRk   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyt   _format_blockk  s    t   paramt   typec   	      C   s   g  } x | D] \ } } } |  j  |  } t |  rr |  j |  } d | | f } | j |  j | |   n | j d | | f  | r | j d | | | f  q q W| d g S(   Ns   :%s %s: s   :%s %s:s
   :%s %s: %sR   (   R   t   anyR   t   extendR   Rh   (	   RZ   R   t
   field_rolet	   type_roleRc   R?   R~   R   t   field(    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyt   _format_docutils_params|  s    !c         C   s  |  j  |  } t |  } | r' d p* d } | r | rq d | k r[ d | | | f } q d | | | f } q d | | f } n> | r d | k r d | | f } q d | | f } n d } | r|  j |  } | d	 r | | d	 g | d
 S| g | Sn | g Sd  S(   Ns    -- R   t   `s   **%s** (%s)%ss   **%s** (*%s*)%ss   **%s**%ss   %s%ss   *%s*%si    i   (   R   R   R   (   RZ   R?   R~   R   t   has_desct	   separatorR   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyt   _format_field  s(    
c   
      C   s   d | j    } d t |  } t |  d k } g  } x | D] \ } } } |  j | | |  }	 | r | r | j |  j | d |	   q | j |  j | d |	   q? | j |  j | d |	   q? W| r | d r | j d  n  | S(   Ns   :%s:R   i   s    * iR   (   R   R   R   R   R   Rh   (
   RZ   t
   field_typeR   R   t   multiRc   R?   R~   R   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyt   _format_fields  s      !i    c         C   sn   |  j  j | d  | } xM | |  j  j k ri | rB |  j |  S| d 7} |  j  j | d  | } q Wd S(   Ni   i    (   RD   Re   t   sentinelRv   (   RZ   t
   peek_aheadRk   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyt   _get_current_indent  s    
c         C   s7   x* t  |  D] \ } } | j   s | Sq Wt |  S(   N(   R   t   isspaceR   (   RZ   Rk   R   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRv     s    c         C   s(   x! | D] } | r |  j  |  Sq Wd S(   Ni    (   Rv   (   RZ   Rc   Rk   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyR     s    c         C   sc   d  } xP | D]H } | r |  j |  } | d  k r= | } qU | | k  rU | } qU q q W| pb d S(   Ni    (   R   Rv   (   RZ   Rc   R   Rk   Rj   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyR     s    	i   c         C   s   g  | D] } d | | ^ q S(   NR   (    (   RZ   Rc   t   nRk   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyR     s    c         C   sA   x: t  |  D], \ } } | | k r) t S| j   s t Sq Wt S(   N(   R   t   TrueR   RF   (   RZ   Rk   Rj   R   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRg     s    c         C   s   | s
 t  St j | d  r! t St j | d  r8 t St |  d k  s] | d j d  ra t  S|  j | d  } | } x+ | d D] } | r |  j |  } Pq q W| | k S(   Ni    i   s   ::i   (   RF   t   _bullet_list_regexRs   R   t   _enumerated_list_regexR   R   Rv   (   RZ   Rc   Rj   t   next_indentRk   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyR     s    %c         C   s   |  j  j   j   } t j |  } | rm | j d  |  j k rm |  j |  } |  j d d  } | | k S|  j	 r t
 j |  r x' |  j	 D] } | j |  r t Sq Wq n  t S(   NR   R   i   (   RD   Re   R   t   _google_section_regexRs   R   R   Rv   R   R   t   _directive_regext
   startswithR   RF   (   RZ   R   Rs   t   header_indentt   section_indentt   directive_section(    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRn     s    
	c         C   sN   |  j  j   } |  j  j   pM |  j   pM |  j oM | oM |  j | |  j  S(   N(   RD   Re   Rm   Rn   RG   Rg   RH   (   RZ   Rk   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRf     s    	c         C   s   |  j  j d  k	 r xr |  j  j D]a } t | t  rM |  j |  j | j   <q |  j j | d j   |  j  |  j | d j   <q Wn  d  S(   Ni   i    (	   R5   t   napoleon_custom_sectionsR   R<   R   t   _parse_custom_generic_sectionR   R   t   get(   RZ   t   entry(    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRX     s    c         C   sW  |  j    |  _ |  j rt |  j d k s6 |  j d k rt g  } y |  j   } Wn t k
 r_ n X|  j j |  d  Sx |  j j   rR|  j	   rzf |  j
   } t |  _ |  j   |  _ t j |  r | g |  j   } n |  j | j   |  } Wd  t |  _ d |  _ Xn. |  j s3|  j   |  j    } n |  j   } |  j j |  qw Wd  S(   Nt	   attributet   datai    (   Rp   RE   R?   R>   t   _parse_attribute_docstringt   StopIterationR   RD   Rm   Rn   R   R   RG   R   RH   R   Rs   R   R   R   RF   Ro   (   RZ   t   resR   Rc   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRY   *  s0    '			c         C   s   |  j    } |  j | |  S(   N(   R   R   (   RZ   R   R   Rc   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRK   M  s    c         C   sK   |  j    \ } } |  j d d |  } | rG | j d d | g  n  | S(   NR   s	   :type: %s(   R   R   R   (   RZ   R~   R   Rc   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyR   R  s
    c         C   s   g  } x |  j    D] \ } } } |  j j rt d | } | j |  j | |   | r | j d | | f  q q | j d | d g  |  j d d |  } | j |  j | d   | r | j d  | j |  j d | g d   n  | j d  q W|  j j r| j d  n  | S(   Ns
   :ivar %s: s   :vartype %s: %ss   .. attribute:: R   i   s	   :type: %s(   R   R5   t   napoleon_use_ivarR   R   Rh   R   R   (   RZ   R   Rc   R?   R~   R   R   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRL   Z  s"    
#c         C   sT   i t  d  d 6t  d  d 6} |  j j } | j | j   |  } |  j | |  S(   Nt   ExampleR"   t   ExamplesR#   (   R   R5   t$   napoleon_use_admonition_for_examplesR   R   t   _parse_generic_section(   RZ   R   t   labelst   use_admonitiont   label(    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRM   o  s    c         C   s   |  j  | t  S(   N(   R   RF   (   RZ   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyR   y  s    c         C   sI   d d g } d d g } |  j    } |  j | d  } | | | d g S(   Ns   .. rubric:: Usage:R   s   .. code-block:: pythoni   (   R   R   (   RZ   R   t   headert   blockRc   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyt   _parse_usage_section}  s
    c         C   s|   |  j  |  j    } |  j |  } | rI d | } |  j | d  } n
 d | } | rn | d g | d g S| d g Sd  S(   Ns   .. admonition:: %si   s   .. rubric:: %sR   (   R   R   Rw   R   (   RZ   R   R   Rc   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyR     s    

c         C   sK   |  j    } |  j j r1 |  j | d d d d S|  j t d  |  Sd  S(   NR   t   keywordR   t   kwtypes   Keyword Arguments(   R   R5   t   napoleon_use_keywordR   R   R   (   RZ   R   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRN     s    c         C   sw   g  } xj |  j  d t  D]V \ } } } | j d |  | rb | j d g |  j | d   n  | j d  q W| S(   NRy   s   .. method:: %su    i   R   (   R   RF   Rh   R   R   (   RZ   R   Rc   R?   R~   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRO     s    "#c         C   s"   |  j  j } |  j t d  |  S(   Nt   Notes(   R5   t!   napoleon_use_admonition_for_notesR   R   (   RZ   R   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRP     s    c         C   s   |  j  t d  |  j    S(   Ns   Other Parameters(   R   R   R   (   RZ   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRQ     s    c         C   s?   |  j    } |  j j r% |  j |  S|  j t d  |  Sd  S(   Nt
   Parameters(   R   R5   t   napoleon_use_paramR   R   R   (   RZ   R   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRJ     s    c         C   s  |  j  d t d t  } d } d t |  } t |  d k } g  } xe| D]]\ } } }	 |  j |	  }	 t |	  }
 |
 r d p d } | r;d | k p d	 | k } t d
   | D  } | r | r d | | f } n/ |
 r | r d | | f } n d | | f } |
 r/| |	 d g |	 d } qA| g } n |	 } | r| rm| j |  j | d |   q| j |  j | d |   qM | j |  j | d |   qM W| r| d r| j d  n  | S(   NRy   Rz   s   :raises:R   i   s    -- R   R   R   c         s   s   |  ] } | d  k Vq d S(   s    	
 N(    (   t   .0t   c(    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pys	   <genexpr>  s    s   :exc:`%s`%ss   *%s*%ss   %s%si    s    * i(	   R   RF   R   R   R   R   R   R   Rh   (   RZ   R   R   R   R   R   Rc   R?   R~   R   R   R   t   has_refst	   has_spaceR   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRS     s:      !c         C   s"   |  j  j } |  j t d  |  S(   Nt
   References(   R5   t&   napoleon_use_admonition_for_referencesR   R   (   RZ   R   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRT     s    c   
      C   s3  |  j    } t |  d k } | r- t } n |  j j } g  } x | D] \ } } } | rs |  j | d |  }	 n |  j | | |  }	 | r | r | j |  j d |	   q| j |  j d |	   qF | j |  j d |	   | rF | rF | j d | d g  qF qF W| r/| d r/| j d  n  | S(   Ni   R   s             * s   :returns: * s
   :returns: s
   :rtype: %si(	   R   R   RF   R5   t   napoleon_use_rtypeR   R   R   Rh   (
   RZ   R   R   R   t	   use_rtypeRc   R?   R~   R   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRR     s(    	c         C   s   |  j  d |  S(   Nt   seealso(   RK   (   RZ   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRU     s    c         C   s   |  j  t d  |  j    S(   Nt   Warns(   R   R   R   (   RZ   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRV     s    c         C   s"   |  j    } |  j t d  |  S(   Nt   Yields(   R   R   R   (   RZ   R   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRW   
  s    c   	      C   s  g  } g  } d } t  } x t t j |   D] \ } } | rP | j |  q. t j |  } | d d k r | r t } | | j   | j	   !} | j | | j     | j | | j	    q. | j |  q. Wd j
 |  j   | d j
 |  j   f S(   NR   i   i    (   RF   R   t   _xref_regext   splitRh   t   _single_colon_regext   searchR   t   startt   endRb   R   (	   RZ   Rk   t   before_colont   after_colonR|   t   found_colonR   t   sourcet   m(    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRq     s"    "c         C   s   | r d } x* t  |  D] \ } } | r | } Pq q W| d k rN g  } n  d } x: t t t |    D]  } | | } | rm | } Pqm qm W| d k s | d t |  k  r | | | d !} q n  | S(   Nii    i   (   R   t   reversedR   R   (   RZ   Rc   R   R   Rk   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyR   &  s"    	
"N(;   t   __name__t
   __module__t   __doc__R   Ra   Rd   Rc   Rl   Ro   Rp   R   RF   R   R   R   R   R   R   R   R   Rw   Ru   R   R   R   R   R   R   R   Rv   R   R   R   Rg   R   Rn   Rf   RX   RY   RK   R   RL   RM   R   R   R   RN   RO   RP   RQ   RJ   RS   RT   RR   RU   RV   RW   Rq   R   (    (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyR   .   sp   =F		
				
	
											
										#				
					
				'						t   NumpyDocstringc           B   s   e  Z d  Z d d d d d d d  Z e e d  Z d   Z d   Z	 d   Z
 d   Z e j d e j  Z d	   Z d
   Z RS(   s
  Convert NumPy style docstrings to reStructuredText.

    Parameters
    ----------
    docstring : :obj:`str` or :obj:`list` of :obj:`str`
        The docstring to parse, given either as a string or split into
        individual lines.
    config: :obj:`sphinx.ext.napoleon.Config` or :obj:`sphinx.config.Config`
        The configuration settings to use. If not given, defaults to the
        config object on `app`; or if `app` is not given defaults to the
        a new :class:`sphinx.ext.napoleon.Config` object.


    Other Parameters
    ----------------
    app : :class:`sphinx.application.Sphinx`, optional
        Application object representing the Sphinx process.
    what : :obj:`str`, optional
        A string specifying the type of the object to which the docstring
        belongs. Valid values: "module", "class", "exception", "function",
        "method", "attribute".
    name : :obj:`str`, optional
        The fully qualified name of the object.
    obj : module, class, exception, function, method, or attribute
        The object to which the docstring belongs.
    options : :class:`sphinx.ext.autodoc.Options`, optional
        The options given to the directive: an object with attributes
        inherited_members, undoc_members, show_inheritance and noindex that
        are True if the flag option of same name was given to the auto
        directive.


    Example
    -------
    >>> from sphinx.ext.napoleon import Config
    >>> config = Config(napoleon_use_param=True, napoleon_use_rtype=True)
    >>> docstring = '''One line summary.
    ...
    ... Extended description.
    ...
    ... Parameters
    ... ----------
    ... arg1 : int
    ...     Description of `arg1`
    ... arg2 : str
    ...     Description of `arg2`
    ... Returns
    ... -------
    ... str
    ...     Description of return value.
    ... '''
    >>> print(NumpyDocstring(docstring, config))
    One line summary.
    <BLANKLINE>
    Extended description.
    <BLANKLINE>
    :param arg1: Description of `arg1`
    :type arg1: int
    :param arg2: Description of `arg2`
    :type arg2: str
    <BLANKLINE>
    :returns: Description of return value.
    :rtype: str
    <BLANKLINE>

    Methods
    -------
    __str__()
        Return the parsed docstring in reStructuredText format.

        Returns
        -------
        str
            UTF-8 encoded version of the docstring.

    __unicode__()
        Return the parsed docstring in reStructuredText format.

        Returns
        -------
        unicode
            Unicode version of the docstring.

    lines()
        Return the parsed lines of the docstring in reStructuredText format.

        Returns
        -------
        list(str)
            The lines of the docstring in a list.

    R   c         C   s8   d g |  _  t t |   j | | | | | | |  d  S(   Ns
   .. index::(   R   t   superR   Ra   (   RZ   R[   R8   R\   R]   R^   R_   R`   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRa     s    c   	      C   s   t  |  j  } | r0 |  j |  \ } } } n | d } } | j   | j   } } |  j |  } | r | r | | } } n  |  j |  d } |  j |  j |   } |  j | |  j	  j
   } | | | f S(   NR   i   (   Ri   RD   Rq   R   Ru   Rv   Rw   Rl   Rx   R5   Rc   (	   RZ   Ry   Rz   Rk   R?   R   R~   Rj   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyR     s    c         C   s   |  j  d t  S(   NRz   (   R   R   (   RZ   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyR     s    c         C   s2   t  |  j  } t j |  s. t  |  j  n  | S(   N(   Ri   RD   R   Rs   (   RZ   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyR     s    c         C   so   |  j  j d  \ } } |  j  j   pn |  j   pn d d g | | g k pn |  j on | on |  j | |  j  S(   Ni   R   (   RD   Re   Rm   Rn   RG   Rg   RH   (   RZ   t   line1t   line2(    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRf     s    	c         C   s   |  j  j d  \ } } | j   } | |  j k rU t | t  rU t t j |   S|  j	 r t
 j |  r x' |  j	 D] } | j |  rw t Sqw Wq n  t S(   Ni   (   RD   Re   R   R   R<   R   t   boolt   _numpy_section_regexRs   R   R   R   R   RF   (   RZ   R   t	   underlineR   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRn     s    	sO   ^\s*(:(?P<role>\w+):`(?P<name>[a-zA-Z0-9_.-]+)`| (?P<name2>[a-zA-Z0-9_.-]+))\s*c         C   sB   |  j    } y |  j |  SWn t k
 r= |  j d |  SXd  S(   NR   (   R   t    _parse_numpydoc_see_also_sectiont
   ValueErrorR   (   RZ   R   Rc   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyRU     s
    c            s;  g     f d       f d   } d } g  } x[| D]S} | j   sR q: n   j j |  } | r | | j   j   j d  r | | |  | | j    | | j   } } | j d d  d j   g } | d sg  } qq: | j d  sk| | |  d } d | k rSxK | j d  D]" } | j   r*| | g   q*q*Wq| j   r| } qq: | d k	 r: | j | j    q: q: W| | |    sg  Si d d	 6d d 6d
 d 6d
 d
 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6}  j d k r6d }	 n | j	  j d  }	 g  }
 t
 } x   D] \ } } } | rd | | f } n# |	 rd |	 | f } n
 d | } | s| r|
 d g 7}
 |
 | g 7}
 n |
 d c d | 7<| r|
  j d j |  g  7}
 t
 } q^t } q^W|
 d g 7}
  j d |
  S(   s  
        Derived from the NumpyDoc implementation of _parse_see_also.

        See Also
        --------
        func_name : Descriptive text
            continued text
        another_func_name : Descriptive text
        func_name1, func_name2, :meth:`func_name`, func_name3

        c            sk     j  j |   } | rW | j   } | d d k rB | d d f S| d | d f Sn  t d |    d S(   s   Match ':role:`name`' or 'name'i   i   i   s   %s is not a item nameN(   t	   _name_rgxRs   t   groupsR   R  (   t   textR   t   g(   RZ   (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyt   parse_item_name  s    c            s@   |  s
 d  S |   \ }  }   j  |  t |  | f  | 2d  S(   N(   Rh   t   list(   R^   t   restt   role(   t   itemsR  (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyt	   push_item  s
    R   i   i    R   t   ,t   metht   methodt   funcR   R   t   exct	   exceptionR_   R   t   modR   R   t   constt   constantt   attrR   R   s   :%s:`%s`s   `%s`_is   , %sR   N(   R   R   R  Rs   R   R   R   Rh   R>   R   R   R   Rb   RF   R   (   RZ   t   contentR  t   current_funcR
  Rk   R   R  t   rolest	   func_roleRc   t   last_had_descR   R  t   link(    (   R  R  RZ   s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyR    s    %!

	
	
N(   R   R   R   R   Ra   R   RF   R   R   R   Rf   Rn   t   ret   compilet   XR  RU   R  (    (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyR   ;  s   \			
			()   R   R=   R9   R  t	   functoolsR    t   sixR   R   t	   six.movesR   t   sphinx.ext.napoleon.iteratorsR   t   sphinx.localeR   t   sphinx.util.pycompatR   RF   t   typingR   R   R	   R
   R   R   t   sphinx.applicationR   t   sphinx.configR   t   SphinxConfigR  R   R   Rr   R   R   R   R   R   R   R   (    (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/docstring.pyt   <module>   s6   .	   