
    -Ph                     ^    d Z dgZ G d d          Z G d d          Z G d d          ZdS )a  
Helper for looping over sequences, particular in templates.

Often in a loop in a template it's handy to know what's next up,
previously up, if this is the first or last item in the sequence, etc.
These can be awkward to manage in a normal Python loop, but using the
looper you can get a better sense of the context.  Use like::

    >>> for loop, item in looper(['a', 'b', 'c']):
    ...     print loop.number, item
    ...     if not loop.last:
    ...         print '---'
    1 a
    ---
    2 b
    ---
    3 c

looperc                   $    e Zd ZdZd Zd Zd ZdS )r   z
    Helper for looping (particularly in templates)

    Use this like::

        for loop, item in looper(seq):
            if loop.first:
                ...
    c                     || _         d S N)seqselfr   s     V/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/Cython/Tempita/_looper.py__init__zlooper.__init__#   s        c                 *    t          | j                  S r   )looper_iterr   r   s    r	   __iter__zlooper.__iter__&   s    48$$$r   c                 2    d| j         j        d| j        dS )N<z for >)	__class____name__r   r   s    r	   __repr__zlooper.__repr__)   s$     N###TXXX/ 	/r   N)r   
__module____qualname____doc__r
   r   r    r   r	   r   r      sK           % % %/ / / / /r   c                        e Zd Zd Zd Zd ZdS )r   c                 <    t          |          | _        d| _        d S N    )listr   posr   s     r	   r
   zlooper_iter.__init__0   s    99r   c                     | S r   r   r   s    r	   r   zlooper_iter.__iter__4   s    r   c                     | j         t          | j                  k    rt          t	          | j        | j                   | j        | j                  f}| xj         dz  c_         |S N   )r   lenr   StopIterationloop_pos)r   results     r	   __next__zlooper_iter.__next__7   sR    8s48}}$$$(DH--tx/AAAr   N)r   r   r   r
   r   r(   r   r   r	   r   r   .   sA                r   r   c                   H   e Zd Zd Zd Zd Z ee          Zd Z ee          Zd Z ee          Zd Z	 ee	          Z	d Z
 ee
          Z
d Z ee          Zd	 Z ee          Zd
 Z ee          Zd Z ee          Zd Z ee          ZddZddZd ZdS )r&   c                 "    || _         || _        d S r   r   r   )r   r   r   s      r	   r
   zloop_pos.__init__A   s    r   c                 >    d| j         | j                 d| j        dS )Nz
<loop pos=z at r   r+   r   s    r	   r   zloop_pos.__repr__E   s(     HTX* 	*r   c                     | j         S r   r   r   s    r	   indexzloop_pos.indexI   s	    xr   c                     | j         dz   S r"   r.   r   s    r	   numberzloop_pos.numberM       x!|r   c                 &    | j         | j                 S r   r+   r   s    r	   itemzloop_pos.itemQ   s    x!!r   c                 P    	 | j         | j        dz            S # t          $ r Y d S w xY wr"   )r   r   
IndexErrorr   s    r	   r(   zloop_pos.__next__U   s<    	8DHqL)) 	 	 	44	s    
%%c                 F    | j         dk    rd S | j        | j         dz
           S )Nr   r#   )r   r   r   s    r	   previouszloop_pos.previous\   s%    8q==4x1%%r   c                     | j         dz   S N   r.   r   s    r	   oddzloop_pos.oddb   s    8a<r   c                     | j         dz  S r:   r.   r   s    r	   evenzloop_pos.evenf   r2   r   c                     | j         dk    S r   r.   r   s    r	   firstzloop_pos.firstj   s    x1}r   c                 B    | j         t          | j                  dz
  k    S r"   )r   r$   r   r   s    r	   lastzloop_pos.lastn   s    x3tx==1,,,r   c                 *    t          | j                  S r   )r$   r   r   s    r	   lengthzloop_pos.lengthr   s    48}}r   Nc                 V    | j         rdS |                     | j        | j        |          S )a  
        Returns true if this item is the start of a new group,
        where groups mean that some attribute has changed.  The getter
        can be None (the item itself changes), an attribute name like
        ``'.attr'``, a function, or a dict key or list index.
        T)r@   _compare_groupr4   r8   r   getters     r	   first_groupzloop_pos.first_groupv   s/     : 	4""49dmVDDDr   c                 V    | j         rdS |                     | j        | j        |          S )a  
        Returns true if this item is the end of a new group,
        where groups mean that some attribute has changed.  The getter
        can be None (the item itself changes), an attribute name like
        ``'.attr'``, a function, or a dict key or list index.
        T)rB   rF   r4   r(   rG   s     r	   
last_groupzloop_pos.last_group   s/     9 	4""49dmVDDDr   c                    |||k    S t          |t                    r|                    d          r}|dd          }|                    d          r<|d d         } t	          ||                       t	          ||                      k    S t	          ||          t	          ||          k    S t          |d          r ||           ||          k    S ||         ||         k    S )N.r#   z()__call__)
isinstancestr
startswithendswithgetattrhasattr)r   r4   otherrH   s       r	   rF   zloop_pos._compare_group   s    >5= %% 	1##C((	1ABBZFt$$ G,wtV,,..2H'%2H2H2J2JJJtV,,v0F0FFFVZ(( 	16$<<66%==00<5=00r   r   )r   r   r   r
   r   r/   propertyr1   r4   r(   r8   r<   r>   r@   rB   rD   rI   rK   rF   r   r   r	   r&   r&   ?   s         * * *  HUOOE  XfF" " "8D>>D  
 x!!H& & & x!!H     
(3--C  8D>>D  HUOOE- - -8D>>D  XfF	E 	E 	E 	E	E 	E 	E 	E1 1 1 1 1r   r&   N)r   __all__r   r   r&   r   r   r	   <module>rY      s    ( */ / / / / / / /,       "[1 [1 [1 [1 [1 [1 [1 [1 [1 [1r   