
    NgH                     x    d Z ddlZddlmZ dgZ G d de          Z G d de          Z G d d	e          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

    N)basestring_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     R/var/www/html/ai-engine/env/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ej        dk     reZdS dS )r   c                 <    t          |          | _        d| _        d S Nr   )listr   posr	   s     r   r   zlooper_iter.__init__3   s    99r   c                     | S r   r   r   s    r   r   zlooper_iter.__iter__7   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__:   sR    8s48}}$$$(DH--tx/AAAr   3N)	r   r   r   r   r   r)   sysversionnextr   r   r   r   r   1   sW               {S r   r   c                   b   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	e
j        dk     r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__G   s    r   c                 >    d| j         | j                 d| j        dS )Nz
<loop pos=z at r   r0   r   s    r   r   zloop_pos.__repr__K   s(     HTX* 	*r   c                     | j         S r   r    r   s    r   indexzloop_pos.indexO   s	    xr   c                     | j         dz   S r#   r3   r   s    r   numberzloop_pos.numberS       x!|r   c                 &    | j         | j                 S r   r0   r   s    r   itemzloop_pos.itemW   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__[   s<    	8DHqL)) 	 	 	44	s    
%%r*   c                 F    | j         dk    rd S | j        | j         dz
           S )Nr   r$   )r    r   r   s    r   previouszloop_pos.previouse   s%    8q==4x1%%r   c                     | j         dz   S N   r3   r   s    r   oddzloop_pos.oddk   s    8a<r   c                     | j         dz  S r?   r3   r   s    r   evenzloop_pos.eveno   r7   r   c                     | j         dk    S r   r3   r   s    r   firstzloop_pos.firsts   s    x1}r   c                 B    | j         t          | j                  dz
  k    S r#   )r    r%   r   r   s    r   lastzloop_pos.lastw   s    x3tx==1,,,r   c                 *    t          | j                  S r   )r%   r   r   s    r   lengthzloop_pos.length{   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)rE   _compare_groupr9   r=   r
   getters     r   first_groupzloop_pos.first_group   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)rG   rK   r9   r)   rL   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__)
isinstancer   
startswithendswithgetattrhasattr)r
   r9   otherrM   s       r   rK   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   r4   propertyr6   r9   r)   r+   r,   r-   r=   rA   rC   rE   rG   rI   rN   rP   rK   r   r   r   r'   r'   E   s         * * *  HUOOE  XfF" " "8D>>D  
 x!!H
{S& & & 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'   )	r   r+   Cython.Tempita.compat3r   __all__objectr   r   r'   r   r   r   <module>r_      s    ( 


 . . . . . .*/ / / / /V / / /,    &   (^1 ^1 ^1 ^1 ^1v ^1 ^1 ^1 ^1 ^1r   