
    ^Mh*                        d Z ddlmZmZmZ ddlmZmZ ddlZg dZ	 edede
f                   Z G d	 d
e          Zddedeeef         dz  defdZde
defdZde
dedefdZde
dedefdZdee         defdZd deeef         dedefdZdeeef         deeef         fdZdedefdZde
dededefdZdS )!zkUtilities to allow inserting docstring fragments for common
parameters into function and method docstrings.    )CallableIterableMapping)ProtocolTypeVarN)		docformatinherit_docstring_fromindentcount_linesfilldocunindent_dictunindent_stringextend_notes_in_docstringreplace_notes_in_docstringdoc_replace_F.)boundc                   "    e Zd ZdZdedefdZdS )	DecoratorzA decorator of a function.funcreturnc                    d S N )selfr   s     Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/scipy/_lib/doccer.py__call__zDecorator.__call__   s          N)__name__
__module____qualname____doc__r   r   r   r   r   r   r      s,        $$.R.r......r   r   	docstringdocdictr   c                    | s| S |i }|s| S |                                                                  }t          |          dk     rd}nt          |dd                   }d|z  }i }|                                D ]\  }}|                                                                 }	 |d         g}|dd         D ]}	|                    ||	z              d                    |          ||<   s# t          $ r |||<   Y w xY w| |z  S )ab  Fill a function docstring from variables in dictionary.

    Adapt the indent of the inserted docs

    Parameters
    ----------
    docstring : str
        A docstring from a function, possibly with dict formatting strings.
    docdict : dict[str, str], optional
        A 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
    -------
    docstring : str
        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'
    N   r       
)
expandtabs
splitlineslenr
   itemsappendjoin
IndexError)
r"   r#   linesicountindentindentednamedstrnewlineslines
             r   r   r      sA   @     ""--//E
5zzA~~"59--6\FHmmoo " "
d!!,,..	"azHabb	 / /....!YYx00HTNN 	" 	" 	"!HTNNN	"xs   'AC..D ?D clsc                 0     dt           dt           f fd}|S )a  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 : type or object
        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
    -------
    decfunc : 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:
    ...     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.
        '
    r   r   c                     t          | j                  j        }| j        }||| _        n|t          |          z  }|| _        | S )N)super)getattrr   r!   dict)r   cls_docstringfunc_docstringnew_docstringr8   s       r   _docz$inherit_docstring_from.<locals>._doc   sN    T]33;!(DLL*T-F-F-FFM(DLr   r   )r8   rA   s   ` r   r	   r	   X   s7    X2 "       Kr   notesc                 4     dt           dt           f fd}|S )a  This decorator replaces the decorated function's docstring
    with the docstring from corresponding method in `cls`.
    It extends the 'Notes' section of that docstring to include
    the given `notes`.

    Parameters
    ----------
    cls : type or object
        A class with a method with the same name as the decorated method.
        The docstring of the method in this class replaces the docstring of the
        decorated method.
    notes : str
        Additional notes to append to the 'Notes' section of the docstring.

    Returns
    -------
    decfunc : function
        The decorator function that modifies the __doc__ attribute
        of its argument.
    r   r   c                    t          | j                  j        }|| S |                    d          }|dk    r*|                    d          }|dk    rt	          |          }|d |         z   ||d          z   | _        | S )N        References
        Examples
r<   r   r!   findr+   )r   r>   end_of_notesr8   rC   s      r   rA   z'extend_notes_in_docstring.<locals>._doc   s    T]33;  K$))*@AA2(--.BCCLr!!"=11-<-(50=3OO 	 r   rB   r8   rC   rA   s   `` r   r   r      s<    ,2 "         Kr   c                 4     dt           dt           f fd}|S )a  This decorator replaces the decorated function's docstring
    with the docstring from corresponding method in `cls`.
    It replaces the 'Notes' section of that docstring with
    the given `notes`.

    Parameters
    ----------
    cls : type or object
        A class with a method with the same name as the decorated method.
        The docstring of the method in this class replaces the docstring of the
        decorated method.
    notes : str
        The notes to replace the existing 'Notes' section with.

    Returns
    -------
    decfunc : function
        The decorator function that modifies the __doc__ attribute
        of its argument.
    r   r   c                 V   t          | j                  j        }d}|| S |                    |          }|                    d          }|dk    r*|                    d          }|dk    rt	          |          }|d |t	          |          z            z   ||d          z   | _        | S )Nz        Notes
        -----
rF   rG   rH   rI   )r   r>   notes_headerstart_of_notesrK   r8   rC   s        r   rA   z(replace_notes_in_docstring.<locals>._doc   s    T]33;7  K&++L99$))*@AA2(--.BCCLr!!"=11>NS->->>>?LMM*+ 	
 r   rB   rL   s   `` r   r   r      s<    ,2 "       ( Kr   r0   c                     t           j        }| D ]E}|                                }|r-t          |t	          |          t	          |          z
            }F|t           j        k    rdS |S )a  Minimum indent for all lines in line list

    Parameters
    ----------
    lines : Iterable[str]
        The lines to find the minimum indent of.

    Returns
    -------
    indent : int
        The minimum indent.


    Examples
    --------
    >>> lines = [' one', '  two', '   three']
    >>> indentcount_lines(lines)
    1
    >>> lines = []
    >>> indentcount_lines(lines)
    0
    >>> lines = [' one']
    >>> indentcount_lines(lines)
    1
    >>> indentcount_lines(['    '])
    0
    r   )sysmaxsizelstripminr+   )r0   indentnor7   strippeds       r   r
   r
      sj    8 {H @ @;;== 	@8SYYX%>??H3;qOr   Tunindent_paramsc                 R     |rt                      dt          dt          f fd}|S )a  Return docstring decorator using docdict variable dictionary.

    Parameters
    ----------
    docdict : dict[str, str]
        A dictionary containing name, docstring fragment pairs.
    unindent_params : bool, optional
        If True, strip common indentation from all parameters in docdict.
        Default is False.

    Returns
    -------
    decfunc : function
        The decorator function that applies dictionary to its
        argument's __doc__ attribute.
    r   r   c                 D    | j         pd}t          |          | _         | S )N )r!   r   )r   docr#   s     r   decoratezfilldoc.<locals>.decorate!  s%    l b g..r   )r   r   )r#   rX   r]   s   `  r   r   r     sM    "  )((r b       Or   c                 b    i }|                                  D ]\  }}t          |          ||<   |S )a  Unindent all strings in a docdict.

    Parameters
    ----------
    docdict : dict[str, str]
        A dictionary with string values to unindent.

    Returns
    -------
    docdict : dict[str, str]
        The `docdict` dictionary but each of its string values are unindented.
    )r,   r   )r#   can_dictr4   r5   s       r   r   r   *  s<      "Hmmoo / /
d(..Or   c                     |                                                                  }t          |          dk    r| S d                    fd|D                       S )aq  Set docstring to minimum indent for all lines, including first.

    Parameters
    ----------
    docstring : str
        The input docstring to unindent.

    Returns
    -------
    docstring : str
        The unindented docstring.

    Examples
    --------
    >>> unindent_string(' two')
    'two'
    >>> unindent_string('  two\n   three')
    'two\n three'
    r   r(   c                 $    g | ]}|d          S r   r   ).0r7   r1   s     r   
<listcomp>z#unindent_string.<locals>.<listcomp>U  s!    666d677m666r   )r)   r*   r
   r.   )r"   r0   r1   s     @r   r   r   =  se    (   ""--//Eu%%F{{996666666777r   objoldvalnewvalc                 j    | j         pd                    ||          dt          dt          ffd}|S )az  Decorator to take the docstring from obj, with oldval replaced by newval

    Equivalent to ``func.__doc__ = obj.__doc__.replace(oldval, newval)``

    Parameters
    ----------
    obj : object
        A class or object whose docstring will be used as the basis for the
        replacement operation.
    oldval : str
        The string to search for in the docstring.
    newval : str
        The string to replace `oldval` with in the docstring.

    Returns
    -------
    decfunc : function
        A decorator function that replaces occurrences of `oldval` with `newval`
        in the docstring of the decorated function.
    r[   r   r   c                     | _         | S r   )r!   )r   r\   s    r   innerzdoc_replace.<locals>.innerp  s    r   )r!   replacer   )rd   re   rf   ri   r\   s       @r   r   r   X  sT    , ;"
%
%ff
5
5CB 2       Lr   r   )T)r!   collections.abcr   r   r   typingr   r   rR   __all__objectr   r   strr   r	   r   r   intr
   boolr   r=   r   r   r   r   r   r   <module>rr      sK  3 3 8 7 7 7 7 7 7 7 7 7 $ $ $ $ $ $ $ $ 




 
 
 WT#v+.//// / / / / / / /8  8  8 wsCx'84'? 8 3 8  8  8  8 v6 69 6 6 6 6r&6 &# &) & & & &R*F *3 *9 * * * *Z#Xc] #s # # # #L WS#X&      :738, c3h    &8s 8s 8 8 8 86V S # )      r   