
    (ph*                     `   S r SSKJrJrJr  SSKJrJr  SSKr/ SQr	\" S\S\
4   S9r " S	 S
\5      rSS\S\\\4   S-  S\4S jjrS\
S\4S jrS\
S\S\4S jrS\
S\S\4S jrS\\   S\4S jrSS\\\4   S\S\4S jjrS\\\4   S\\\4   4S jrS\S\4S jrS\
S\S\S\4S jrg) 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                   *    \ rS rSrSrS\S\4S jrSrg)	Decorator   zA decorator of a function.funcreturnc                    g N )selfr   s     D/var/www/html/venv/lib/python3.13/site-packages/scipy/_lib/doccer.py__call__Decorator.__call__   s    3    r   N)__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes__r   r   r   r   r      s    $.R.r.r   r   	docstringdocdictr   c                    U (       d  U $ Uc  0 nU(       d  U $ U R                  5       R                  5       n[        U5      S:  a  SnO[        USS 5      nSU-  n0 nUR	                  5        H\  u  pgUR                  5       R                  5       n US   /nUSS  H  n	UR                  XI-   5        M     SR                  U5      XV'   M^     X-  $ ! [         a    XuU'    Mu  f = f)a  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      s    @   "--/E
5zA~"59-6\FHmmo
!,,.	"azHab	. "!YYx0HN &   	"!TN	"s   8CC#"C#clsc                 0   ^  S[         S[         4U 4S jjnU$ )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U R                  5      R                  nU R                  nUc  Xl        U $ U[        US9-  nX0l        U $ )N)super)getattrr    r$   dict)r   cls_docstringfunc_docstringnew_docstringr<   s       r   _doc$inherit_docstring_from.<locals>._doc   sO    T]]3;;!(L  +T-FFM(Lr   r   )r<   rE   s   ` r   r	   r	   X   s    X2 "  Kr   notesc                 4   ^ ^ S[         S[         4U U4S jjnU$ )aa  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U R                  5      R                  nUc  U $ UR                  S5      nUS:X  a"  UR                  S5      nUS:X  a  [	        U5      nUS U T-   XS  -   U l        U $ )N        References
        Examples
r@   r    r$   findr/   )r   rB   end_of_notesr<   rH   s      r   rE   'extend_notes_in_docstring.<locals>._doc   s    T]]3;;  K$))*@A2(--.BCLr!"=1-<(50=3OO 	 r   rG   r<   rH   rE   s   `` r   r   r      s"    ,2 "    Kr   c                 4   ^ ^ S[         S[         4U U4S jjnU$ )aP  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                 &  > [        TU R                  5      R                  nSnUc  U $ UR                  U5      nUR                  S5      nUS:X  a"  UR                  S5      nUS:X  a  [	        U5      nUS U[	        U5      -    T-   XS  -   U l        U $ )Nz        Notes
        -----
rK   rL   rM   rN   )r   rB   notes_headerstart_of_notesrP   r<   rH   s        r   rE   (replace_notes_in_docstring.<locals>._doc   s    T]]3;;7  K&++L9$))*@A2(--.BCLr!"=1>NS->>?M*+ 	
 r   rG   rR   s   `` r   r   r      s"    ,2 "  ( Kr   r4   c                     [         R                  nU  H=  nUR                  5       nU(       d  M  [        U[	        U5      [	        U5      -
  5      nM?     U[         R                  :X  a  gU$ )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/   )r4   indentnor;   strippeds       r   r
   r
      sV    8 {{H;;=88SYX%>?H  3;;Or   unindent_paramsc                 T   ^  U(       a  [        T 5      m S[        S[        4U 4S jjnU$ )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                 T   > U R                   =(       d    Sn[        UT5      U l         U $ )N )r$   r   )r   docr'   s     r   decoratefilldoc.<locals>.decorate!  s$    ll b g.r   )r   r   )r'   r_   rd   s   `  r   r   r     s,    " (r b  Or   c                 V    0 nU R                  5        H  u  p#[        U5      X'   M     U$ )zUnindent 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.
)r0   r   )r'   can_dictr8   r9   s       r   r   r   *  s,      "Hmmo
(. &Or   c                     U R                  5       R                  5       n[        U5      nUS:X  a  U $ SR                  U Vs/ s H  o3US PM	     sn5      $ s  snf )a5  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,   N)r-   r.   r
   r2   )r&   r4   r5   r;   s       r   r   r   =  sW    (   "--/Eu%F{99667m6776s   Aobjoldvalnewvalc                 x   ^ U R                   =(       d    SR                  X5      mS[        S[        4U4S jjnU$ )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
    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.
rb   r   r   c                    > TU l         U $ r   )r$   )r   rc   s    r   innerdoc_replace.<locals>.innerp  s    r   )r$   replacer   )ri   rj   rk   rn   rc   s       @r   r   r   X  s8    , ;;"
%
%f
5CB 2  Lr   r   )T)r$   collections.abcr   r   r   typingr   r   rY   __all__objectr   r   strr   r	   r   r   intr
   boolr   rA   r   r   r   r   r   r   <module>rx      sH  3 8 7 $ 

 T#v+.// /8  8 wsCx'84'? 8 3 8 v6 69 6r&6 &# &) &R*F *3 *9 *Z#Xc] #s #LWS#X&   :738, c3h &8s 8s 86V S # ) r   