σ
Λ½χXc           @` s   d  Z  d d l m Z m Z m Z d d l Z d d d d d d	 g Z d d
  Z d   Z	 d   Z
 e d  Z d   Z d   Z d S(   sk    Utilities to allow inserting docstring fragments for common
parameters into function and method docstringsi    (   t   divisiont   print_functiont   absolute_importNt	   docformatt   inherit_docstring_fromt   indentcount_linest   filldoct   unindent_dictt   unindent_stringc   
      C` s  |  s
 |  S| d k r i  } n  | s) |  S|  j   j   } t |  d k  rV d } n t | d  } d | } i  } x | j   D] \ } } | j   j   } yJ | d g } x# | d D] }	 | j | |	  qΌ Wd j |  | | <Wq t k
 r| | | <q Xq W|  | S(   sV   Fill a function docstring from variables in dictionary

    Adapt the indent of the inserted docs

    Parameters
    ----------
    docstring : string
        docstring from function, possibly with dict formatting strings
    docdict : dict, optional
        dictionary with keys that match the dict formatting strings
        and values that are docstring fragments to be inserted.  The
        indentation of the inserted docstrings is set to match the
        minimum indentation of the ``docstring`` by adding this
        indentation to all lines of the inserted string, except the
        first

    Returns
    -------
    outstring : string
        string with requested ``docdict`` strings inserted

    Examples
    --------
    >>> docformat(' Test string with %(value)s', {'value':'inserted value'})
    ' Test string with inserted value'
    >>> docstring = 'First line\n    Second line\n    %(value)s'
    >>> inserted_string = "indented\nstring"
    >>> docdict = {'value': inserted_string}
    >>> docformat(docstring, docdict)
    'First line\n    Second line\n    indented\n    string'
    i   i    i   t    s   
N(	   t   Nonet
   expandtabst
   splitlinest   lenR   t   itemst   appendt   joint
   IndexError(
   t	   docstringt   docdictt   linest   icountt   indentt   indentedt   namet   dstrt   newlinest   line(    (    s0   /tmp/pip-build-7oUkmx/scipy/scipy/misc/doccer.pyR      s,     		
c         ` s     f d   } | S(   sΥ  
    This decorator modifies the decorated function's docstring by
    replacing occurrences of '%(super)s' with the docstring of the
    method of the same name from the class `cls`.

    If the decorated method has no docstring, it is simply given the
    docstring of `cls`s method.

    Parameters
    ----------
    cls : Python class or instance
        A class with a method with the same name as the decorated method.
        The docstring of the method in this class replaces '%(super)s' in the
        docstring of the decorated method.

    Returns
    -------
    f : function
        The decorator function that modifies the __doc__ attribute
        of its argument.

    Examples
    --------
    In the following, the docstring for Bar.func created using the
    docstring of `Foo.func`.

    >>> class Foo(object):
    ...     def func(self):
    ...         '''Do something useful.'''
    ...         return
    ...
    >>> class Bar(Foo):
    ...     @inherit_docstring_from(Foo)
    ...     def func(self):
    ...         '''%(super)s
    ...         Do it fast.
    ...         '''
    ...         return
    ...
    >>> b = Bar()
    >>> b.func.__doc__
    'Do something useful.
        Do it fast.
        '

    c         ` sV   t    |  j  j } |  j } | d  k r6 | |  _ n | t d |  } | |  _ |  S(   Nt   super(   t   getattrt   __name__t   __doc__R
   t   dict(   t   funct   cls_docstringt   func_docstringt   new_docstring(   t   cls(    s0   /tmp/pip-build-7oUkmx/scipy/scipy/misc/doccer.pyt   _doct   s    		(    (   R%   R&   (    (   R%   s0   /tmp/pip-build-7oUkmx/scipy/scipy/misc/doccer.pyR   G   s    -	c         C` se   t  j } xB |  D]: } | j   } | r t | t |  t |   } q q W| t  j k ra d S| S(   s)   Minimum indent for all lines in line list

    >>> lines = [' one', '  two', '   three']
    >>> indentcount_lines(lines)
    1
    >>> lines = []
    >>> indentcount_lines(lines)
    0
    >>> lines = [' one']
    >>> indentcount_lines(lines)
    1
    >>> indentcount_lines(['    '])
    0
    i    (   t   syst   maxsizet   lstript   minR   (   R   t   indentnoR   t   stripped(    (    s0   /tmp/pip-build-7oUkmx/scipy/scipy/misc/doccer.pyR      s    	&c         ` s(   | r t       n    f d   } | S(   sΆ   Return docstring decorator using docdict variable dictionary

    Parameters
    ----------
    docdict : dictionary
        dictionary containing name, docstring fragment pairs
    unindent_params : {False, True}, boolean, optional
        If True, strip common indentation from all parameters in
        docdict

    Returns
    -------
    decfunc : function
        decorator that applies dictionary to input function docstring

    c         ` s   t  |  j    |  _ |  S(   N(   R   R   (   t   f(   R   (    s0   /tmp/pip-build-7oUkmx/scipy/scipy/misc/doccer.pyt   decorate­   s    (   R   (   R   t   unindent_paramsR.   (    (   R   s0   /tmp/pip-build-7oUkmx/scipy/scipy/misc/doccer.pyR      s    c         C` s7   i  } x* |  j    D] \ } } t |  | | <q W| S(   s#    Unindent all strings in a docdict (   R   R   (   R   t   can_dictR   R   (    (    s0   /tmp/pip-build-7oUkmx/scipy/scipy/misc/doccer.pyR   ³   s    c         C` sR   |  j    j   } t |  } | d k r. |  Sd j g  | D] } | | ^ q;  S(   s¬    Set docstring to minimum indent for all lines, including first

    >>> unindent_string(' two')
    'two'
    >>> unindent_string('  two\n   three')
    'two\n three'
    i    s   
(   R   R   R   R   (   R   R   R   R   (    (    s0   /tmp/pip-build-7oUkmx/scipy/scipy/misc/doccer.pyR   »   s
    (   R   t
   __future__R    R   R   R'   t   __all__R
   R   R   R   t   TrueR   R   R   (    (    (    s0   /tmp/pip-build-7oUkmx/scipy/scipy/misc/doccer.pyt   <module>   s   	;	9		