
    O&i                         d Z ddlZddlZddlmZmZmZ ddlmZ  ej	        de            G d d          Z
 G d d	e
          ZdS )
z"A collection of helpful iterators.    N)AnyIterableOptional)RemovedInSphinx70Warningz,sphinx.ext.napoleon.iterators is deprecated.c                       e Zd ZdZdeddfdZddZddee         defdZ	dee         ddfd	Z
defd
Zddee         defdZddee         defdZdS )	peek_iteral  An iterator object that supports peeking ahead.

    Parameters
    ----------
    o : iterable or callable
        `o` is interpreted very differently depending on the presence of
        `sentinel`.

        If `sentinel` is not given, then `o` must be a collection object
        which supports either the iteration protocol or the sequence protocol.

        If `sentinel` is given, then `o` must be a callable object.

    sentinel : any value, optional
        If given, the iterator will call `o` with no arguments for each
        call to its `next` method; if the value returned is equal to
        `sentinel`, :exc:`StopIteration` will be raised, otherwise the
        value will be returned.

    See Also
    --------
    `peek_iter` can operate as a drop in replacement for the built-in
    `iter <https://docs.python.org/3/library/functions.html#iter>`_ function.

    Attributes
    ----------
    sentinel
        The value used to indicate the iterator is exhausted. If `sentinel`
        was not given when the `peek_iter` was instantiated, then it will
        be set to a new object instance: ``object()``.

    argsreturnNc                     t          | | _        t          j                    | _        t          |          dk    r|d         | _        dS t                      | _        dS )z__init__(o, sentinel=None)      N)iter	_iterablecollectionsdeque_cachelensentinelobject)selfr	   s     j/home/geonatureadmin/si_en_reseau/tutos/venv/lib/python3.11/site-packages/sphinx/ext/napoleon/iterators.py__init__zpeek_iter.__init__.   sJ    #';)4):)<)<t99>> GDMMM"HHDMMM    c                     | S N r   s    r   __iter__zpeek_iter.__iter__7   s    r   nc                 ,    |                      |          S r   )nextr   r   s     r   __next__zpeek_iter.__next__:   s    yy||r   c                    |sd}	 t          | j                  |k     rF| j                            t          | j                             t          | j                  |k     DdS dS # t
          $ rV t          | j                  |k     r:| j                            | j                   t          | j                  |k     7Y dS Y dS w xY w)z<Cache `n` items. If `n` is 0 or None, then 1 item is cached.r   N)r   r   appendr!   r   StopIterationr   r"   s     r   
_fillcachezpeek_iter._fillcache=   s     	A	2dk""Q&&""4#7#7888 dk""Q&&&&&& 	2 	2 	2dk""Q&&""4=111 dk""Q&&&&&&&&	2s   AA& &ACCc                 <    |                                  | j        k    S )zDetermine if iterator is exhausted.

        Returns
        -------
        bool
            True if iterator has more items, False otherwise.

        Note
        ----
        Will never raise :exc:`StopIteration`.

        )peekr   r   s    r   has_nextzpeek_iter.has_nextH   s     yy{{dm++r   c                 $                          |           |s< j        d          j        k    rt          | j                                        }n>g }n; j        |dz
            j        k    rt           fdt          |          D             }|S )aK  Get the next item or `n` items of the iterator.

        Parameters
        ----------
        n : int or None
            The number of items to retrieve. Defaults to None.

        Returns
        -------
        item or list of items
            The next item or `n` items of the iterator. If `n` is None, the
            item itself is returned. If `n` is an int, the items will be
            returned in a list. If `n` is 0, an empty list is returned.

        Raises
        ------
        StopIteration
            Raised if the iterator is exhausted, even if `n` is 0.

        r   Nr   c                 B    g | ]}j                                         S r   )r   popleft.0ir   s     r   
<listcomp>z"peek_iter.next.<locals>.<listcomp>w   s'    >>>dk))++>>>r   )r'   r   r   r&   r-   ranger   r   results   `  r   r!   zpeek_iter.nextW   s    * 	 
	?{1~..##y,,..{1q5!T]22##>>>>U1XX>>>Fr   c                                            |           | j        d         }n fdt          |          D             }|S )ah  Preview the next item or `n` items of the iterator.

        The iterator is not advanced when peek is called.

        Returns
        -------
        item or list of items
            The next item or `n` items of the iterator. If `n` is None, the
            item itself is returned. If `n` is an int, the items will be
            returned in a list. If `n` is 0, an empty list is returned.

            If the iterator is exhausted, `peek_iter.sentinel` is returned,
            or placed as the last item in the returned list.

        Note
        ----
        Will never raise :exc:`StopIteration`.

        Nr   c                 *    g | ]}j         |         S r   )r   r.   s     r   r1   z"peek_iter.peek.<locals>.<listcomp>   s    777dk!n777r   )r'   r   r2   r3   s   `  r   r)   zpeek_iter.peekz   sM    ( 	9[^FF7777eAhh777Fr   )r
   r   r   )__name__
__module____qualname____doc__r   r   r   r   intr#   r'   boolr*   r!   r)   r   r   r   r   r      s        @%c %d % % % %    (3- 3    	2HSM 	2d 	2 	2 	2 	2,$ , , , ,! !hsm !s ! ! ! !F hsm s      r   r   c                   L     e Zd ZdZdededdf fdZdee         ddfdZ xZ	S )	modify_iteraT  An iterator object that supports modifying items as they are returned.

    Parameters
    ----------
    o : iterable or callable
        `o` is interpreted very differently depending on the presence of
        `sentinel`.

        If `sentinel` is not given, then `o` must be a collection object
        which supports either the iteration protocol or the sequence protocol.

        If `sentinel` is given, then `o` must be a callable object.

    sentinel : any value, optional
        If given, the iterator will call `o` with no arguments for each
        call to its `next` method; if the value returned is equal to
        `sentinel`, :exc:`StopIteration` will be raised, otherwise the
        value will be returned.

    modifier : callable, optional
        The function that will be used to modify each item returned by the
        iterator. `modifier` should take a single argument and return a
        single value. Defaults to ``lambda x: x``.

        If `sentinel` is not given, `modifier` must be passed as a keyword
        argument.

    Attributes
    ----------
    modifier : callable
        `modifier` is called with each item in `o` as it is iterated. The
        return value of `modifier` is returned in lieu of the item.

        Values returned by `peek` as well as `next` are affected by
        `modifier`. However, `modify_iter.sentinel` is never passed through
        `modifier`; it will always be returned from `peek` unmodified.

    Example
    -------
    >>> a = ["     A list    ",
    ...      "   of strings  ",
    ...      "      with     ",
    ...      "      extra    ",
    ...      "   whitespace. "]
    >>> modifier = lambda s: s.strip().replace('with', 'without')
    >>> for s in modify_iter(a, modifier=modifier):
    ...   print('"%s"' % s)
    "A list"
    "of strings"
    "without"
    "extra"
    "whitespace."

    r	   kwargsr
   Nc                    d|v r|d         | _         n3t          |          dk    r|d         | _         |dd         }nd | _         t          | j                   st          d           t	                      j        |  dS )z0__init__(o, sentinel=None, modifier=lambda x: x)modifierr   Nc                     | S r   r   )xs    r   <lambda>z&modify_iter.__init__.<locals>.<lambda>   s    a r   z3modify_iter(o, modifier): modifier must be callable)rA   r   callable	TypeErrorsuperr   )r   r	   r?   	__class__s      r   r   zmodify_iter.__init__   s    ":.DMMYY]] GDM8DD'KDM&& 	9 8 9 9 9$r   r   c                    |sd}	 t          | j                  |k     rY| j                            |                     t	          | j                                       t          | j                  |k     WdS dS # t          $ rV t          | j                  |k     r:| j                            | j                   t          | j                  |k     7Y dS Y dS w xY w)zCache `n` modified items. If `n` is 0 or None, 1 item is cached.

        Each item returned by the iterator is passed through the
        `modify_iter.modified` function before being cached.

        r   N)r   r   r%   rA   r!   r   r&   r   r"   s     r   r'   zmodify_iter._fillcache   s      	A	2dk""Q&&""4==dn1E1E#F#FGGG dk""Q&&&&&& 	2 	2 	2dk""Q&&""4=111 dk""Q&&&&&&&&	2s   A/A9 9ACC)
r7   r8   r9   r:   r   r   r   r;   r'   __classcell__)rH   s   @r   r>   r>      s        5 5l c  S  T            2HSM 2d 2 2 2 2 2 2 2 2r   r>   )r:   r   warningstypingr   r   r   sphinx.deprecationr   warnr   r>   r   r   r   <module>rO      s    ( (      * * * * * * * * * * 7 7 7 7 7 7 <&( ( (F F F F F F F FRS2 S2 S2 S2 S2) S2 S2 S2 S2 S2r   