
(*\c           @` s  d  Z  d d l m Z m Z m Z d d l Z d d l Z d d l Z d d l Z d d l	 m
 Z
 d d l m Z y d d l m Z m Z Wn' e k
 r d d l m Z m Z n Xd d l Z d d l Z d d l m Z d   Z d	 e f d
     YZ d e f d     YZ e d d d d g  Z d e f d     YZ d d  Z d   Z d d  Z d e f d     YZ d e f d     YZ  d S(   s=   Extract reference documentation from the NumPy source tree.

i    (   t   divisiont   absolute_importt   print_functionN(   t   warn(   t
   namedtuple(   t   Callablet   Mapping(   t   ALLc         C` sN   x" |  r$ |  d j    r$ |  d =q Wx" |  rI |  d j    rI |  d =q( W|  S(   s<   Remove leading and trailing blank lines from a list of linesi    i(   t   strip(   t   l(    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   strip_blank_lines   s
    t   Readerc           B` st   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
 d  Z d   Z RS(   s!   A line-based string reader.

    c         C` s;   t  | t  r | |  _ n | j d  |  _ |  j   d S(   sr   
        Parameters
        ----------
        data : str
           String with lines separated by '
'.

        s   
N(   t
   isinstancet   listt   _strt   splitt   reset(   t   selft   data(    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   __init__"   s    c         C` s   |  j  | S(   N(   R   (   R   t   n(    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   __getitem__1   s    c         C` s   d |  _  d  S(   Ni    (   t   _l(   R   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyR   4   s    c         C` s4   |  j    s, |  |  j } |  j d 7_ | Sd Sd  S(   Ni   t    (   t   eofR   (   R   t   out(    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   read7   s
    c         C` s;   x4 |  |  j  D]% } | j   r$ Pq |  j  d 7_  q Wd  S(   Ni   (   R   R   (   R   R	   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   seek_next_non_empty_line?   s    c         C` s   |  j  t |  j  k S(   N(   R   t   lenR   (   R   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyR   F   s    c         C` si   |  j  } xY |  | D]M } | |  r4 |  | |  j  !S|  j  d 7_  |  j   r |  | |  j  d !Sq Wg  S(   Ni   (   R   R   (   R   t   condition_funct   startt   line(    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   read_to_conditionI   s    	c         C` s    |  j    d   } |  j |  S(   Nc         S` s   |  j    S(   N(   R   (   R   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   is_emptyV   s    (   R   R    (   R   R!   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   read_to_next_empty_lineS   s    
	c         C` s   d   } |  j  |  S(   Nc         S` s(   |  j    o' t |  j    t |   k S(   N(   R   R   t   lstrip(   R   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   is_unindented\   s    (   R    (   R   R$   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   read_to_next_unindented_line[   s    	i    c         C` s3   |  j  | t |  j  k  r+ |  |  j  | Sd Sd  S(   NR   (   R   R   R   (   R   R   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   peek`   s    c         C` s   d j  |  j  j   S(   NR   (   t   joinR   R   (   R   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyR!   f   s    (   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R    R"   R%   R&   R!   (    (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyR      s   							
		t
   ParseErrorc           B` s   e  Z d    Z RS(   c         C` s6   |  j  d } t |  d  r2 d | |  j f } n  | S(   Ni    t	   docstrings   %s in %r(   t   argst   hasattrR,   (   R   t   message(    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   __str__k   s    (   R(   R)   R0   (    (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyR+   j   s   t	   Parametert   namet   typet   desct   NumpyDocStringc           B` s&  e  Z d  Z i d d 6d g d 6g  d 6g  d 6g  d 6g  d 6g  d 6g  d	 6g  d
 6g  d 6g  d 6g  d 6g  d 6g  d 6g  d 6d d 6d d 6i  d 6Z i  d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z e d  Z d Z d Z d  Z d! e e d" e d# Z e j d$ d%  Z e j d& d'  Z d( Z e j d) e d*  Z e j dA e d, e d- d# d. e  Z d/ Z d0   Z d1   Z d2   Z d3   Z e d4  Z  d5 d6  Z! d7 d8  Z" d9   Z# d:   Z$ d;   Z% d<   Z& d=   Z' d>   Z( d?   Z) d d@  Z* RS(B   s   Parses a numpydoc string to an abstract representation

    Instances define a mapping from section title to structured data.

    R   t	   Signaturet   Summarys   Extended Summaryt
   Parameterst   Returnst   Yieldst   Receivest   Raisest   Warnss   Other Parameterst
   Attributest   Methodss   See Alsot   Notest   Warningst
   Referencest   Examplest   indexc         C` sv   | } t  j |  j d  } t |  |  _ t j |  j  |  _ y |  j	   Wn t
 k
 rq } | | _   n Xd  S(   Ns   
(   t   textwrapt   dedentR   R   t   _doct   copyt   deepcopyt   sectionst   _parsed_datat   _parseR+   R,   (   R   R,   t   configt   orig_docstringt   e(    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyR      s    	c         C` s   |  j  | S(   N(   RK   (   R   t   key(    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyR      s    c         C` s:   | |  j  k r) |  j d | d t n | |  j  | <d  S(   Ns   Unknown section %st   error(   RK   t   _error_locationt   False(   R   RP   t   val(    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   __setitem__   s    c         C` s   t  |  j  S(   N(   t   iterRK   (   R   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   __iter__   s    c         C` s   t  |  j  S(   N(   R   RK   (   R   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   __len__   s    c         C` s   |  j  j   |  j  j   r  t S|  j  j   j   } | j d  rH t S|  j  j d  j   } | j d t |   p | j d t |   S(   Ns
   .. index::i   t   -t   =(	   RG   R   R   RS   R&   R   t
   startswitht   TrueR   (   R   t   l1t   l2(    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   _is_at_section   s    c         C` s   d } d } x* t  |  D] \ } } | j   r Pq q Wx7 t  | d  d  d   D] \ } } | j   rS PqS qS W| | t |  | !S(   Ni    i(   t	   enumerateR   R   (   R   t   doct   it   jR   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   _strip   s    &c         C` sr   |  j  j   } x\ |  j   rm |  j  j   rm |  j  j d  j   sW | d g 7} n  | |  j  j   7} q W| S(   NiR   (   RG   R"   R_   R   R&   R   (   R   t   section(    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   _read_to_next_section   s     c         c` s   x |  j  j   s |  j   } | d j   } | j d  rO | | d f Vq t |  d k  ri t Vq | |  j | d  f Vq Wd  S(   Ni    s   ..i   i   (   RG   R   Rf   R   R[   R   t   StopIterationRd   (   R   R   R2   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   _read_sections   s    c   	      C` s   t  |  } g  } x | j   s | j   j   } d | k r[ | j d  d  \ } } n# | rq d | } } n | d } } | j   } t |  } t |  } | j t	 | | |   q W| S(   Ns    : i   R   (
   R   R   R   R   R   R%   t   dedent_linesR
   t   appendR1   (	   R   t   contentt   single_element_is_typet   rt   paramst   headert   arg_namet   arg_typeR4   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   _parse_param_list   s    s   :(?P<role>\w+):s'   `(?P<name>(?:~\w+\.)?[a-zA-Z0-9_\.-]+)`s   (?P<name2>[a-zA-Z0-9_\.-]+)t   (t   |t   )t   rolet   rolenextR2   t   namenexts/   (?P<description>\s*:(\s+(?P<desc>\S+.*))?)?\s*$s   ^\s*s   \s*s   (?P<allfuncs>s   (?P<morefuncs>([,]\s+s   )*)s   (?P<trailing>[,\.])?s   ..c         ` s  g  }   f d   } g  } x| D]} | j    s: q" n    j j |  } d } | r | j d  } | j d  r | r   j d | j d  | f d t q n  | r | j d  r | j	 | j     q" | rg  } | j d  }	 x{ t
 rl|	 j    sPn  | |	  \ }
 } } | j	 |
 | f  |	 | j    }	 |	 r |	 d d	 k r |	 d
 j    }	 q q Wt t d | g   } | j	 | | f  q" t d |   q" W| S(   s   
        func_name : Descriptive text
            continued text
        another_func_name : Descriptive text
        func_name1, func_name2, :meth:`func_name`, func_name3

        c         ` sq     j  j |   } | s+ t d |    n  | j d  } | rO | j d  n | j d  } | | | j   f S(   s   Match ':role:`name`' or 'name'.s   %s is not a item nameRv   R2   t   name2(   t	   _func_rgxt   matchR+   t   groupt   end(   t   textt   mRv   R2   (   R   (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   parse_item_name#  s    $R4   t   trailingsG   Unexpected comma or period after function list at index %d of line "%s"RQ   t    t   allfuncsi    t   ,i   s   %s is not a item nameN(   R   t	   _line_rgxR{   t   NoneR|   RR   R}   RS   R[   Rj   R\   R   t   filterR+   (   R   Rk   t   itemsR   t   restR   t
   line_matcht   descriptiont   funcsR~   R2   Rv   t	   match_end(    (   R   s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   _parse_see_also  s@    			c         C` s   d   } i  } | j  d  } t |  d k rT | | d j  d   d | d <n  xS | D]K } | j  d  } t |  d k r[ | | d j  d   | | d <q[ q[ W| S(	   sT   
        .. index: default
           :refguide: something, else, and more

        c         S` s   g  |  D] } | j    ^ q S(   N(   R   (   t   lstt   s(    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   strip_each_inS  s    s   ::i   R   i    t   defaultt   :i   (   R   R   (   R   Re   Rk   R   R   R   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   _parse_indexM  s    	$(c         C` s   |  j    r d Sx t r |  j j   } d j g  | D] } | j   ^ q5  j   } t j d  } | j |  r | |  d <|  j    s q q n  Pq W| d k	 r | |  d <n  |  j    s |  j
   |  d <n  d S(   s%   Grab signature (if given) and summaryNR   s   ^([\w., ]+=)?\s*[\w\.]+\(.*\)$R6   R7   s   Extended Summary(   R_   R\   RG   R"   R'   R   t   ret   compileR{   R   Rf   (   R   t   summaryR   t   summary_strt   compiled(    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   _parse_summary`  s    	.
	c         C` s  |  j  j   |  j   t |  j    } t g  | D] \ } } | ^ q3  } d | k } d | k } | r | r d } t |   n  | r d | k r d } t |   n  x| D]\ } } | j d  sd   | j d  D } d j	 |  } |  j
 |  r|  j d	 |  qn  | d k rA|  j |  |  | <q | d k ri|  j | d t |  | <q | j d  r|  j | |  |  d <q | d k r|  j |  |  d <q | |  | <q Wd  S(   NR9   R:   s5   Docstring contains both a Returns and Yields section.R;   s5   Docstring contains a Receives section but not Yields.s   ..c         s` s   |  ] } | j    Vq d  S(   N(   t
   capitalize(   t   .0R   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pys	   <genexpr>  s    R   s   The section %s appears twiceR8   s   Other ParametersR>   R?   R<   R=   Rl   s
   .. index::RD   s   See Also(   R8   s   Other ParametersR>   R?   (   R9   R:   R<   R=   R;   (   RG   R   R   R   Rh   t   sett
   ValueErrorR[   R   R'   t   getRR   Rr   R\   R   R   (   R   RJ   Re   Rk   t   section_namest   has_returnst
   has_yieldst   msg(    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyRL   v  s<    
%		c         C` s|   t  |  d  rY y t j |  j  } Wn t k
 r> d  } n X| d |  j | f } n  | rn t |   n
 t |  d  S(   Nt   _objs    in the docstring of %s in %s.(   R.   t   inspectt   getsourcefileR   t	   TypeErrorR   R   R   (   R   R   RQ   t   filename(    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyRR     s    
RY   c         C` s   | t  |  | g S(   N(   R   (   R   R2   t   symbol(    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   _str_header  s    i   c         C` s0   g  } x# | D] } | d | | g 7} q W| S(   NR   (    (   R   Ra   t   indentR   R   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   _str_indent  s    c         C` s3   |  d r( |  d j  d d  g d g Sd g Sd  S(   NR6   t   *s   \*R   (   t   replace(   R   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   _str_signature  s    
c         C` s!   |  d r |  d d g Sg  Sd  S(   NR7   R   (    (   R   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   _str_summary  s    
c         C` s!   |  d r |  d d g Sg  Sd  S(   Ns   Extended SummaryR   (    (   R   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   _str_extended_summary  s    
c         C` s   g  } |  | r | |  j  |  7} x |  | D] } g  } | j rV | j | j  n  | j rr | j | j  n  | d j |  g 7} | j r. d j | j  j   r. | |  j | j  7} q. q. W| d g 7} n  | S(   Ns    : R   (   R   R2   Rj   R3   R'   R4   R   R   (   R   R2   R   t   paramt   parts(    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   _str_param_list  s    
		!c         C` sE   g  } |  | rA | |  j  |  7} | |  | 7} | d g 7} n  | S(   NR   (   R   (   R   R2   R   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   _str_section  s    
c   
      C` s`  |  d s g  Sg  } | |  j  d  7} | d g 7} t } x |  d D] \ } } t | t  sf t  g  } x] | D]U \ } } | r d | | f }	 n# | r d | | f }	 n
 d | }	 | j |	  qs Wd j |  }	 | |	 g 7} | r| |  j d j |  g  7} t } qE t } | |  j |  j	 g  7} qE W| rO| d g 7} n  | d g 7} | S(   Ns   See AlsoR   s   :%s:`%s`s   `%s`_s   , R   (
   R   R\   R   R   t   AssertionErrorRj   R'   R   RS   t   empty_description(
   R   t	   func_roleR   t   last_had_descR   R4   t   linkst   funcRv   t   link(    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   _str_see_also  s6    

	c         C` s   |  d } g  } t  } | j d d  } | r7 t } n  | d | g 7} xR | j   D]D \ } } | d k rs qU n  t } | d | d j |  f g 7} qU W| r | Sd Sd  S(   NRD   R   R   s   .. index:: %ss
      :%s: %ss   , (   RS   R   R\   R   R'   (   R   t   idxR   t   output_indext   default_indexRe   t
   references(    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt
   _str_index  s    
	$c         C` s   g  } | |  j    7} | |  j   7} | |  j   7} x! d D] } | |  j |  7} q= W| |  j d  7} | |  j |  7} x! d D] } | |  j |  7} q Wx! d D] } | |  j |  7} q W| |  j   7} d j |  S(   NR8   R9   R:   R;   s   Other ParametersR<   R=   RA   R@   RB   RC   R>   R?   s   
(   R8   R9   R:   R;   s   Other ParametersR<   R=   (   R@   RB   RC   (   R>   R?   (   R   R   R   R   R   R   R   R'   (   R   R   R   t
   param_listR   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyR0     s    
s   ^\s*(?P<allfuncs>(+   R(   R)   R*   RJ   R   R   RU   RW   RX   R_   Rd   Rf   Rh   RS   Rr   t   _rolet   _funcbacktickt
   _funcplaint	   _funcnameR   t   _funcnamenextt   _descriptionR   R   Rz   R   R   R   R   R   RL   R\   RR   R   R   R   R   R   R   R   R   R   R0   (    (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyR5   u   sr   

								%
	5			&						 	i   c         ` sF   d |   |  d  k r   S|  j d  } d j   f d   | D  S(   NR   s   
c         3` s   |  ] }   | Vq d  S(   N(    (   R   R	   (   t
   indent_str(    s1   lib/python2.7/site-packages/numpydoc/docscrape.pys	   <genexpr>(  s    (   R   R   R'   (   t   strR   t   lines(    (   R   s1   lib/python2.7/site-packages/numpydoc/docscrape.pyR   #  s
    
c         C` s   t  j d j |    j d  S(   s"   Deindent a list of lines maximallys   
(   RE   RF   R'   R   (   R   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyRi   +  s    RY   c         C` s   |  d | t  |   d S(   Ns   
(   R   (   R~   t   style(    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyRo   0  s    t   FunctionDocc           B` s,   e  Z d  d i  d  Z d   Z d   Z RS(   R   c         C` sO  | |  _  | |  _ | d  k rQ | d  k r9 t d   n  t j |  pK d } n  t j |  |  |  d rK| d  k	 rK|  j   \ } } y y t	 t j
 |   } WnZ t t f k
 rt j d d k r t j |  } n t j |  } t j |   } n Xd | | j d d  f } Wn t k
 r=d	 | } n X| |  d <n  d  S(
   Ns   No function or docstring givenR   R6   i    i   s   %s%sR   s   \*s   %s()(   t   _fR   R   R   R   t   getdocR5   R   t   get_funcR   t	   signaturet   AttributeErrort   syst   version_infot   getfullargspect
   getargspect   formatargspecR   R   (   R   R   Rv   Ra   RM   t	   func_nameR   t   argspec(    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyR   5  s*    		 c         C` s^   t  |  j d |  j j  } t j |  j  rK t  |  j d |  j j  } n	 |  j } | | f S(   NR(   t   __call__(   t   getattrR   t	   __class__R(   R   t   isclassR   (   R   R   R   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyR   P  s
    	c         C` s   d } |  j    \ } } |  d j d d  } i d d 6d d 6} |  j r |  j | k rn t d	 |  j  n  | d
 | j |  j d  | f 7} n  | t t |   j d |  j  7} | S(   NR   R6   R   s   \*t   functionR   t   methodt   meths   Warning: invalid role %ss   .. %s:: %s
    

R   (   R   R   R   t   printR   t   superR   R0   (   R   R   R   R   R   t   roles(    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyR0   X  s    

	"N(   R(   R)   R   R   R   R0   (    (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyR   4  s   	t   ClassDocc           B` sM   e  Z d  g Z d d e i  d  Z e d    Z e d    Z d   Z	 RS(   R   R   c         C` s  t  j |  r/ | d  k	 r/ t d |   n  | |  _ | j d t  |  _ | rp | j d  rp | d 7} n  | |  _	 | d  k r | d  k r t d   n  t
 j |  } n  t j |  |  | j d g   } | t k r d  } n  | j d g   } | j d t  r| t k	 rd   } x d	 |  j f d
 |  j f g D] \ }	 }
 |  |	 sAg  } x t |
  D]| } | | k sj| r| | k rqjn  y> t
 j t |  j |   } | j t | d | |    Wqjt k
 rqjXqjW| |  |	 <qAqAWn  d  S(   Ns$   Expected a class or None, but got %rt   show_inherited_class_memberst   .s&   No class or documentation string givent   memberss   exclude-memberst   show_class_membersc         S` s   |  s
 g  S|  j    Sd  S(   N(   t
   splitlines(   R   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   splitlines_x  s    R?   R>   R   (   R   R   R   R   t   _clsR   R\   t   show_inherited_memberst   endswitht   _modt   pydocR   R5   R   R   t   methodst
   propertiest   sortedR   Rj   R1   R   (   R   t   clsRa   t
   modulenamet   func_docRM   t   _memberst   _excludeR   t   fieldR   t   doc_listR2   t   doc_item(    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyR   o  sD    				
c         C` sy   |  j  d  k r g  Sg  t j |  j   D]O \ } } | j d  sQ | |  j k r& t | t  r& |  j |  r& | ^ q& S(   Nt   _(	   R   R   R   t
   getmembersR[   t   extra_public_methodsR   R   t   _is_show_member(   R   R2   R   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyR     s    c         C` s   |  j  d  k r g  Sg  t j |  j   D][ \ } } | j d  r& | d  k sl t | t  sl t j |  r& |  j |  r& | ^ q& S(   NR   (	   R   R   R   R   R[   R   t   propertyt   isdatadescriptorR   (   R   R2   R   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyR     s    c         C` s'   |  j  r t S| |  j j k r# t St S(   N(   R   R\   R   t   __dict__RS   (   R   R2   (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyR     s
    	N(
   R(   R)   R   R   R   R   R   R   R   R   (    (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyR   k  s   		.

(!   R*   t
   __future__R    R   R   R   RE   R   R   t   warningsR   t   collectionsR   t   collections.abcR   R   t   ImportErrorRH   R   t   sphinx.ext.autodocR   R
   t   objectR   t	   ExceptionR+   R1   R5   R   Ri   Ro   R   R   (    (    (    s1   lib/python2.7/site-packages/numpydoc/docscrape.pyt   <module>   s2   		L 	7