
    ۏDj!                     J    d Z dgZ G d d      Z G d d      Z G d d      Zy)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y)r   z
    Helper for looping (particularly in templates)

    Use this like::

        for loop, item in looper(seq):
            if loop.first:
                ...
    c                     || _         y N)seqselfr   s     ZC:\Crop_Prediction\Backend\crop-ai-system\venv\Lib\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    488$$r   c                 P    d| j                   j                  d| j                  dS )N<z for >)	__class____name__r   r   s    r	   __repr__zlooper.__repr__)   s    NN##TXX/ 	/r   N)r   
__module____qualname____doc__r
   r   r    r   r	   r   r      s    %/r   c                       e Zd Zd Zd Zd Zy)r   c                 2    t        |      | _        d| _        y N    )listr   posr   s     r	   r
   zlooper_iter.__init__0   s    9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   sT    88s488}$$((DHH-txx/AAAr   N)r   r   r   r
   r   r(   r   r   r	   r   r   .   s    r   r   c                   
   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y)r&   c                      || _         || _        y r   r   r   )r   r   r   s      r	   r
   zloop_pos.__init__A   s    r   c                 V    d| j                   | j                     d| j                  dS )Nz
<loop pos=z at r   r+   r   s    r	   r   zloop_pos.__repr__E   s"    HHTXX* 	*r   c                     | j                   S r   r   r   s    r	   indexzloop_pos.indexI   s    xxr   c                      | j                   dz   S r"   r.   r   s    r	   numberzloop_pos.numberM       xx!|r   c                 4    | j                   | j                     S r   r+   r   s    r	   itemzloop_pos.itemQ   s    xx!!r   c                 Z    	 | j                   | j                  dz      S # t        $ r Y y w xY wr"   )r   r   
IndexErrorr   s    r	   r(   zloop_pos.__next__U   s0    	88DHHqL)) 		s    	**c                 Z    | j                   dk(  ry | j                  | j                   dz
     S )Nr   r#   )r   r   r   s    r	   previouszloop_pos.previous\   s'    88q=xx1%%r   c                 "    | j                   dz   S N   r.   r   s    r	   oddzloop_pos.oddb   s    88a<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    xx1}r   c                 L    | j                   t        | j                        dz
  k(  S r"   )r   r$   r   r   s    r	   lastzloop_pos.lastn   s    xx3txx=1,,,r   c                 ,    t        | j                        S r   )r$   r   r   s    r	   lengthzloop_pos.lengthr   s    488}r   Nc                 j    | j                   ry| j                  | 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+     ::""499dmmVDDr   c                 j    | j                   ry| j                  | 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+     99""499dmmVDDr   c                 P   |||k7  S t        |t              rh|j                  d      rW|dd  }|j                  d      r(|d d } t	        ||              t	        ||             k7  S t	        ||      t	        ||      k7  S t        |d      r ||       ||      k7  S ||   ||   k7  S )N.r#   z()__call__)
isinstancestr
startswithendswithgetattrhasattr)r   r4   otherrH   s       r	   rF   zloop_pos._compare_group   s    >5= %##C(ABZFt$,wtV,.2H'%2H2JJJtV,v0FFFVZ($<6%=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    *UOEfF"D>D
 !H& !H 
3-CD>DUOE-D>DfF	E	E1r   r&   N)r   __all__r   r   r&   r   r   r	   <module>rY      s3   ( */ /, "[1 [1r   