
    4[g                      R    d Z ddlZg dZddZd Zd Zd Zd Zdd	Zd
 Z	d Z
d Zy)zk Utilities to allow inserting docstring fragments for common
parameters into function and method docstrings    N)		docformatinherit_docstring_fromindentcount_linesfilldocunindent_dictunindent_stringextend_notes_in_docstringreplace_notes_in_docstringdoc_replacec                    | s| S |i }|s| S | j                         j                         }t        |      dk  rd}nt        |dd       }d|z  }i }|j	                         D ]\  \  }}|j                         j                         }	 |d   g}|dd D ]  }	|j                  ||	z           dj                  |      ||<   ^ | |z  S # t        $ r |||<   Y tw xY w)aV   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'
    N   r       
)
expandtabs
splitlineslenr   itemsappendjoin
IndexError)
	docstringdocdictlinesicountindentindentednamedstrnewlineslines
             L/var/www/html/bid-api/venv/lib/python3.12/site-packages/scipy/_lib/doccer.pyr   r      s    @   "--/E
5zA~"59-6\FHmmo
d!,,.	"azHab	t, "!YYx0HTN & x  	"!HTN	"s   8CCCc                       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 : 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:
    ...     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                     t        | j                        j                  }| j                  }|	|| _        | S |t        |      z  }|| _        | S )N)super)getattr__name____doc__dict)funccls_docstringfunc_docstringnew_docstringclss       r"   _docz$inherit_docstring_from.<locals>._docu   sS    T]]3;;!(DL  +T-FFM(DL     )r.   r/   s   ` r"   r   r   H   s    Z Kr0   c                       fd}|S )z
    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`.
    c                     t        | j                        j                  }|| S |j                  d      }|dk(  r!|j                  d      }|dk(  rt	        |      }|d | z   ||d  z   | _        | S )N        References
        Examples
r&   r'   r(   findr   )r*   r+   end_of_notesr.   notess      r"   r/   z'extend_notes_in_docstring.<locals>._doc   s    T]]3;;  K$))*@A2(--.BCLr!"=1%m|4u<%lm45r0   r1   r.   r:   r/   s   `` r"   r	   r	      s     Kr0   c                       fd}|S )z
    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`.
    c                 "   t        | j                        j                  }d}|| S |j                  |      }|j                  d      }|dk(  r!|j                  d      }|dk(  rt	        |      }|d |t	        |      z    z   ||d  z   | _        | S )Nz        Notes
        -----
r4   r5   r6   r7   )r*   r+   notes_headerstart_of_notesr9   r.   r:   s        r"   r/   z(replace_notes_in_docstring.<locals>._doc   s    T]]3;;7  K&++L9$))*@A2(--.BCLr!"=1%&I~L8I'IJ%lm45 r0   r1   r;   s   `` r"   r
   r
      s    " Kr0   c                     t         j                  }| D ]6  }|j                         }|st        |t	        |      t	        |      z
        }8 |t         j                  k(  ry|S )a)   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
    r   )sysmaxsizelstripminr   )r   indentnor!   strippeds       r"   r   r      sT     {{H;;=8SYX%>?H  3;;Or0   c                 ,     |rt                 fd}|S )a   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                 >    t        | j                        | _        | S N)r   r(   )fr   s    r"   decoratezfilldoc.<locals>.decorate   s    aii1	r0   )r   )r   unindent_paramsrK   s   `  r"   r   r      s    " ( Or0   c                 V    i }| j                         D ]  \  }}t        |      ||<    |S )z# Unindent all strings in a docdict )r   r   )r   can_dictr   r   s       r"   r   r      s.    Hmmo
d(. &Or0   c                     | j                         j                         }t        |      }|dk(  r| S dj                  |D cg c]  }||d 	 c}      S c c}w )z Set docstring to minimum indent for all lines, including first

    >>> unindent_string(' two')
    'two'
    >>> unindent_string('  two\n   three')
    'two\n three'
    r   r   N)r   r   r   r   )r   r   r   r!   s       r"   r   r      sY       "--/Eu%F{996d67m6776s    Ac                 R    | j                   xs dj                  ||      fd}|S )a  Decorator to take the docstring from obj, with oldval replaced by newval

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

    Parameters
    ----------
    obj : object
        The object to take the docstring from.
    oldval : string
        The string to replace from the original docstring.
    newval : string
        The string to replace ``oldval`` with.
     c                     | _         | S rI   )r(   )r*   docs    r"   innerzdoc_replace.<locals>.inner  s    r0   )r(   replace)objoldvalnewvalrT   rS   s       @r"   r   r      s,     ;;"
%
%ff
5C Lr0   rI   )T)r(   rA   __all__r   r   r	   r
   r   r   r   r   r   r1   r0   r"   <module>rZ      sE   2 8 v6r06248r0   