ó
öÀ„\c           @   sa   d  Z  d d l Z e r1 d d l m Z m Z n  d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   sá   
    sphinx.ext.napoleon.iterators
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


    A collection of helpful iterators.


    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
iÿÿÿÿN(   t   Anyt   Iterablet	   peek_iterc           B   sV   e  Z d  Z d „  Z d „  Z d d „ Z d „  Z d „  Z d d „ Z	 d d „ Z
 RS(	   sl  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()``.

    c         G   sP   t  | Œ  |  _ t j ƒ  |  _ t | ƒ d k r@ | d |  _ n t ƒ  |  _ d S(   s   __init__(o, sentinel=None)i   i   N(   t   itert	   _iterablet   collectionst   dequet   _cachet   lent   sentinelt   object(   t   selft   args(    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/iterators.pyt   __init__6   s
    c         C   s   |  S(   N(    (   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/iterators.pyt   __iter__@   s    c         C   s   t  |  d ƒ | ƒ S(   Nt   next(   t   getattr(   R   t   n(    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/iterators.pyt   __next__D   s    c         C   s   | s d } n  y9 x2 t  |  j ƒ | k  rF |  j j t |  j ƒ ƒ q WWn@ t k
 rŠ x0 t  |  j ƒ | k  r† |  j j |  j ƒ q[ Wn Xd S(   s<   Cache `n` items. If `n` is 0 or None, then 1 item is cached.i   N(   R   R   t   appendR   R   t   StopIterationR	   (   R   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/iterators.pyt
   _fillcacheJ   s    	!c         C   s   |  j  ƒ  |  j k S(   sã   Determine if iterator is exhausted.

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

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

        (   t   peekR	   (   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/iterators.pyt   has_nextV   s    c         C   s¨   |  j  | ƒ | sY |  j d |  j k r2 t ‚ n  | d k rP |  j j ƒ  } q¤ g  } nK |  j | d |  j k r| t ‚ n  g  t | ƒ D] } |  j j ƒ  ^ q‰ } | S(   sK  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.

        i    i   N(   R   R   R	   R   t   Nonet   popleftt   range(   R   R   t   resultt   i(    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/iterators.pyR   f   s    			(c         C   sS   |  j  | ƒ | d k r) |  j d } n& g  t | ƒ D] } |  j | ^ q6 } | S(   sh  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`.

        i    N(   R   R   R   R   (   R   R   R   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/iterators.pyR   Š   s
    &N(   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R   R   (    (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/iterators.pyR      s    	
			$t   modify_iterc           B   s    e  Z d  Z d „  Z d „  Z RS(   sT  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."

    c         O   sŒ   d | k r | d |  _  n8 t | ƒ d k rH | d |  _  | d  } n d „  |  _  t |  j  ƒ sr t d ƒ ‚ n  t t |  ƒ j | Œ  d S(   s0   __init__(o, sentinel=None, modifier=lambda x: x)t   modifieri   c         S   s   |  S(   N(    (   t   x(    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/iterators.pyt   <lambda>ç   s    s3   modify_iter(o, modifier): modifier must be callableN(   R!   R   t   callablet	   TypeErrort   superR    R   (   R   R   t   kwargs(    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/iterators.pyR   Þ   s    c         C   s˜   | s d } n  yB x; t  |  j ƒ | k  rO |  j j |  j t |  j ƒ ƒ ƒ q WWn@ t k
 r“ x0 t  |  j ƒ | k  r |  j j |  j ƒ qd Wn Xd S(   sÉ   Cache `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.

        i   N(   R   R   R   R!   R   R   R   R	   (   R   R   (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/iterators.pyR   í   s    	*(   R   R   R   R   R   (    (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/iterators.pyR    §   s   6	(	   R   R   t   Falset   typingR    R   R
   R   R    (    (    (    s<   lib/python2.7/site-packages/sphinx/ext/napoleon/iterators.pyt   <module>   s
   ’