
    h                     J    S r S/r " S S5      r " S S5      r " S S5      rg)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                   *    \ rS rSrSrS rS rS rSrg)r      z
Helper for looping (particularly in templates)

Use this like::

    for loop, item in looper(seq):
        if loop.first:
            ...
c                     Xl         g Nseqselfr   s     P/var/www/fran/franai/venv/lib/python3.13/site-packages/Cython/Tempita/_looper.py__init__looper.__init__#   s        c                 ,    [        U R                  5      $ r   )looper_iterr   r
   s    r   __iter__looper.__iter__&   s    488$$r   c                 T    SU R                   R                  < SU R                  < S3$ )N<z for >)	__class____name__r   r   s    r   __repr__looper.__repr__)   s    NN##TXX/ 	/r   r   N)	r   
__module____qualname____firstlineno____doc__r   r   r   __static_attributes__ r   r   r   r      s    %/r   c                   &    \ rS rSrS rS rS rSrg)r   .   c                 2    [        U5      U l        SU l        g N    )listr   posr	   s     r   r   looper_iter.__init__0   s    9r   c                     U $ r   r    r   s    r   r   looper_iter.__iter__4   s    r   c                     U R                   [        U R                  5      :  a  [        e[	        U R                  U R                   5      U R                  U R                      4nU =R                   S-  sl         U$ N   )r'   lenr   StopIterationloop_pos)r
   results     r   __next__looper_iter.__next__7   sT    88s488}$$((DHH-txx/AAAr   r'   r   N)r   r   r   r   r   r   r2   r   r    r   r   r   r   .   s    r   r   c                      \ rS rSrS rS rS r\" \5      rS r\" \5      rS r	\" \	5      r	S r
\" \
5      r
S r\" \5      rS	 r\" \5      rS
 r\" \5      rS r\" \5      rS r\" \5      rS r\" \5      rSS jrSS jrS rSrg)r0   ?   c                     Xl         X l        g r   r   r'   )r
   r   r'   s      r   r   loop_pos.__init__A   s    r   c                 Z    SU R                   U R                     < SU R                  < S3$ )Nz
<loop pos=z at r   r8   r   s    r   r   loop_pos.__repr__E   s"    HHTXX* 	*r   c                     U R                   $ r   r'   r   s    r   indexloop_pos.indexI   s    xxr   c                      U R                   S-   $ r,   r=   r   s    r   numberloop_pos.numberM       xx!|r   c                 4    U R                   U R                     $ r   r8   r   s    r   itemloop_pos.itemQ   s    xx!!r   c                 \     U R                   U R                  S-      $ ! [         a     g f = fr,   )r   r'   
IndexErrorr   s    r   r2   loop_pos.__next__U   s0    	88DHHqL)) 		s    
++c                 \    U R                   S:X  a  g U R                  U R                   S-
     $ )Nr%   r-   r4   r   s    r   previousloop_pos.previous\   s'    88q=xx1%%r   c                 *    U R                   S-  (       + $ N   r=   r   s    r   oddloop_pos.oddb   s    88a<r   c                      U R                   S-  $ rN   r=   r   s    r   evenloop_pos.evenf   rC   r   c                      U R                   S:H  $ r$   r=   r   s    r   firstloop_pos.firstj   s    xx1}r   c                 L    U R                   [        U R                  5      S-
  :H  $ r,   )r'   r.   r   r   s    r   lastloop_pos.lastn   s    xx3txx=1,,,r   c                 ,    [        U R                  5      $ r   )r.   r   r   s    r   lengthloop_pos.lengthr   s    488}r   Nc                 t    U R                   (       a  gU R                  U R                  U R                  U5      $ )z
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)rV   _compare_grouprE   rK   r
   getters     r   first_grouploop_pos.first_groupv   s+     ::""499dmmVDDr   c                 t    U R                   (       a  gU R                  U R                  U R                  U5      $ )z
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)rY   r_   rE   r2   r`   s     r   
last_grouploop_pos.last_group   s+     99""499dmmVDDr   c                 l   Uc  X:g  $ [        U[        5      (       an  UR                  S5      (       aX  USS  nUR                  S5      (       a&  US S n[	        X5      " 5       [	        X#5      " 5       :g  $ [	        X5      [	        X#5      :g  $ [        US5      (       a  U" U5      U" U5      :g  $ X   X#   :g  $ )N.r-   z()__call__)
isinstancestr
startswithendswithgetattrhasattr)r
   rE   otherra   s       r   r_   loop_pos._compare_group   s    >= %%##C((ABZFt$$t,.'%2H2JJJt,0FFFVZ(($<6%=00<5=00r   r4   r   )r   r   r   r   r   r   r>   propertyrA   rE   r2   rK   rP   rS   rV   rY   r\   rb   re   r_   r   r    r   r   r0   r0   ?   s    *UOEfF"D>D
 !H& !H 
3-CD>DUOE-D>DfF	E	E1r   r0   N)r   __all__r   r   r0   r    r   r   <module>ru      s3   ( */ /, "[1 [1r   