
(*\c           @` sf  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 y d d l	 m
 Z
 Wn! e k
 r d d l m
 Z
 n Xd d l Z d d l Z d d l m Z m Z m Z m Z m Z d d l Z d d l m Z m Z d d l m Z e j d k  re d	   n  d
 d l m a d
 d l m  Z  d
 d l! m Z e j" e#  Z$ e j% d d k rxd   Z& n	 d   Z& d Z' d   Z( d   Z) d   Z* d   Z+ d Z, d   Z- d   Z. t d  Z/ d   Z0 d d l1 m2 Z2 d d l3 m4 Z4 d d l5 m6 Z6 d e7 f d     YZ8 d  e8 e6 f d!     YZ9 d" e8 e4 f d#     YZ: d$   Z; d%   Z< d S(&   sk  
========
numpydoc
========

Sphinx extension that handles docstrings in the Numpy standard format. [1]

It will:

- Convert Parameters etc. sections to field lists.
- Convert See Also section to a See also entry.
- Renumber references.
- Extract the signature from the docstring, if it can't be determined
  otherwise.

.. [1] https://github.com/numpy/numpydoc

i    (   t   divisiont   absolute_importt   print_functionN(   t   Callable(   t   citationt   Textt   sectiont   commentt	   reference(   t   pending_xreft   desc_content(   t   loggings   1.0.1s!   Sphinx 1.0.1 or newer is requiredi   (   t   get_doc_object(   t   DEFAULT_LINKS(   t   __version__i   c         C` s   |  S(   N(    (   t   s(    (    s0   lib/python2.7/site-packages/numpydoc/numpydoc.pyt   <lambda>/   t    c         C` s   t  |  d  S(   Nt   unicode_escape(   t   unicode(   R   (    (    s0   lib/python2.7/site-packages/numpydoc/numpydoc.pyR   1   R   i   c         C` sH  t    } xa | D]Y } | j   } t j t d  |  j j | t j  } | r | j | j	 d   q q W| rDt
 j   }	 |	 j | j d   d |	 j   t  }
 x | D] } |
 d | } xv t |  D]h \ } } | | j t d  | t d  |  | | <| | j t d  | t d  |  | | <q Wq Wn  d  S(   Ns   ^\.\. +\[(%s)\]i   t   utf8t   Rt   -s   [%s]_s   .. [%s](   t   sett   stript   ret   matcht   sixut   configt   numpydoc_citation_ret   It   addt   groupt   hashlibt   sha256t   updatet   encodet	   hexdigestt   HASH_LENt	   enumeratet   replace(   t   appt   whatt   namet   objt   optionst   linest
   referencest   linet   mt   shat   prefixt   rt   new_rt   i(    (    s0   lib/python2.7/site-packages/numpydoc/numpydoc.pyt   rename_references6   s&    	
c      	   C` s   |  j  } d   } x) | |  s= | j  } | d  k r t Sq Wt j | j | d t d t d t  } x^ | D]V } | j s qo n  | j d } t | t	  s qo n  | j
 j   t j   k ro t Sqo Wt S(   Nc         S` s   t  |  t t f  S(   N(   t
   isinstanceR   R
   (   t   node(    (    s0   lib/python2.7/site-packages/numpydoc/numpydoc.pyt   is_docstring_sectionW   s    t   include_selft   descendt   siblingsi(   t   parentt   Nonet   Falset	   itertoolst   chaint   traverset   Truet   childrenR8   R   t	   rawsourceR   t   DEDUPLICATION_TAG(   t   citation_nodet   section_nodeR:   t   sibling_sectionst   sibling_sectiont
   last_child(    (    s0   lib/python2.7/site-packages/numpydoc/numpydoc.pyt   _is_cite_in_numpydoc_docstringQ   s&    				c         ` s$  x| j  t  D]} t |  s( q n  | d } | d j   j d  \ } } } t |  t d k sp t  t |  } | j	 | d |  x | d D]} } | j
 | }	 |	 d     f d   }
 x8 |	 j j  |
  D]$ } | j	 | d t d |   q W|	 j	   | j    q Wq Wd  S(   Ni    R   i   t   backrefsc         ` s'   t  |  t  o& |  d j   d   k S(   Ni    s   [%s](   R8   R	   t   astext(   R9   (   t   ref_text(    s0   lib/python2.7/site-packages/numpydoc/numpydoc.pyt   matching_pending_xref~   s    s   [%s](   RC   R   RM   RO   t	   partitiont   lenR&   t   AssertionErrorR   R(   t   idsR>   t   copy(   R)   t   docRH   t
   label_nodeR3   t   _t	   new_labelt   new_textt   id_t   refRQ   t	   xref_node(    (   RP   s0   lib/python2.7/site-packages/numpydoc/numpydoc.pyt   relabel_referencesn   s    
"
"c         C` s   t    } x? | j t d t D]( } x | d D] } | j |  q0 Wq WxJ | j t d t D]3 } g  | d D] } | | k rr | ^ qr | d <qa Wd  S(   NR<   RU   RN   (   R   RC   R   RD   R   R   (   R)   RW   t   docnamet   known_ref_idsR]   R\   RH   (    (    s0   lib/python2.7/site-packages/numpydoc/numpydoc.pyt   clean_backrefs   s    	s       !! processed by numpydoc !!c         C` s  t  | k r d  Si	 |  j j d 6|  j j d 6|  j j d 6|  j j d 6|  j j d 6|  j j d 6|  j j d 6|  j j	 d 6|  j j
 d	 6} | j | p i   t d
  } | d k rd } t j t |  t j t j B }	 |	 j t d  | j |   j |  | (n yl t | | | j |  d | d |  j }
 t j d d k r[t |
  }
 n t |
  }
 |
 j |  | (Wn t j d |    n X|  j j rdt | d  rd| j rdt | d  rt d t d  | j  | j f  } n t d | j  } | t d  t d  t d  g 7} | g  |  j j | j d
  D] } t d  | ^ qD7} n  t! |  | | | | |  | d t  g 7} d  S(   Nt	   use_plotst   use_blockquotest   show_class_memberst   show_inherited_class_memberst   class_members_toctreet   attributes_as_param_listt   xref_param_typet   xref_aliasest   xref_ignores   
t   modules(   ^\s*[#*=]{4,}\n[a-z0-9 -]+\n[#*=]{4,}\s*R   R   t   builderi    i   s,   [numpydoc] While processing docstring for %rt   __name__t
   __module__t	   full_names   %s.%ss   .. htmlonly::s       %ss   ..("   RG   R   t   numpydoc_use_plotst   numpydoc_use_blockquotest   numpydoc_show_class_memberst%   numpydoc_show_inherited_class_memberst   numpydoc_class_members_toctreet!   numpydoc_attributes_as_param_listt   numpydoc_xref_param_typet   numpydoc_xref_aliasest   numpydoc_xref_ignoreR#   R   R   t   compileR   t   St   subt   joint   splitR   Rm   t   syst   version_infot   strR   t   loggert   errort   numpydoc_edit_linkt   hasattrRn   t   dictRo   R7   (   R)   R*   R+   R,   R-   R.   t   cfgt   u_NLt   patternt   title_reRW   t   vt   x(    (    s0   lib/python2.7/site-packages/numpydoc/numpydoc.pyt   mangle_docstrings   sJ    ".	(%7c         C` s   t  j |  r; t | d  s7 d t j | j  k r; d St | t  pV t | d  s] d  St | d  sp d  St | d i t	 d 6} | d p t
 | d	 d   } | r t j t d
  t d  |  } | t d  f Sd  S(   Nt   __init__s   initializes x; see R   t   __argspec_is_invalid_t   __doc__R   Re   t	   Signaturet   __text_signature__s   ^[^(]*(   R   R   (   t   inspectt   isclassR   t   pydoct   getdocR   R8   R   R   R@   t   getattrR?   R   R|   R   (   R)   R*   R+   R,   R-   t   sigt   retannRW   (    (    s0   lib/python2.7/site-packages/numpydoc/numpydoc.pyt   mangle_signature   s    !c         C` s  t  |  d  s d  S| a |  j d  |  j d t  |  j d t  |  j d t  |  j d t  |  j d t  |  j	 d d  t  |  j	 d	 d  t  |  j	 d
 d  t  |  j	 d t t  |  j	 d t t  |  j	 d t t  |  j	 d d t  |  j	 d t t  |  j	 d t t  |  j	 d t   t  |  j	 d t   t  |  j t  |  j t  i t d 6t d 6} | S(   Nt   add_config_values   sphinx.ext.autosummarys   builder-initeds   autodoc-process-docstrings   autodoc-process-signatures   doctree-reads   doctree-resolvedR   Rq   Rr   Rs   Rt   Ru   R   s   [a-z0-9_.-]+Rv   Rw   Rx   Ry   t   versiont   parallel_read_safe(   R   R   t   setup_extensiont   connectt   update_configR   R   R_   Rb   R   R?   R@   RD   R   R   t
   add_domaint   NumpyPythonDomaint   NumpyCDomainR   (   R)   t   get_doc_object_t   metadata(    (    s0   lib/python2.7/site-packages/numpydoc/numpydoc.pyt   setup   s2    

c         C` sF   x? t  j   D]1 \ } } | |  j j k r | |  j j | <q q Wd S(   s-   Update the configuration with default values.N(   R   t   itemsR   Rx   (   R)   t   keyt   value(    (    s0   lib/python2.7/site-packages/numpydoc/numpydoc.pyR     s    (   t   ViewList(   t   CDomain(   t   PythonDomaint   ManglingDomainBasec           B` s    e  Z i  Z d    Z d   Z RS(   c         O` s'   t  t |   j | |   |  j   d  S(   N(   t   superR   R   t   wrap_mangling_directives(   t   selft   at   kw(    (    s0   lib/python2.7/site-packages/numpydoc/numpydoc.pyR     s    c         C` sG   x@ t  |  j j    D]) \ } } t |  j | |  |  j | <q Wd  S(   N(   t   listt   directive_mangling_mapR   t   wrap_mangling_directivet
   directives(   R   R+   t   objtype(    (    s0   lib/python2.7/site-packages/numpydoc/numpydoc.pyR     s    "(   Rn   Ro   R   R   R   (    (    (    s0   lib/python2.7/site-packages/numpydoc/numpydoc.pyR     s   	R   c           B` sK   e  Z d  Z i d d 6d d 6d d 6d d 6d d 6d d 6d d 6Z g  Z RS(   t   npt   functiont   classt	   exceptiont   methodt   classmethodt   staticmethodt	   attribute(   Rn   Ro   R+   R   t   indices(    (    (    s0   lib/python2.7/site-packages/numpydoc/numpydoc.pyR      s   
R   c           B` s7   e  Z d  Z i d d 6d d 6d d 6d d 6d d 6Z RS(	   s   np-cR   R   t   membert   macroR   t   typet   objectt   var(   Rn   Ro   R+   R   (    (    (    s0   lib/python2.7/site-packages/numpydoc/numpydoc.pyR   .  s   c         C` s   g  } | j  } | j } d } x t |   D] \ } } x5 | t |  d k  rn | | j   rn | d 7} q: W| j | |  | j   r+ | t |  d k  r+ | d 7} q+ q+ Wt |  t |   k s t  | S(   st  Create items for mangled lines.

    This function tries to match the lines in ``lines`` with the items (source
    file references and line numbers) in ``content_old``. The
    ``mangle_docstrings`` function changes the actual docstrings, but doesn't
    keep track of where each line came from. The manging does many operations
    on the original lines, which are hard to track afterwards.

    Many of the line changes come from deleting or inserting blank lines. This
    function tries to match lines by ignoring blank lines. All other changes
    (such as inserting figures or changes in the references) are completely
    ignored, so the generated line numbers will be off if ``mangle_docstrings``
    does anything non-trivial.

    This is a best-effort function and the real fix would be to make
    ``mangle_docstrings`` actually keep track of the ``items`` together with
    the ``lines``.

    Examples
    --------
    >>> lines = ['', 'A', '', 'B', '   ', '', 'C', 'D']
    >>> lines_old = ['a', '', '', 'b', '', 'c']
    >>> items_old = [('file1.py', 0), ('file1.py', 1), ('file1.py', 2),
    ...              ('file2.py', 0), ('file2.py', 1), ('file2.py', 2)]
    >>> content_old = ViewList(lines_old, items=items_old)
    >>> match_items(lines, content_old) # doctest: +NORMALIZE_WHITESPACE
    [('file1.py', 0), ('file1.py', 0), ('file2.py', 0), ('file2.py', 0),
     ('file2.py', 2), ('file2.py', 2), ('file2.py', 2), ('file2.py', 2)]
    >>> # first 2 ``lines`` are matched to 'a', second 2 to 'b', rest to 'c'
    >>> # actual content is completely ignored.

    Notes
    -----
    The algorithm tries to match any line in ``lines`` with one in
    ``lines_old``.  It skips over all empty lines in ``lines_old`` and assigns
    this line number to all lines in ``lines``, unless a non-empty line is
    found in ``lines`` in which case it goes to the next line in ``lines_old``.

    i    i   (   t   dataR   R'   RS   R   t   appendRT   (   R.   t   content_oldt	   items_newt	   lines_oldt	   items_oldt   jR6   R0   (    (    s0   lib/python2.7/site-packages/numpydoc/numpydoc.pyt   match_items9  s    (		*"c         ` s#   d   f    f d     Y} | S(   Nt	   directivec           ` s   e  Z    f d    Z RS(   c         ` s   |  j  j j j } d  } |  j rR t j d |  j d  } | j d  j	   } n  | sh |  j d } n  t
 |  j  } t | j  | d  d  |  |  j r t | |  j  } t | d | d |  j j |  _ n    j |   S(   Ns   ^(.*\s+)?(.*?)(\(.*)?i    i   R   R>   (   t   statet   documentt   settingst   envR?   t	   argumentsR   R   R    R   R   t   contentR   R)   R   R   R>   t   run(   R   R   R+   R1   R.   R   (   t   base_directiveR   (    s0   lib/python2.7/site-packages/numpydoc/numpydoc.pyR   s  s    		(   Rn   Ro   R   (    (   R   R   (    s0   lib/python2.7/site-packages/numpydoc/numpydoc.pyR   r  s   (    (   R   R   R   (    (   R   R   s0   lib/python2.7/site-packages/numpydoc/numpydoc.pyR   q  s    (=   R   t
   __future__R    R   R   R   R   R   R   t   collections.abcR   t   ImportErrort   collectionsR!   RA   t   docutils.nodesR   R   R   R   R   t   sphinxt   sphinx.addnodesR	   R
   t   sphinx.utilR   R   t   RuntimeErrort   docscrape_sphinxR   t   xrefR   R   t	   getLoggerRn   R   R   R   R&   R7   RM   R_   Rb   RG   R   R   R   R   t   docutils.statemachineR   t   sphinx.domains.cR   t   sphinx.domains.pythonR   R   R   R   R   R   R   (    (    (    s0   lib/python2.7/site-packages/numpydoc/numpydoc.pyt   <module>   sT   (						6	#		8